diff options
| author | joonhoekim <26rote@gmail.com> | 2025-08-22 03:11:57 +0000 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-08-22 03:11:57 +0000 |
| commit | dbdae213e39b82ff8ee565df0774bd2f72f06140 (patch) | |
| tree | 37ff13e5784426328c40408e960699af554aeb24 /lib/admin-users/table/add-ausers-dialog.tsx | |
| parent | 01296fafda2b52339727ca445de39c6ccb3ba03d (diff) | |
(김준회) 로그인 에러 토스트 메시지 개선, 중공업 유저의 협력사 유저 추가/수정시 전화번호 사용 반영
Diffstat (limited to 'lib/admin-users/table/add-ausers-dialog.tsx')
| -rw-r--r-- | lib/admin-users/table/add-ausers-dialog.tsx | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/lib/admin-users/table/add-ausers-dialog.tsx b/lib/admin-users/table/add-ausers-dialog.tsx index 64941965..3b29adcf 100644 --- a/lib/admin-users/table/add-ausers-dialog.tsx +++ b/lib/admin-users/table/add-ausers-dialog.tsx @@ -47,12 +47,31 @@ import { Check, ChevronsUpDown, Loader } from "lucide-react" import { cn } from "@/lib/utils" import { toast } from "sonner" import { Vendor } from "@/db/schema/vendors" +import { FormDescription } from "@/components/ui/form" const languageOptions = [ { value: "ko", label: "한국어" }, { value: "en", label: "English" }, ] +// Phone validation helper +const validatePhoneNumber = (phone: string): boolean => { + if (!phone) return true; // Optional field + // Basic international phone number validation + const cleanPhone = phone.replace(/[\s\-\(\)]/g, ''); + return /^\+\d{3,20}$/.test(cleanPhone); +}; + +// Get phone placeholder +const getPhonePlaceholder = (): string => { + return "+82-10-1234-5678"; +}; + +// Get phone description +const getPhoneDescription = (): string => { + return "국제 전화번호를 입력하세요. (예: +82-10-1234-5678)"; +}; + export function AddUserDialog() { const [open, setOpen] = React.useState(false) @@ -74,11 +93,12 @@ export function AddUserDialog() { }, []) // react-hook-form 세팅 - const form = useForm<CreateUserSchema & { language?: string }>({ + const form = useForm<CreateUserSchema & { language?: string; phone?: string }>({ resolver: zodResolver(createUserSchema), defaultValues: { name: "", email: "", + phone: "", // Add phone field companyId: null, language:'en', // roles는 array<string>, 여기서는 단일 선택 시 [role]로 담음 @@ -89,9 +109,11 @@ export function AddUserDialog() { }) - async function onSubmit(data: CreateUserSchema & { language?: string }) { + async function onSubmit(data: CreateUserSchema & { language?: string; phone?: string }) { data.domain = "partners" + // Phone validation is now handled by zod schema + // 만약 단일 Select로 role을 정했다면, data.roles = ["manager"] 이런 식 startAddTransition(async ()=> { const result = await createAdminUser(data) @@ -171,6 +193,30 @@ export function AddUserDialog() { )} /> + {/* 전화번호 - 새로 추가 */} + <FormField + control={form.control} + name="phone" + render={({ field }) => ( + <FormItem> + <FormLabel>Phone Number</FormLabel> + <FormControl> + <Input + placeholder={getPhonePlaceholder()} + {...field} + className={cn( + field.value && !validatePhoneNumber(field.value) && "border-red-500" + )} + /> + </FormControl> + <FormDescription className="text-xs text-muted-foreground"> + {getPhoneDescription()} + </FormDescription> + <FormMessage /> + </FormItem> + )} + /> + {/* 회사 선택 (companyId) */} <FormField control={form.control} |
