gitscope
← marzneshin / v0.5.4 / dashboard/src/features/admins/components/dialogs/mutation/fields/password.tsx
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/features/admins/components/dialogs/mutation/fields/password.tsx · TypeScript
Blame Raw
 1import {
 2    Button,
 3    FormControl,
 4    FormField,
 5    FormItem,
 6    Input,
 7    FormLabel,
 8    FormMessage,
 9} from "@marzneshin/components";
10import { type FC } from "react";
11import { useFormContext } from "react-hook-form";
12import { useTranslation } from "react-i18next";
13
14export const PasswordField: FC<{ change: boolean, handleChange: (s: boolean) => void }> = ({
15    change, handleChange
16}) => {
17    const form = useFormContext();
18    const { t } = useTranslation();
19
20    return (
21        <FormField
22            control={form.control}
23            name="password"
24            render={({ field }) => (
25                <FormItem>
26                    <FormLabel>{t("password")}</FormLabel>
27                    <FormControl>
28                        {change ?
29                            (<Input type="password" {...field} />)
30                            : (
31                                <Button
32                                    className="border w-full"
33                                    variant="ghost"
34                                    onClick={(e) => {
35                                        e.preventDefault();
36                                        handleChange(true);
37                                    }}
38                                >
39                                    {t("change")}
40                                </Button>
41                            )
42                        }
43                    </FormControl>
44                    <FormMessage />
45                </FormItem>
46            )}
47        />
48    );
49};