diff --git a/src/app/(dashboard)/dashboard/accounts/add/page.tsx b/src/app/(dashboard)/dashboard/accounts/add/page.tsx index f8e77c7..75abe98 100644 --- a/src/app/(dashboard)/dashboard/accounts/add/page.tsx +++ b/src/app/(dashboard)/dashboard/accounts/add/page.tsx @@ -1,4 +1,6 @@ -import AddAccountForm from "@/components/add-account-form"; +"use client" + +import AccountForm from "@/components/account-form"; import Breadcrumb from "@/components/breadcrumb"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; @@ -10,25 +12,29 @@ const breadcrumbItems = [ { title: "Add" }, ]; -export default function SettingsDisplayPage() { +export default function Page() { return ( -
+
- - - - Create Account - - - + + + + Create Account + + + - - - - -
+ + {}} + btn1_content="Create" + btn2_content="Create and add another" + /> + + +
diff --git a/src/app/(dashboard)/dashboard/accounts/edit/[id]/page.tsx b/src/app/(dashboard)/dashboard/accounts/edit/[id]/page.tsx new file mode 100644 index 0000000..d5e3d3d --- /dev/null +++ b/src/app/(dashboard)/dashboard/accounts/edit/[id]/page.tsx @@ -0,0 +1,48 @@ +"use client"; + +import AccountForm from "@/components/account-form"; +import Breadcrumb from "@/components/breadcrumb"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; +import { Separator } from "@/components/ui/separator"; +import { dummyAccounts } from "@/constants/data"; +import { Account } from "@/types/account"; + +const breadcrumbItems = [ + { title: "Dashboard", link: "/dashboard" }, + { title: "Accounts", link: "/dashboard/accounts" }, + { title: "Edit" }, +]; + +export default function Page({ params }: { params: { id: string } }) { + + const account = dummyAccounts.find((account) => account.id === +params.id); + + return ( + +
+ +
+ + + + Edit Account + + + + + + {}} + btn1_content="Save and continue editing" + btn2_content="Save changes" + /> + + +
+
+ +
+ ); +} diff --git a/src/components/add-account-form.tsx b/src/components/account-form.tsx similarity index 72% rename from src/components/add-account-form.tsx rename to src/components/account-form.tsx index 8bb9687..ce2fbd6 100644 --- a/src/components/add-account-form.tsx +++ b/src/components/account-form.tsx @@ -22,20 +22,15 @@ import { SelectTrigger, SelectValue, } from "./ui/select"; +import { Account } from "@/types/account"; const displayFormSchema = z.object({ - email: z - .string({ - required_error: "Please select a user.", - }) - .trim() - .email(), + email: z.string().trim().min(1, { message: "Please select a user." }).email(), balance: z.string().trim().min(1, "Balance is required."), organization: z - .string({ - required_error: "Please select an organization.", - }) - .trim(), + .string() + .trim() + .min(1, { message: "Please select an organization." }), }); type DisplayFormValues = z.infer; @@ -47,10 +42,26 @@ const defaultValues: Partial = { organization: "", }; -export default function AddAccountForm() { +type Props = { + account?: Account; + onSubmit: () => void; + btn1_content: string; + btn2_content: string; +}; + +export default function AccountForm({ + account, + onSubmit: onFormSubmit, + btn1_content, + btn2_content, +}: Props) { const form = useForm({ resolver: zodResolver(displayFormSchema), - defaultValues, + defaultValues: { + balance: account?.balance ? String(account?.balance) : "", + email: account?.email || "", + organization: account?.organization || "", + }, }); function onSubmit(data: DisplayFormValues) { @@ -73,21 +84,19 @@ export default function AddAccountForm() { render={({ field }) => ( User - - - johndoe@gmail.com + john@gmail.com + + sarah@example.com - - adramov@gmail.com - - - hello@gmail.com + + michael@example.com @@ -123,8 +132,11 @@ export default function AddAccountForm() { - Skilld - Ecareers + XYZ Tech Inc. + ABC Solutions + + Acme Corporation + @@ -134,10 +146,10 @@ export default function AddAccountForm() {
diff --git a/src/components/accounts-table/cell-action.tsx b/src/components/accounts-table/cell-action.tsx index 7b3e682..e181cdc 100644 --- a/src/components/accounts-table/cell-action.tsx +++ b/src/components/accounts-table/cell-action.tsx @@ -14,6 +14,7 @@ import { Organization } from "@/types/organization"; import { User } from "@/types/user"; import { BookCheck, Edit, MoreHorizontal, Trash } from "lucide-react"; +import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -49,14 +50,15 @@ export const CellAction: React.FC = ({ data }) => { Actions - - // router.push(`#`) - // } - > - Update + + + Edit + + setIsDeleteModalOpen(true)} diff --git a/src/constants/data.ts b/src/constants/data.ts index 0d3f130..3a2b33d 100644 --- a/src/constants/data.ts +++ b/src/constants/data.ts @@ -89,7 +89,7 @@ export const dummyAccounts: Account[] = [ { id: 2, email: "sarah@example.com", - balance: 0, + balance: 2000, organization: "ABC Solutions", accountHistory: "None", created_at: new Date().toISOString(),