Skip to content

Commit

Permalink
working on edit candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
sangdth committed Feb 9, 2024
1 parent e3906d2 commit 5d81d66
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{
Expand Down
117 changes: 73 additions & 44 deletions app/(dashboard)/candidates/components/EditCandidateItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -31,11 +36,7 @@ export const EditCandidateItem = ({
email: candidate.email,
};

const {
register,
handleSubmit,
formState: { isSubmitting },
} = useForm<ManualInputs>({ defaultValues });
const form = useForm<ManualInputs>({ defaultValues });

const handleOpenChange = (isOpen: boolean) => {
if (isOpen) {
Expand All @@ -46,7 +47,7 @@ export const EditCandidateItem = ({
};

const onSubmit: SubmitHandler<ManualInputs> = async (data) => {
if (isSubmitting) return;
console.log('### onSubmit');

const result = await updateUser(candidate.id, data);

Expand All @@ -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 (
<Dialog onOpenChange={handleOpenChange} open={isOpen}>
<DialogTrigger asChild>
Expand All @@ -75,49 +84,69 @@ export const EditCandidateItem = ({
<DialogTitle>Edit Candidate</DialogTitle>
</DialogHeader>

<form onSubmit={handleSubmit(onSubmit)}>
<div className="flex flex-col gap-4">
<div className="flex flex-col gap-2">
<Label htmlFor="name">Name</Label>
<Input
id="name"
placeholder="Name"
{...register('name', { required: true })}
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<div className="flex flex-col gap-4">
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Candidate Name</FormLabel>
<FormControl>
<Input
placeholder="Name"
{...field}
value={field.value ?? ''}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>

<div className="flex flex-col gap-2">
<Label htmlFor="email">Email</Label>
<Input
id="email"
placeholder="[email protected]"
{...register('email', { required: true })}
<FormField
control={form.control}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>Candidate Email</FormLabel>
<FormControl>
<Input
placeholder="Email"
{...field}
value={field.value ?? ''}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
</div>

<DialogFooter className="mt-6 w-full justify-between">
<Button
onClick={(e) => {
e.preventDefault();
handleOpenChange(false);
}}
className="max-w-fit"
variant="ghost"
>
Cancel
</Button>
<DialogFooter className="mt-6 w-full justify-between">
<Button
onClick={(e) => {
e.preventDefault();
handleOpenChange(false);
}}
className="max-w-fit"
variant="ghost"
>
Cancel
</Button>

<Button
isLoading={isSubmitting}
disabled={isSubmitting}
className="max-w-fit"
type="submit"
>
Save
</Button>
</DialogFooter>
</form>
<Button
isLoading={form.formState.isSubmitting}
disabled={form.formState.isSubmitting}
className="max-w-fit"
type="submit"
>
Save
</Button>
</DialogFooter>
</form>
</Form>
</DialogContent>
</Dialog>
);
Expand Down
21 changes: 12 additions & 9 deletions components/client/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -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<LucideIcon>;

export const Spinner = ({ className, ...rest }: SpinnerProps) => {
return (
<Loader2 className={cn('h-4 w-4 animate-spin', className)} {...rest} />
);
};
export const Spinner = React.forwardRef<
React.ElementRef<LucideIcon>,
React.ComponentPropsWithoutRef<LucideIcon>
>(({ className, ...rest }, ref) => (
<Loader2
ref={ref}
className={cn('h-4 w-4 animate-spin', className)}
{...rest}
/>
));

0 comments on commit 5d81d66

Please sign in to comment.