From 5d81d6621e91318baae97e1c8294f9b6b528db72 Mon Sep 17 00:00:00 2001 From: Sang Dang Date: Fri, 9 Feb 2024 15:19:18 +0200 Subject: [PATCH] working on edit candidate --- .eslintrc.js | 2 +- .../components/EditCandidateItem.tsx | 117 +++++++++++------- components/client/Spinner.tsx | 21 ++-- 3 files changed, 86 insertions(+), 54 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 63bf2f8..2a9a7e0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,8 +10,8 @@ module.exports = { ], rules: { 'import/no-cycle': 'error', - 'react/display-name': 'off', 'no-unused-vars': 'off', + 'react/display-name': 'off', '@typescript-eslint/no-unused-vars': [ 'warn', { diff --git a/app/(dashboard)/candidates/components/EditCandidateItem.tsx b/app/(dashboard)/candidates/components/EditCandidateItem.tsx index 3d50c15..473c448 100644 --- a/app/(dashboard)/candidates/components/EditCandidateItem.tsx +++ b/app/(dashboard)/candidates/components/EditCandidateItem.tsx @@ -7,8 +7,13 @@ import { DialogTitle, DialogTrigger, DropdownMenuItem, + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, Input, - Label, } from '@/components/ui'; import { useDisclosure, useForm } from '@/hooks'; import { updateUser } from '@/services/users'; @@ -31,11 +36,7 @@ export const EditCandidateItem = ({ email: candidate.email, }; - const { - register, - handleSubmit, - formState: { isSubmitting }, - } = useForm({ defaultValues }); + const form = useForm({ defaultValues }); const handleOpenChange = (isOpen: boolean) => { if (isOpen) { @@ -46,7 +47,7 @@ export const EditCandidateItem = ({ }; const onSubmit: SubmitHandler = async (data) => { - if (isSubmitting) return; + console.log('### onSubmit'); const result = await updateUser(candidate.id, data); @@ -57,6 +58,14 @@ export const EditCandidateItem = ({ handleOpenChange(false); }; + // useKeyPressEvent('Enter', (e) => { + // if (isOpen && formRef && formRef.current) { + // e.preventDefault(); + // console.log('### isOpen: ', { isOpen }); + // form.handleSubmit(onSubmit) + // } + // }); + return ( @@ -75,49 +84,69 @@ export const EditCandidateItem = ({ Edit Candidate -
-
-
- - + +
+ ( + + Candidate Name + + + + + + )} /> -
-
- - ( + + Candidate Email + + + + + + )} />
-
- - + + - - - + + + +
); diff --git a/components/client/Spinner.tsx b/components/client/Spinner.tsx index f3a44ff..b05e88b 100644 --- a/components/client/Spinner.tsx +++ b/components/client/Spinner.tsx @@ -1,11 +1,14 @@ -import { Loader2, LucideIcon } from '@/components/icons'; -import { ComponentProps } from '@/types'; +import { Loader2, LucideIcon } from 'lucide-react'; import { cn } from '@/lib/utils'; +import * as React from 'react'; -export type SpinnerProps = ComponentProps; - -export const Spinner = ({ className, ...rest }: SpinnerProps) => { - return ( - - ); -}; +export const Spinner = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...rest }, ref) => ( + +));