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())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
//
|
//
|
||||||
name String?
|
|
||||||
username String? @unique
|
username String? @unique
|
||||||
|
password String?
|
||||||
|
//
|
||||||
|
name String?
|
||||||
email String @unique
|
email String @unique
|
||||||
emailVerified DateTime?
|
emailVerified DateTime?
|
||||||
password String?
|
avatarUrl String?
|
||||||
image String?
|
|
||||||
bucketImage String?
|
bucketImage String?
|
||||||
admin Boolean @default(false)
|
admin Boolean @default(false)
|
||||||
accounts Account[]
|
accounts Account[]
|
||||||
@@ -1283,4 +1284,10 @@ model PartyUser {
|
|||||||
status String @default("pending")
|
status String @default("pending")
|
||||||
role String @default("")
|
role String @default("")
|
||||||
isVerified Boolean @default(false)
|
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": {
|
"partyUserData": {
|
||||||
"createdAt": "2025-06-15T17:47:24.547Z",
|
"name": "Alice 123321",
|
||||||
"updatedAt": "2025-06-15T17:47:24.547Z",
|
|
||||||
"name": "Alice",
|
|
||||||
"username": null,
|
"username": null,
|
||||||
"email": "alice@prisma.io",
|
"email": "alice@123111321.io",
|
||||||
"emailVerified": "2025-06-15T17:47:23.919Z",
|
"emailVerified": "2025-06-15T17:47:23.919Z",
|
||||||
"password": "Aa12345678",
|
"password": "Aa12345678",
|
||||||
"image": null,
|
|
||||||
"bucketImage": null,
|
"bucketImage": null,
|
||||||
"admin": false,
|
"admin": false,
|
||||||
"info": null
|
"info": null,
|
||||||
|
"phoneNumber": "+85291234567",
|
||||||
|
"avatarUrl": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -184,15 +184,29 @@ type CreateUserData = {
|
|||||||
password: string;
|
password: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function createUser(createUserData: CreateUserData) {
|
export async function createPartyUser(partyUserData: CreateUserData) {
|
||||||
console.log('create product ?');
|
/**
|
||||||
// const url = productId ? [endpoints.product.details, { params: { productId } }] : '';
|
* 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 { Controller, useForm } from 'react-hook-form';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { isValidPhoneNumber } from 'react-phone-number-input/input';
|
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 { Field, Form, schemaHelper } from 'src/components/hook-form';
|
||||||
import { Label } from 'src/components/label';
|
import { Label } from 'src/components/label';
|
||||||
import { toast } from 'src/components/snackbar';
|
import { toast } from 'src/components/snackbar';
|
||||||
@@ -49,6 +49,7 @@ export const NewUserSchema = zod.object({
|
|||||||
avatarUrl: zod.string().optional().or(zod.literal('')),
|
avatarUrl: zod.string().optional().or(zod.literal('')),
|
||||||
phoneNumber: zod.string().optional().or(zod.literal('')),
|
phoneNumber: zod.string().optional().or(zod.literal('')),
|
||||||
isVerified: zod.boolean().default(true),
|
isVerified: zod.boolean().default(true),
|
||||||
|
//
|
||||||
username: zod.string().optional().or(zod.literal('')),
|
username: zod.string().optional().or(zod.literal('')),
|
||||||
password: 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) => {
|
const onSubmit = handleSubmit(async (data: any) => {
|
||||||
try {
|
try {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
||||||
reset();
|
|
||||||
|
|
||||||
const temp: any = data.avatarUrl;
|
const temp: any = data.avatarUrl;
|
||||||
if (temp instanceof File) {
|
if (temp instanceof File) {
|
||||||
data.avatarUrl = await fileToBase64(temp);
|
data.avatarUrl = await fileToBase64(temp);
|
||||||
@@ -134,7 +132,7 @@ export function PartyUserNewEditForm({ currentUser }: Props) {
|
|||||||
await updatePartyUser(sanitizedValues);
|
await updatePartyUser(sanitizedValues);
|
||||||
} else {
|
} else {
|
||||||
// perform create
|
// perform create
|
||||||
await createUser(sanitizedValues);
|
await createPartyUser(sanitizedValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
toast.success(currentUser ? t('Update success!') : t('Create success!'));
|
toast.success(currentUser ? t('Update success!') : t('Create success!'));
|
||||||
@@ -289,14 +287,13 @@ export function PartyUserNewEditForm({ currentUser }: Props) {
|
|||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Stack sx={{ mt: 3, alignItems: 'flex-end' }}>
|
<Stack sx={{ mt: 3, alignItems: 'flex-end' }}>
|
||||||
<>{JSON.stringify({ errors })}</>
|
|
||||||
<Button
|
<Button
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
loading={isSubmitting}
|
loading={isSubmitting}
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
>
|
>
|
||||||
{!currentUser ? t('create-user') : t('save-changes')}
|
{!currentUser ? t('create user') : t('save changes')}
|
||||||
</Button>
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Card>
|
</Card>
|
||||||
|
@@ -12,12 +12,12 @@ export function UserCreateView() {
|
|||||||
return (
|
return (
|
||||||
<DashboardContent>
|
<DashboardContent>
|
||||||
<CustomBreadcrumbs
|
<CustomBreadcrumbs
|
||||||
heading={t('Create a new user')}
|
heading={t('Create a new party user')}
|
||||||
links={[
|
links={[
|
||||||
//
|
//
|
||||||
{ name: t('Dashboard'), href: paths.dashboard.root },
|
{ name: t('Dashboard'), href: paths.dashboard.root },
|
||||||
{ name: t('User'), href: paths.dashboard.user.root },
|
{ name: t('Party User'), href: paths.dashboard.user.root },
|
||||||
{ name: t('New user') },
|
{ name: t('New') },
|
||||||
]}
|
]}
|
||||||
sx={{ mb: { xs: 3, md: 5 } }}
|
sx={{ mb: { xs: 3, md: 5 } }}
|
||||||
/>
|
/>
|
||||||
|
Reference in New Issue
Block a user