From cbc0cde9e84579a5b4efa2ac4a28a01fa03bc2c3 Mon Sep 17 00:00:00 2001 From: mehedi-hasan Date: Sat, 4 May 2024 23:05:38 +0600 Subject: [PATCH] feat: edit api communication page --- .../dashboard/api-communications/add/page.tsx | 8 ++- .../api-communications/edit/[id]/page.tsx | 51 +++++++++++++++++++ ...on-form.tsx => api-communication-form.tsx} | 35 +++++++++++-- .../api-communication-table/cell-action.tsx | 15 +++--- src/constants/data.ts | 2 +- 5 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 src/app/(dashboard)/dashboard/api-communications/edit/[id]/page.tsx rename src/components/{add-api-communication-form.tsx => api-communication-form.tsx} (85%) diff --git a/src/app/(dashboard)/dashboard/api-communications/add/page.tsx b/src/app/(dashboard)/dashboard/api-communications/add/page.tsx index 9ce6ca7..744fa08 100644 --- a/src/app/(dashboard)/dashboard/api-communications/add/page.tsx +++ b/src/app/(dashboard)/dashboard/api-communications/add/page.tsx @@ -1,4 +1,6 @@ -import AddAPICommunicationForm from "@/components/add-api-communication-form"; +"use client" + +import AddAPICommunicationForm from "@/components/api-communication-form"; import Breadcrumb from "@/components/breadcrumb"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; @@ -25,7 +27,9 @@ export default function SettingsDisplayPage() { - + {}} + btn1_content="Create" + btn2_content="Create and add another" /> diff --git a/src/app/(dashboard)/dashboard/api-communications/edit/[id]/page.tsx b/src/app/(dashboard)/dashboard/api-communications/edit/[id]/page.tsx new file mode 100644 index 0000000..b2f8faf --- /dev/null +++ b/src/app/(dashboard)/dashboard/api-communications/edit/[id]/page.tsx @@ -0,0 +1,51 @@ +"use client"; + +import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; +import { Separator } from "@/components/ui/separator"; +import ConfigurationForm from "@/components/configuration-form"; +import Breadcrumb from "@/components/breadcrumb"; +import { dummyApiCommunications, dummyConfigurations } from "@/constants/data"; +import { Configuration } from "@/types/configuration"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import APICommunicationForm from "@/components/api-communication-form"; +import { ApiCommunication } from "@/types/api-communication"; + +const breadcrumbItems = [ + { title: "Dashboard", link: "/dashboard" }, + { title: "Api Communications", link: "/dashboard/api-communications" }, + { title: "Edit" }, +]; + +export default function Page({ params }: { params: { id: string } }) { + const apiCommunication = dummyApiCommunications.find( + (apiCommunication) => apiCommunication.id === +params.id + ); + + return ( + +
+ +
+ + + + Edit Api Communication + + + + + + {}} + btn1_content="Save and continue editing" + btn2_content="Save changes" + /> + + +
+
+ +
+ ); +} diff --git a/src/components/add-api-communication-form.tsx b/src/components/api-communication-form.tsx similarity index 85% rename from src/components/add-api-communication-form.tsx rename to src/components/api-communication-form.tsx index e43b566..90ed2f8 100644 --- a/src/components/add-api-communication-form.tsx +++ b/src/components/api-communication-form.tsx @@ -23,6 +23,7 @@ import { SelectValue, } from "./ui/select"; import { Textarea } from "./ui/textarea"; +import { ApiCommunication } from "@/types/api-communication"; const displayFormSchema = z.object({ pt: z @@ -89,10 +90,31 @@ const defaultValues: Partial = { evaluation: "", }; -export default function AddAPICommunicationForm() { +type Props = { + apiCommunication?: ApiCommunication; + onSubmit: () => void; + btn1_content: string; + btn2_content: string; +}; + +export default function APICommunicationForm({ + apiCommunication, + onSubmit: onFormSubmit, + btn1_content, + btn2_content, +}: Props) { const form = useForm({ resolver: zodResolver(displayFormSchema), - defaultValues, + defaultValues: { + pt: apiCommunication?.pt ? String(apiCommunication.pt) : "", + messages: apiCommunication?.messages || "", + completion: apiCommunication?.completion || "", + ct: apiCommunication?.ct ? String(apiCommunication.ct) : "", + tt: apiCommunication?.tt ? String(apiCommunication.tt) : "", + status: apiCommunication?.status || "", + type: apiCommunication?.type || "", + evaluation: apiCommunication?.evaluation || "", + }, }); function onSubmit(data: DisplayFormValues) { @@ -104,6 +126,8 @@ export default function AddAPICommunicationForm() { ), }); + + onFormSubmit(); } return ( @@ -215,11 +239,12 @@ export default function AddAPICommunicationForm() { - + Uploaded at: 2023-09-20 00:00:00 - Uploader: jschultz@php.net - Developer: fabien@potencier.org - Status: finished + @@ -229,10 +254,10 @@ export default function AddAPICommunicationForm() {
diff --git a/src/components/api-communication-table/cell-action.tsx b/src/components/api-communication-table/cell-action.tsx index 366a180..d8c10e1 100644 --- a/src/components/api-communication-table/cell-action.tsx +++ b/src/components/api-communication-table/cell-action.tsx @@ -12,6 +12,7 @@ import { useToast } from "@/components/ui/use-toast"; import { ApiCommunication } from "@/types/api-communication"; import { Edit, MoreHorizontal, Trash } from "lucide-react"; +import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -47,13 +48,13 @@ export const CellAction: React.FC = ({ data }) => { Actions - - // router.push(`#`) - // } - > - Update + + + Edit +