feat: enhance party user schema with address fields, update frontend form and API calls to use PartyUser naming convention

This commit is contained in:
louiscklaw
2025-06-17 19:59:09 +08:00
parent 834f9360ba
commit ae7f005236
5 changed files with 43 additions and 26 deletions

View File

@@ -11,7 +11,7 @@ import { useState } from 'react';
import { Controller, useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { isValidPhoneNumber } from 'react-phone-number-input/input';
import { createUser, deletePartyUser, updatePartyUser } from 'src/actions/party-user';
import { createPartyUser, deletePartyUser, updatePartyUser } from 'src/actions/party-user';
import { Field, Form, schemaHelper } from 'src/components/hook-form';
import { Label } from 'src/components/label';
import { toast } from 'src/components/snackbar';
@@ -49,6 +49,7 @@ export const NewUserSchema = zod.object({
avatarUrl: zod.string().optional().or(zod.literal('')),
phoneNumber: zod.string().optional().or(zod.literal('')),
isVerified: zod.boolean().default(true),
//
username: zod.string().optional().or(zod.literal('')),
password: zod.string().optional().or(zod.literal('')),
});
@@ -119,9 +120,6 @@ export function PartyUserNewEditForm({ currentUser }: Props) {
const onSubmit = handleSubmit(async (data: any) => {
try {
await new Promise((resolve) => setTimeout(resolve, 500));
reset();
const temp: any = data.avatarUrl;
if (temp instanceof File) {
data.avatarUrl = await fileToBase64(temp);
@@ -134,7 +132,7 @@ export function PartyUserNewEditForm({ currentUser }: Props) {
await updatePartyUser(sanitizedValues);
} else {
// perform create
await createUser(sanitizedValues);
await createPartyUser(sanitizedValues);
}
toast.success(currentUser ? t('Update success!') : t('Create success!'));
@@ -289,14 +287,13 @@ export function PartyUserNewEditForm({ currentUser }: Props) {
</Box>
<Stack sx={{ mt: 3, alignItems: 'flex-end' }}>
<>{JSON.stringify({ errors })}</>
<Button
disabled={isSubmitting}
loading={isSubmitting}
type="submit"
variant="contained"
>
{!currentUser ? t('create-user') : t('save-changes')}
{!currentUser ? t('create user') : t('save changes')}
</Button>
</Stack>
</Card>

View File

@@ -12,12 +12,12 @@ export function UserCreateView() {
return (
<DashboardContent>
<CustomBreadcrumbs
heading={t('Create a new user')}
heading={t('Create a new party user')}
links={[
//
{ name: t('Dashboard'), href: paths.dashboard.root },
{ name: t('User'), href: paths.dashboard.user.root },
{ name: t('New user') },
{ name: t('Party User'), href: paths.dashboard.user.root },
{ name: t('New') },
]}
sx={{ mb: { xs: 3, md: 5 } }}
/>