-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### What problem does this PR solve? feat: Add database page #1842 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
- Loading branch information
Showing
9 changed files
with
140 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,17 @@ | ||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; | ||
import { File, PlusCircle } from 'lucide-react'; | ||
import { Button } from '@/components/ui/button'; | ||
import { ProductsTable } from './products-table'; | ||
// import { getProducts } from '@/lib/db'; | ||
|
||
export default async function ProductsPage({ | ||
import { ApiUrl } from '@/lib/constant/api'; | ||
import { request } from '@/lib/utils'; | ||
|
||
export default async function HomePage({ | ||
searchParams | ||
}: { | ||
searchParams: { q: string; offset: string }; | ||
}) { | ||
const x = await request(ApiUrl.databases); | ||
console.log('🚀 ~ x:', x); | ||
const search = searchParams.q ?? ''; | ||
const offset = searchParams.offset ?? 0; | ||
// const { products, newOffset, totalProducts } = await getProducts( | ||
// search, | ||
// Number(offset) | ||
// ); | ||
|
||
const ret = await fetch('http://localhost:3000/products'); | ||
const products = await ret.json(); | ||
|
||
const { newOffset, totalProducts } = { | ||
newOffset: 0, | ||
totalProducts: 0 | ||
}; | ||
|
||
return ( | ||
<Tabs defaultValue="all"> | ||
<div className="flex items-center"> | ||
<TabsList> | ||
<TabsTrigger value="all">All</TabsTrigger> | ||
<TabsTrigger value="active">Active</TabsTrigger> | ||
<TabsTrigger value="draft">Draft</TabsTrigger> | ||
<TabsTrigger value="archived" className="hidden sm:flex"> | ||
Archived | ||
</TabsTrigger> | ||
</TabsList> | ||
<div className="ml-auto flex items-center gap-2"> | ||
<Button size="sm" variant="outline" className="h-8 gap-1"> | ||
<File className="h-3.5 w-3.5" /> | ||
<span className="sr-only sm:not-sr-only sm:whitespace-nowrap"> | ||
Export | ||
</span> | ||
</Button> | ||
<Button size="sm" className="h-8 gap-1"> | ||
<PlusCircle className="h-3.5 w-3.5" /> | ||
<span className="sr-only sm:not-sr-only sm:whitespace-nowrap"> | ||
Add Product | ||
</span> | ||
</Button> | ||
</div> | ||
</div> | ||
<TabsContent value="all"> | ||
<ProductsTable | ||
products={products} | ||
offset={newOffset ?? 0} | ||
totalProducts={totalProducts} | ||
/> | ||
</TabsContent> | ||
</Tabs> | ||
); | ||
return <div>HomePage</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Button } from '@/components/ui/button'; | ||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; | ||
import { File, PlusCircle } from 'lucide-react'; | ||
import { ProductsTable } from './products-table'; | ||
// import { getProducts } from '@/lib/db'; | ||
|
||
export default async function ProductsPage({ | ||
searchParams | ||
}: { | ||
searchParams: { q: string; offset: string }; | ||
}) { | ||
const search = searchParams.q ?? ''; | ||
const offset = searchParams.offset ?? 0; | ||
// const { products, newOffset, totalProducts } = await getProducts( | ||
// search, | ||
// Number(offset) | ||
// ); | ||
|
||
// const products = await request('http://localhost:3000/products'); | ||
|
||
const { newOffset, totalProducts, products } = { | ||
newOffset: 0, | ||
totalProducts: 0, | ||
products: [] | ||
}; | ||
|
||
return ( | ||
<Tabs defaultValue="all"> | ||
<div className="flex items-center"> | ||
<TabsList> | ||
<TabsTrigger value="all">All</TabsTrigger> | ||
<TabsTrigger value="active">Active</TabsTrigger> | ||
<TabsTrigger value="draft">Draft</TabsTrigger> | ||
<TabsTrigger value="archived" className="hidden sm:flex"> | ||
Archived | ||
</TabsTrigger> | ||
</TabsList> | ||
<div className="ml-auto flex items-center gap-2"> | ||
<Button size="sm" variant="outline" className="h-8 gap-1"> | ||
<File className="h-3.5 w-3.5" /> | ||
<span className="sr-only sm:not-sr-only sm:whitespace-nowrap"> | ||
Export | ||
</span> | ||
</Button> | ||
<Button size="sm" className="h-8 gap-1"> | ||
<PlusCircle className="h-3.5 w-3.5" /> | ||
<span className="sr-only sm:not-sr-only sm:whitespace-nowrap"> | ||
Add Product | ||
</span> | ||
</Button> | ||
</div> | ||
</div> | ||
<TabsContent value="all"> | ||
<ProductsTable | ||
products={products} | ||
offset={newOffset ?? 0} | ||
totalProducts={totalProducts} | ||
/> | ||
</TabsContent> | ||
</Tabs> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use client'; // Error boundaries must be Client Components | ||
|
||
import { useEffect } from 'react'; | ||
|
||
export default function Error({ | ||
error, | ||
reset | ||
}: { | ||
error: Error & { digest?: string }; | ||
reset: () => void; | ||
}) { | ||
useEffect(() => { | ||
// Log the error to an error reporting service | ||
console.error(error); | ||
}, [error]); | ||
|
||
return ( | ||
<div> | ||
<h2>Something went wrong!</h2> | ||
<button | ||
onClick={ | ||
// Attempt to recover by trying to re-render the segment | ||
() => reset() | ||
} | ||
> | ||
Try again | ||
</button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface IResponse { | ||
error_code: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const ApiUrl = { | ||
databases: 'databases' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
import { type ClassValue, clsx } from "clsx" | ||
import { twMerge } from "tailwind-merge" | ||
import { type ClassValue, clsx } from 'clsx'; | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
const baseUrl = 'http://127.0.0.1:23820/'; | ||
|
||
export function cn(...inputs: ClassValue[]) { | ||
return twMerge(clsx(inputs)) | ||
return twMerge(clsx(inputs)); | ||
} | ||
|
||
export const request = async (url: string, params?: any) => { | ||
const nextUrl = `${baseUrl}${url}`; | ||
try { | ||
const res = await fetch(nextUrl, { | ||
headers: { | ||
accept: 'application/json' | ||
}, | ||
cache: 'no-store', | ||
...params | ||
}); | ||
const ret = await res.json(); | ||
return ret; | ||
} catch (error) { | ||
console.warn('request error:', error); | ||
} | ||
}; |