diff --git a/apps/admin/app/dashboard/auth-control/phone/page.tsx b/apps/admin/app/dashboard/auth-control/phone/page.tsx index c946af0..a8e94a8 100644 --- a/apps/admin/app/dashboard/auth-control/phone/page.tsx +++ b/apps/admin/app/dashboard/auth-control/phone/page.tsx @@ -208,48 +208,44 @@ export default function Page() { /> - - - - {platformConfig?.sms_template_code && ( + {platformConfig?.sms_template_code && ( + + +

{t('platformConfigTip', { key: platformConfig?.sms_template_code })}

- )} -
- - updateConfig('sms_template_code', value)} - disabled={isFetching} - placeholder={ - platformConfig?.sms_template_code && - t('platformConfigTip', { key: platformConfig?.sms_template_code }) - } - /> - -
- - - - {platformConfig?.sms_template_param && ( + + + updateConfig('sms_template_code', value)} + disabled={isFetching} + placeholder={t('platformConfigTip', { key: platformConfig?.sms_template_code })} + /> + + + )} + {platformConfig?.sms_template_param && ( + + +

{t('platformConfigTip', { key: platformConfig?.sms_template_param })}

- )} -
- - updateConfig('sms_template_param', value)} - disabled={isFetching} - placeholder={ - platformConfig?.sms_template_param && - t('platformConfigTip', { key: platformConfig?.sms_template_param }) - } - /> - -
+
+ + updateConfig('sms_template_param', value)} + disabled={isFetching} + placeholder={t('platformConfigTip', { + key: platformConfig?.sms_template_param, + })} + /> + +
+ )} diff --git a/apps/admin/app/dashboard/user/page.tsx b/apps/admin/app/dashboard/user/page.tsx index aac7a51..c16043c 100644 --- a/apps/admin/app/dashboard/user/page.tsx +++ b/apps/admin/app/dashboard/user/page.tsx @@ -75,6 +75,14 @@ export default function Page() { accessorKey: 'email', header: t('userName'), }, + { + accessorKey: 'telephone', + header: t('telephone'), + cell: ({ row }) => { + if (!row.original.telephone) return '--'; + return `+${row.original.telephone_area_code} ${row.original.telephone}`; + }, + }, { accessorKey: 'balance', header: t('balance'), diff --git a/apps/admin/app/dashboard/user/user-form.tsx b/apps/admin/app/dashboard/user/user-form.tsx index 20ed829..abe864d 100644 --- a/apps/admin/app/dashboard/user/user-form.tsx +++ b/apps/admin/app/dashboard/user/user-form.tsx @@ -22,6 +22,7 @@ import { SheetTrigger, } from '@workspace/ui/components/sheet'; import { Switch } from '@workspace/ui/components/switch'; +import { AreaCodeSelect } from '@workspace/ui/custom-components/area-code-select'; import { EnhancedInput } from '@workspace/ui/custom-components/enhanced-input'; import { unitConversion } from '@workspace/ui/utils'; import { useTranslations } from 'next-intl'; @@ -52,6 +53,8 @@ export default function UserForm>({ const [open, setOpen] = useState(false); const formSchema = z.object({ email: z.string().email(t('form.invalidEmailFormat')), + telephone_area_code: z.string().optional(), + telephone: z.string().optional(), password: z.string().optional(), referer_id: z.number().optional(), refer_code: z.string().optional(), @@ -115,6 +118,48 @@ export default function UserForm>({ )} /> + + ( + + {t('form.telephone')} + + ( + + + { + form.setValue(field.name, value.phone); + }} + /> + + + + )} + /> + } + placeholder={t('form.telephonePlaceholder')} + {...field} + onValueChange={(value) => { + form.setValue(field.name, value); + }} + /> + + + + )} + /> void; className?: string; placeholder?: string; + simple?: boolean; } const items = countries @@ -30,34 +43,73 @@ export const AreaCodeSelect = ({ onChange, className, placeholder = 'Select Area Code', + simple = false, }: AreaCodeSelectProps) => { - const [selectedIndex, setSelectedIndex] = useState(-1); + const [open, setOpen] = useState(false); + const [selectedItem, setSelectedItem] = useState(); useEffect(() => { - const index = items.findIndex((item) => item.phone === value); - setSelectedIndex(index); - }, [value]); + if (value !== selectedItem?.phone) { + const found = items.find((item) => item.phone === value); + setSelectedItem(found); + } + }, [selectedItem?.phone, value]); return ( - ({ - label: `+${item.phone} (${item.name})`, - value: index, - children: ( -
- +{item.phone}{' '} - ({item.name}) -
- ), - }))} - value={selectedIndex >= 0 ? selectedIndex : undefined} - onChange={(index) => { - if (typeof index !== 'number') return; - setSelectedIndex(index); - if (items[index]) onChange?.(items[index]); - }} - /> + + + + + + + + + + + + + {items.map((item) => ( + { + setSelectedItem(item); + onChange?.(item); + setOpen(false); + }} + > +
+ + + {item.phone} ({item.name}) +
+ +
+ ))} +
+
+
+
+
); }; diff --git a/packages/ui/src/custom-components/enhanced-input.tsx b/packages/ui/src/custom-components/enhanced-input.tsx index 6ae90b2..ccb37f3 100644 --- a/packages/ui/src/custom-components/enhanced-input.tsx +++ b/packages/ui/src/custom-components/enhanced-input.tsx @@ -4,8 +4,8 @@ import { ChangeEvent, ReactNode, useEffect, useState } from 'react'; export interface EnhancedInputProps extends Omit, 'prefix'> { - prefix?: ReactNode; - suffix?: ReactNode; + prefix?: string | ReactNode; + suffix?: string | ReactNode; formatInput?: (value: string | number) => string; formatOutput?: (value: string | number) => string | number; onValueChange?: (value: string | number) => void; @@ -70,29 +70,38 @@ export function EnhancedInput({ onValueBlur?.(outputValue); } }; + const renderPrefix = () => { + return typeof prefix === 'string' ? ( +
{prefix}
+ ) : ( + prefix + ); + }; + const renderSuffix = () => { + return typeof suffix === 'string' ? ( +
{suffix}
+ ) : ( + suffix + ); + }; return (
- {prefix && ( -
- {prefix} -
- )} + {renderPrefix()} - {suffix && ( -
- {suffix} -
- )} + {renderSuffix()}
); }