✨ feat(user): Add user Detail
This commit is contained in:
@@ -1,17 +1,48 @@
|
||||
'use client';
|
||||
|
||||
import {
|
||||
createUserAuthMethod,
|
||||
deleteUserAuthMethod,
|
||||
updateUserAuthMethod,
|
||||
} from '@/services/admin/user';
|
||||
import { Badge } from '@workspace/ui/components/badge';
|
||||
import { Button } from '@workspace/ui/components/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@workspace/ui/components/card';
|
||||
import { EnhancedInput } from '@workspace/ui/custom-components/enhanced-input';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useState } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
export function AuthMethodsForm({ user }: { user: API.User }) {
|
||||
const t = useTranslations('user');
|
||||
|
||||
const [emailChanges, setEmailChanges] = useState<Record<string, string>>({});
|
||||
|
||||
const handleRemoveAuth = async (authType: string) => {};
|
||||
const handleUpdateEmail = async (authType: string) => {};
|
||||
const handleCreateEmail = async (email: string) => {};
|
||||
const handleRemoveAuth = async (authType: string) => {
|
||||
await deleteUserAuthMethod({
|
||||
user_id: user.id,
|
||||
auth_type: authType,
|
||||
});
|
||||
toast.success(t('deleteSuccess'));
|
||||
};
|
||||
|
||||
const handleUpdateEmail = async (email: string) => {
|
||||
await updateUserAuthMethod({
|
||||
user_id: user.id,
|
||||
auth_type: 'email',
|
||||
auth_identifier: email,
|
||||
});
|
||||
toast.success(t('updateSuccess'));
|
||||
};
|
||||
|
||||
const handleCreateEmail = async (email: string) => {
|
||||
await createUserAuthMethod({
|
||||
user_id: user.id,
|
||||
auth_type: 'email',
|
||||
auth_identifier: email,
|
||||
});
|
||||
toast.success(t('createSuccess'));
|
||||
};
|
||||
|
||||
const handleEmailChange = (authType: string, value: string) => {
|
||||
setEmailChanges((prev) => ({
|
||||
@@ -34,7 +65,7 @@ export function AuthMethodsForm({ user }: { user: API.User }) {
|
||||
const handleEmailAction = () => {
|
||||
const email = emailChanges['email'];
|
||||
if (isEmailExists) {
|
||||
handleUpdateEmail('email');
|
||||
handleUpdateEmail(email as string);
|
||||
} else {
|
||||
handleCreateEmail(email as string);
|
||||
}
|
||||
@@ -43,7 +74,7 @@ export function AuthMethodsForm({ user }: { user: API.User }) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Authentication Settings</CardTitle>
|
||||
<CardTitle>{t('authMethodsTitle')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className='space-y-6'>
|
||||
<div className='space-y-6'>
|
||||
@@ -52,14 +83,14 @@ export function AuthMethodsForm({ user }: { user: API.User }) {
|
||||
<div className='flex items-center justify-between'>
|
||||
<div className='font-medium uppercase'>email</div>
|
||||
<Badge variant={defaultEmailMethod.verified ? 'default' : 'destructive'}>
|
||||
{defaultEmailMethod.verified ? 'Verified' : 'Unverified'}
|
||||
{defaultEmailMethod.verified ? t('verified') : t('unverified')}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className='flex items-center gap-2'>
|
||||
<div className='flex-1'>
|
||||
<EnhancedInput
|
||||
value={defaultEmailMethod.auth_identifier}
|
||||
placeholder='Please enter email'
|
||||
placeholder={t('pleaseEnterEmail')}
|
||||
onValueChange={(value) => handleEmailChange('email', value as string)}
|
||||
/>
|
||||
</div>
|
||||
@@ -70,7 +101,7 @@ export function AuthMethodsForm({ user }: { user: API.User }) {
|
||||
(isEmailExists && emailChanges['email'] === defaultEmailMethod.auth_identifier)
|
||||
}
|
||||
>
|
||||
{isEmailExists ? 'Update' : 'Add'}
|
||||
{isEmailExists ? t('update') : t('add')}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
@@ -82,7 +113,7 @@ export function AuthMethodsForm({ user }: { user: API.User }) {
|
||||
<div className='flex items-center justify-between'>
|
||||
<div className='font-medium uppercase'>{method.auth_type}</div>
|
||||
<Badge variant={method.verified ? 'default' : 'destructive'}>
|
||||
{method.verified ? 'Verified' : 'Unverified'}
|
||||
{method.verified ? t('verified') : t('unverified')}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className='flex items-center gap-4'>
|
||||
@@ -94,7 +125,7 @@ export function AuthMethodsForm({ user }: { user: API.User }) {
|
||||
size='sm'
|
||||
onClick={() => handleRemoveAuth(method.auth_type)}
|
||||
>
|
||||
Remove
|
||||
{t('remove')}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import useGlobalStore from '@/config/use-global';
|
||||
import { updateUser } from '@/services/admin/user';
|
||||
import { updateUserBasicInfo } from '@/services/admin/user';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { Button } from '@workspace/ui/components/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@workspace/ui/components/card';
|
||||
@@ -18,6 +18,7 @@ import { Switch } from '@workspace/ui/components/switch';
|
||||
import { EnhancedInput } from '@workspace/ui/custom-components/enhanced-input';
|
||||
import { UploadImage } from '@workspace/ui/custom-components/upload-image';
|
||||
import { unitConversion } from '@workspace/ui/utils';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { toast } from 'sonner';
|
||||
import * as z from 'zod';
|
||||
@@ -37,6 +38,8 @@ const basicInfoSchema = z.object({
|
||||
type BasicInfoValues = z.infer<typeof basicInfoSchema>;
|
||||
|
||||
export function BasicInfoForm({ user }: { user: API.User }) {
|
||||
const t = useTranslations('user');
|
||||
|
||||
const { common } = useGlobalStore();
|
||||
const { currency } = common;
|
||||
|
||||
@@ -55,11 +58,12 @@ export function BasicInfoForm({ user }: { user: API.User }) {
|
||||
});
|
||||
|
||||
async function onSubmit(data: BasicInfoValues) {
|
||||
await updateUser({
|
||||
id: user.id,
|
||||
await updateUserBasicInfo({
|
||||
user_id: user.id,
|
||||
telegram: user.telegram,
|
||||
...data,
|
||||
} as API.UpdateUserRequest);
|
||||
toast.success('Saved successfully');
|
||||
} as API.UpdateUserBasiceInfoRequest);
|
||||
toast.success(t('updateSuccess'));
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -67,9 +71,9 @@ export function BasicInfoForm({ user }: { user: API.User }) {
|
||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||
<Card>
|
||||
<CardHeader className='flex flex-row items-center justify-between'>
|
||||
<CardTitle>Basic Information</CardTitle>
|
||||
<CardTitle>{t('basicInfoTitle')}</CardTitle>
|
||||
<Button type='submit' size='sm'>
|
||||
Save
|
||||
{t('save')}
|
||||
</Button>
|
||||
</CardHeader>
|
||||
<CardContent className='space-y-4'>
|
||||
@@ -78,7 +82,7 @@ export function BasicInfoForm({ user }: { user: API.User }) {
|
||||
name='enable'
|
||||
render={({ field }) => (
|
||||
<FormItem className='flex items-center justify-between space-x-2'>
|
||||
<FormLabel>Account Enable</FormLabel>
|
||||
<FormLabel>{t('accountEnable')}</FormLabel>
|
||||
<FormControl>
|
||||
<Switch checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
@@ -91,7 +95,7 @@ export function BasicInfoForm({ user }: { user: API.User }) {
|
||||
name='is_admin'
|
||||
render={({ field }) => (
|
||||
<FormItem className='flex items-center justify-between space-x-2'>
|
||||
<FormLabel>Administrator</FormLabel>
|
||||
<FormLabel>{t('administrator')}</FormLabel>
|
||||
<FormControl>
|
||||
<Switch checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
@@ -104,7 +108,7 @@ export function BasicInfoForm({ user }: { user: API.User }) {
|
||||
name='balance'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Balance</FormLabel>
|
||||
<FormLabel>{t('balance')}</FormLabel>
|
||||
<FormControl>
|
||||
<EnhancedInput
|
||||
type='number'
|
||||
@@ -127,7 +131,7 @@ export function BasicInfoForm({ user }: { user: API.User }) {
|
||||
name='commission'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Commission</FormLabel>
|
||||
<FormLabel>{t('commission')}</FormLabel>
|
||||
<FormControl>
|
||||
<EnhancedInput
|
||||
type='number'
|
||||
@@ -150,7 +154,7 @@ export function BasicInfoForm({ user }: { user: API.User }) {
|
||||
name='gift_amount'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Gift Amount</FormLabel>
|
||||
<FormLabel>{t('giftAmount')}</FormLabel>
|
||||
<FormControl>
|
||||
<EnhancedInput
|
||||
type='number'
|
||||
@@ -175,7 +179,7 @@ export function BasicInfoForm({ user }: { user: API.User }) {
|
||||
name='refer_code'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Referral Code</FormLabel>
|
||||
<FormLabel>{t('referralCode')}</FormLabel>
|
||||
<FormControl>
|
||||
<EnhancedInput
|
||||
value={field.value}
|
||||
@@ -193,7 +197,7 @@ export function BasicInfoForm({ user }: { user: API.User }) {
|
||||
name='referer_id'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Referrer (User ID)</FormLabel>
|
||||
<FormLabel>{t('referrerUserId')}</FormLabel>
|
||||
<FormControl>
|
||||
<EnhancedInput
|
||||
type='number'
|
||||
@@ -213,7 +217,7 @@ export function BasicInfoForm({ user }: { user: API.User }) {
|
||||
name='avatar'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Avatar</FormLabel>
|
||||
<FormLabel>{t('avatar')}</FormLabel>
|
||||
<FormControl>
|
||||
<EnhancedInput
|
||||
value={field.value}
|
||||
@@ -238,9 +242,9 @@ export function BasicInfoForm({ user }: { user: API.User }) {
|
||||
name='password'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Password</FormLabel>
|
||||
<FormLabel>{t('password')}</FormLabel>
|
||||
<FormControl>
|
||||
<Input type='password' placeholder='Leave empty to keep unchanged' {...field} />
|
||||
<Input type='password' placeholder={t('passwordPlaceholder')} {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
'use client';
|
||||
|
||||
import { updateUserNotifySetting } from '@/services/admin/user';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { Button } from '@workspace/ui/components/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@workspace/ui/components/card';
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel } from '@workspace/ui/components/form';
|
||||
import { Switch } from '@workspace/ui/components/switch';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { toast } from 'sonner';
|
||||
import * as z from 'zod';
|
||||
@@ -21,6 +23,8 @@ const notifySettingsSchema = z.object({
|
||||
type NotifySettingsValues = z.infer<typeof notifySettingsSchema>;
|
||||
|
||||
export function NotifySettingsForm({ user }: { user: API.User }) {
|
||||
const t = useTranslations('user');
|
||||
|
||||
const form = useForm<NotifySettingsValues>({
|
||||
resolver: zodResolver(notifySettingsSchema),
|
||||
defaultValues: {
|
||||
@@ -34,7 +38,11 @@ export function NotifySettingsForm({ user }: { user: API.User }) {
|
||||
});
|
||||
|
||||
async function onSubmit(data: NotifySettingsValues) {
|
||||
toast.warning('In Development...');
|
||||
await updateUserNotifySetting({
|
||||
...data,
|
||||
user_id: user.id,
|
||||
});
|
||||
toast.success(t('updateSuccess'));
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -42,9 +50,9 @@ export function NotifySettingsForm({ user }: { user: API.User }) {
|
||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||
<Card>
|
||||
<CardHeader className='flex flex-row items-center justify-between'>
|
||||
<CardTitle>Notification Settings</CardTitle>
|
||||
<CardTitle>{t('notifySettingsTitle')}</CardTitle>
|
||||
<Button type='submit' size='sm'>
|
||||
Save
|
||||
{t('save')}
|
||||
</Button>
|
||||
</CardHeader>
|
||||
<CardContent className='space-y-4'>
|
||||
@@ -54,7 +62,7 @@ export function NotifySettingsForm({ user }: { user: API.User }) {
|
||||
name='enable_email_notify'
|
||||
render={({ field }) => (
|
||||
<FormItem className='flex items-center justify-between space-x-2'>
|
||||
<FormLabel>Email Notifications</FormLabel>
|
||||
<FormLabel>{t('emailNotifications')}</FormLabel>
|
||||
<FormControl>
|
||||
<Switch checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
@@ -67,7 +75,7 @@ export function NotifySettingsForm({ user }: { user: API.User }) {
|
||||
name='enable_telegram_notify'
|
||||
render={({ field }) => (
|
||||
<FormItem className='flex items-center justify-between space-x-2'>
|
||||
<FormLabel>Telegram Notifications</FormLabel>
|
||||
<FormLabel>{t('telegramNotifications')}</FormLabel>
|
||||
<FormControl>
|
||||
<Switch checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
@@ -80,7 +88,7 @@ export function NotifySettingsForm({ user }: { user: API.User }) {
|
||||
name='enable_balance_notify'
|
||||
render={({ field }) => (
|
||||
<FormItem className='flex items-center justify-between space-x-2'>
|
||||
<FormLabel>Balance Change Notifications</FormLabel>
|
||||
<FormLabel>{t('balanceNotifications')}</FormLabel>
|
||||
<FormControl>
|
||||
<Switch checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
@@ -93,7 +101,7 @@ export function NotifySettingsForm({ user }: { user: API.User }) {
|
||||
name='enable_login_notify'
|
||||
render={({ field }) => (
|
||||
<FormItem className='flex items-center justify-between space-x-2'>
|
||||
<FormLabel>Login Notifications</FormLabel>
|
||||
<FormLabel>{t('loginNotifications')}</FormLabel>
|
||||
<FormControl>
|
||||
<Switch checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
@@ -106,7 +114,7 @@ export function NotifySettingsForm({ user }: { user: API.User }) {
|
||||
name='enable_subscribe_notify'
|
||||
render={({ field }) => (
|
||||
<FormItem className='flex items-center justify-between space-x-2'>
|
||||
<FormLabel>Subscription Notifications</FormLabel>
|
||||
<FormLabel>{t('subscriptionNotifications')}</FormLabel>
|
||||
<FormControl>
|
||||
<Switch checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
@@ -119,7 +127,7 @@ export function NotifySettingsForm({ user }: { user: API.User }) {
|
||||
name='enable_trade_notify'
|
||||
render={({ field }) => (
|
||||
<FormItem className='flex items-center justify-between space-x-2'>
|
||||
<FormLabel>Trade Notifications</FormLabel>
|
||||
<FormLabel>{t('tradeNotifications')}</FormLabel>
|
||||
<FormControl>
|
||||
<Switch checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
|
||||
Reference in New Issue
Block a user