From e4a128a07b39395de0a0b90272262c9cd9679ffc Mon Sep 17 00:00:00 2001 From: balibabu Date: Sun, 29 Sep 2024 11:05:43 +0800 Subject: [PATCH] feat: Create database #1841 (#1938) ### What problem does this PR solve? feat: Create database #1841 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- gui/app/(dashboard)/actions.ts | 36 +++++++++++++++++-- .../(dashboard)/database-creating-dialog.tsx | 14 ++++++-- .../(dashboard)/database-creating-form.tsx | 35 +++++++++++------- gui/app/(dashboard)/page.tsx | 5 ++- gui/app/layout.tsx | 6 +++- gui/lib/constant/common.ts | 4 +++ gui/lib/request.ts | 2 +- gui/lib/service/index.ts | 10 ++++-- 8 files changed, 87 insertions(+), 25 deletions(-) create mode 100644 gui/lib/constant/common.ts diff --git a/gui/app/(dashboard)/actions.ts b/gui/app/(dashboard)/actions.ts index b16f905687..885411004d 100644 --- a/gui/app/(dashboard)/actions.ts +++ b/gui/app/(dashboard)/actions.ts @@ -1,10 +1,42 @@ 'use server'; -import { deleteProductById } from '@/lib/db'; -import { revalidatePath } from 'next/cache'; +import { ApiUrl } from '@/lib/constant/api'; +import { CreateOption } from '@/lib/constant/common'; +import { get, post } from '@/lib/request'; export async function deleteProduct(formData: FormData) { // let id = Number(formData.get('id')); // await deleteProductById(id); // revalidatePath('/'); } + +export async function createDatabaseAction(formData: FormData) { + // let id = Number(formData.get('id')); + // await deleteProductById(id); + // revalidatePath('/'); +} + +export const createDatabase = async (params: { + database_name: string; + create_option: CreateOption; +}) => { + try { + const x = await post(`${ApiUrl.databases}/${params.database_name}`, { + create_option: params.create_option + }); + console.log('🚀 ~ x:', x); + return x; + } catch (error) { + console.log('🚀 ~ error:', error); + } +}; + +export const listDatabase = async () => { + try { + const x = await get(`${ApiUrl.databases}`); + console.log('🚀 ~ x:', x); + return x; + } catch (error) { + console.log('🚀 ~ error:', error); + } +}; diff --git a/gui/app/(dashboard)/database-creating-dialog.tsx b/gui/app/(dashboard)/database-creating-dialog.tsx index cef1060899..d952d8e06a 100644 --- a/gui/app/(dashboard)/database-creating-dialog.tsx +++ b/gui/app/(dashboard)/database-creating-dialog.tsx @@ -1,3 +1,5 @@ +'use client'; + import { Button } from '@/components/ui/button'; import { Dialog, @@ -7,19 +9,25 @@ import { DialogTitle, DialogTrigger } from '@/components/ui/dialog'; -import React from 'react'; +import React, { useCallback } from 'react'; import { DatabaseCreatingForm } from './database-creating-form'; export function DatabaseCreatingDialog({ children }: React.PropsWithChildren) { + const [open, setOpen] = React.useState(false); + + const hide = useCallback(() => { + setOpen(false); + }, []); + return ( - + {children} Create Database
- +