feat: enhance party user schema with address fields, update frontend form and API calls to use PartyUser naming convention
This commit is contained in:
@@ -1267,12 +1267,13 @@ model PartyUser {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
//
|
||||
name String?
|
||||
username String? @unique
|
||||
password String?
|
||||
//
|
||||
name String?
|
||||
email String @unique
|
||||
emailVerified DateTime?
|
||||
password String?
|
||||
image String?
|
||||
avatarUrl String?
|
||||
bucketImage String?
|
||||
admin Boolean @default(false)
|
||||
accounts Account[]
|
||||
@@ -1283,4 +1284,10 @@ model PartyUser {
|
||||
status String @default("pending")
|
||||
role String @default("")
|
||||
isVerified Boolean @default(false)
|
||||
//
|
||||
country String @default("")
|
||||
state String @default("")
|
||||
city String @default("")
|
||||
address String @default("")
|
||||
zipCode String @default("")
|
||||
}
|
||||
|
@@ -5,16 +5,15 @@ Content-Type: application/json
|
||||
|
||||
{
|
||||
"partyUserData": {
|
||||
"createdAt": "2025-06-15T17:47:24.547Z",
|
||||
"updatedAt": "2025-06-15T17:47:24.547Z",
|
||||
"name": "Alice",
|
||||
"name": "Alice 123321",
|
||||
"username": null,
|
||||
"email": "alice@prisma.io",
|
||||
"email": "alice@123111321.io",
|
||||
"emailVerified": "2025-06-15T17:47:23.919Z",
|
||||
"password": "Aa12345678",
|
||||
"image": null,
|
||||
"bucketImage": null,
|
||||
"admin": false,
|
||||
"info": null
|
||||
"info": null,
|
||||
"phoneNumber": "+85291234567",
|
||||
"avatarUrl": ""
|
||||
}
|
||||
}
|
||||
|
@@ -184,15 +184,29 @@ type CreateUserData = {
|
||||
password: string;
|
||||
};
|
||||
|
||||
export async function createUser(createUserData: CreateUserData) {
|
||||
console.log('create product ?');
|
||||
// const url = productId ? [endpoints.product.details, { params: { productId } }] : '';
|
||||
export async function createPartyUser(partyUserData: CreateUserData) {
|
||||
/**
|
||||
* Work on server
|
||||
*/
|
||||
const data = { partyUserData };
|
||||
const {
|
||||
data: { id },
|
||||
} = await axiosInstance.post(endpoints.partyUser.create, data);
|
||||
|
||||
const res = await axiosInstance.post('http://localhost:7272/api/user/createUser', {
|
||||
data: createUserData,
|
||||
});
|
||||
/**
|
||||
* Work in local
|
||||
*/
|
||||
mutate(
|
||||
endpoints.partyUser.list,
|
||||
(currentData: any) => {
|
||||
const currentPartyUsers: IPartyUserItem[] = currentData?.partyUsers;
|
||||
|
||||
return res;
|
||||
const partyUsers = [...currentPartyUsers, { ...partyUserData, id }];
|
||||
|
||||
return { ...currentData, partyUsers };
|
||||
},
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
@@ -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>
|
||||
|
@@ -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 } }}
|
||||
/>
|
||||
|
Reference in New Issue
Block a user