refactor: rename product to partyEvent in list page and view component
This commit is contained in:
@@ -6,20 +6,15 @@ Content-Type: application/json
|
||||
{
|
||||
"partyEventData": {
|
||||
"id":"e99f09a7-dd88-49d5-b1c8-1daf80c2d7b01",
|
||||
"title": "Summer Music Festival",
|
||||
"title": "Summer Music Festival 111",
|
||||
"name": "Summer Music Festival 111",
|
||||
"description": "Annual summer music festival featuring local bands and artists",
|
||||
"startDate": "2024-07-15T18:00:00Z",
|
||||
"endDate": "2024-07-15T23:00:00Z",
|
||||
"location": "Central Park, Hong Kong",
|
||||
"coverUrl": "",
|
||||
"images": [
|
||||
"data:image/png;base64,C",
|
||||
"data:image/png;base64,C"
|
||||
],
|
||||
"tags": [
|
||||
"Music",
|
||||
"Festival"
|
||||
],
|
||||
"images": [ "data:image/png;base64,C", "data:image/png;base64,C" ],
|
||||
"tags": [ "Music", "Festival" ],
|
||||
"status": "upcoming",
|
||||
"capacity": 500,
|
||||
"price": 150.00,
|
||||
@@ -30,6 +25,7 @@ Content-Type: application/json
|
||||
"requirements": "Age 18+",
|
||||
"schedule": "18:00 Doors open\n19:00 First performance\n21:00 Main act",
|
||||
"speakers": ["DJ Lee", "Band XYZ"],
|
||||
"sponsors": ["HK Radio", "Music Magazine"]
|
||||
"sponsors": ["HK Radio", "Music Magazine"],
|
||||
"reviews":[]
|
||||
}
|
||||
}
|
||||
|
@@ -76,10 +76,57 @@ async function createEvent(eventData: any) {
|
||||
return await prisma.eventItem.create({ data: eventData });
|
||||
}
|
||||
|
||||
async function updateEvent(eventId: string, updateForm: UpdateEvent) {
|
||||
async function updateEvent(eventId: string, updateForm: any) {
|
||||
return prisma.eventItem.update({
|
||||
where: { id: eventId },
|
||||
data: updateForm,
|
||||
data: {
|
||||
available: updateForm.available,
|
||||
category: updateForm.category,
|
||||
code: updateForm.code,
|
||||
colors: updateForm.colors,
|
||||
coverUrl: updateForm.coverUrl,
|
||||
description: updateForm.description,
|
||||
gender: updateForm.gender,
|
||||
images: updateForm.images,
|
||||
inventoryType: updateForm.inventoryType,
|
||||
name: updateForm.name,
|
||||
newLabel: updateForm.newLabel,
|
||||
price: updateForm.price,
|
||||
priceSale: updateForm.priceSale,
|
||||
publish: updateForm.publish,
|
||||
quantity: updateForm.quantity,
|
||||
ratings: updateForm.ratings,
|
||||
saleLabel: updateForm.saleLabel,
|
||||
sizes: updateForm.sizes,
|
||||
sku: updateForm.sku,
|
||||
subDescription: updateForm.subDescription,
|
||||
tags: updateForm.tags,
|
||||
taxes: updateForm.taxes,
|
||||
totalRatings: updateForm.totalRatings,
|
||||
totalReviews: updateForm.totalReviews,
|
||||
totalSold: updateForm.totalSold,
|
||||
//
|
||||
ageBottom: updateForm.ageBottom,
|
||||
ageTop: updateForm.ageTop,
|
||||
avatar: updateForm.avatar,
|
||||
currency: updateForm.currency,
|
||||
capacity: updateForm.capacity,
|
||||
duration_m: updateForm.duration_m,
|
||||
endDate: updateForm.endDate,
|
||||
eventDate: updateForm.eventDate,
|
||||
isFeatured: updateForm.isFeatured,
|
||||
joinMembers: updateForm.joinMembers,
|
||||
location: updateForm.location,
|
||||
organizer: updateForm.organizer,
|
||||
registrationDeadline: updateForm.registrationDeadline,
|
||||
requirements: updateForm.requirements,
|
||||
schedule: updateForm.schedule,
|
||||
speakers: updateForm.speakers,
|
||||
sponsors: updateForm.sponsors,
|
||||
startDate: updateForm.startDate,
|
||||
status: updateForm.status,
|
||||
title: updateForm.title,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -98,26 +98,26 @@ export function useSearchProducts(query: string) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export async function createProduct(productData: IPartyEventItem) {
|
||||
export async function createPartyEvent(partyEventData: IPartyEventItem) {
|
||||
/**
|
||||
* Work on server
|
||||
*/
|
||||
const data = { productData };
|
||||
const data = { partyEventData };
|
||||
const {
|
||||
data: { id },
|
||||
} = await axiosInstance.post(endpoints.product.create, data);
|
||||
} = await axiosInstance.post(endpoints.partyEvent.create, data);
|
||||
|
||||
/**
|
||||
* Work in local
|
||||
*/
|
||||
mutate(
|
||||
endpoints.product.list,
|
||||
endpoints.partyEvent.list,
|
||||
(currentData: any) => {
|
||||
const currentProducts: IPartyEventItem[] = currentData?.products;
|
||||
const currentPartyEvents: IPartyEventItem[] = currentData?.partyEvents;
|
||||
|
||||
const products = [...currentProducts, { ...productData, id }];
|
||||
const partyEvents = [...currentPartyEvents, { ...partyEventData, id }];
|
||||
|
||||
return { ...currentData, products };
|
||||
return { ...currentData, partyEvents };
|
||||
},
|
||||
false
|
||||
);
|
||||
@@ -125,27 +125,27 @@ export async function createProduct(productData: IPartyEventItem) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export async function updateProduct(productData: Partial<IPartyEventItem>) {
|
||||
export async function updatePartyEvent(partyEventData: Partial<IPartyEventItem>) {
|
||||
/**
|
||||
* Work on server
|
||||
*/
|
||||
const data = { productData };
|
||||
await axiosInstance.put(endpoints.product.update, data);
|
||||
const data = { partyEventData };
|
||||
await axiosInstance.put(endpoints.partyEvent.update, data);
|
||||
|
||||
/**
|
||||
* Work in local
|
||||
*/
|
||||
|
||||
mutate(
|
||||
endpoints.product.list,
|
||||
endpoints.partyEvent.list,
|
||||
(currentData: any) => {
|
||||
const currentProducts: IPartyEventItem[] = currentData?.products;
|
||||
const currentPartyEvents: IPartyEventItem[] = currentData?.partyEvents;
|
||||
|
||||
const products = currentProducts.map((product) =>
|
||||
product.id === productData.id ? { ...product, ...productData } : product
|
||||
const partyEvents = currentPartyEvents.map((partyEvent) =>
|
||||
partyEvent.id === partyEventData.id ? { ...partyEvent, ...partyEventData } : partyEvent
|
||||
);
|
||||
|
||||
return { ...currentData, products };
|
||||
return { ...currentData, partyEvents };
|
||||
},
|
||||
false
|
||||
);
|
||||
@@ -153,26 +153,25 @@ export async function updateProduct(productData: Partial<IPartyEventItem>) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export async function deletePartyEvent(productId: string) {
|
||||
export async function deletePartyEvent(partyEventId: string) {
|
||||
/**
|
||||
* Work on server
|
||||
*/
|
||||
const data = { productId };
|
||||
await axiosInstance.patch(endpoints.product.delete, data);
|
||||
const data = { partyEventId };
|
||||
await axiosInstance.patch(endpoints.partyEvent.delete, data);
|
||||
|
||||
/**
|
||||
* Work in local
|
||||
*/
|
||||
|
||||
mutate(
|
||||
endpoints.product.list,
|
||||
endpoints.partyEvent.list,
|
||||
(currentData: any) => {
|
||||
console.log({ currentData });
|
||||
const currentProducts: IPartyEventItem[] = currentData?.products;
|
||||
const currentProducts: IPartyEventItem[] = currentData?.partyEvents;
|
||||
|
||||
const products = currentProducts.filter((product) => product.id !== productId);
|
||||
const partyEvents = currentProducts.filter((partyEvent) => partyEvent.id !== partyEventId);
|
||||
|
||||
return { ...currentData, products };
|
||||
return { ...currentData, partyEvents };
|
||||
},
|
||||
false
|
||||
);
|
||||
|
@@ -16,7 +16,7 @@ export default function Page() {
|
||||
<>
|
||||
<title>{metadata.title}</title>
|
||||
|
||||
<PartyEventEditView product={partyEvent} />
|
||||
<PartyEventEditView partyEvent={partyEvent} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@@ -1,19 +1,19 @@
|
||||
import { useGetProducts } from 'src/actions/product';
|
||||
import { useGetPartyEvents } from 'src/actions/party-event';
|
||||
import { CONFIG } from 'src/global-config';
|
||||
import { ProductShopView } from 'src/sections/product/view';
|
||||
import { PartyEventShopView } from 'src/sections/party-event/view';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
const metadata = { title: `Product shop - ${CONFIG.appName}` };
|
||||
|
||||
export default function Page() {
|
||||
const { products, productsLoading } = useGetProducts();
|
||||
const { partyEvents, partyEventsLoading } = useGetPartyEvents();
|
||||
|
||||
return (
|
||||
<>
|
||||
<title>{metadata.title}</title>
|
||||
|
||||
<ProductShopView products={products} loading={productsLoading} />
|
||||
<PartyEventShopView products={partyEvents} loading={partyEventsLoading} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ import {
|
||||
PRODUCT_COLOR_NAME_OPTIONS,
|
||||
PRODUCT_SIZE_OPTIONS,
|
||||
} from 'src/_mock';
|
||||
import { createProduct, updateProduct } from 'src/actions/party-event';
|
||||
import { createPartyEvent, updatePartyEvent } from 'src/actions/party-event';
|
||||
import { Field, Form, schemaHelper } from 'src/components/hook-form';
|
||||
import { Iconify } from 'src/components/iconify';
|
||||
import { toast } from 'src/components/snackbar';
|
||||
@@ -81,7 +81,7 @@ const PRODUCT_GENDER_OPTIONS = [
|
||||
{ label: 'Kids', value: 'Kids' },
|
||||
];
|
||||
|
||||
export type NewProductSchemaType = zod.infer<typeof NewProductSchema>;
|
||||
export type NewPartyEventSchemaType = zod.infer<typeof NewProductSchema>;
|
||||
|
||||
export const NewProductSchema = zod.object({
|
||||
sku: zod.string().min(1, { message: 'Product sku is required!' }),
|
||||
@@ -128,10 +128,10 @@ export const NewProductSchema = zod.object({
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
type Props = {
|
||||
currentProduct?: IPartyEventItem;
|
||||
currentPartyEvent?: IPartyEventItem;
|
||||
};
|
||||
|
||||
export function ProductNewEditForm({ currentProduct }: Props) {
|
||||
export function PartyEventNewEditForm({ currentPartyEvent }: Props) {
|
||||
const router = useRouter();
|
||||
|
||||
const openDetails = useBoolean(true);
|
||||
@@ -140,9 +140,9 @@ export function ProductNewEditForm({ currentProduct }: Props) {
|
||||
|
||||
const [includeTaxes, setIncludeTaxes] = useState(false);
|
||||
|
||||
const defaultValues: NewProductSchemaType = {
|
||||
const defaultValues: NewPartyEventSchemaType = {
|
||||
sku: '321',
|
||||
name: 'hello product',
|
||||
name: 'hello party event',
|
||||
code: '123',
|
||||
price: 1.1,
|
||||
taxes: 1.1,
|
||||
@@ -171,10 +171,10 @@ export function ProductNewEditForm({ currentProduct }: Props) {
|
||||
saleLabel: { enabled: false, content: '' },
|
||||
};
|
||||
|
||||
const methods = useForm<NewProductSchemaType>({
|
||||
const methods = useForm<NewPartyEventSchemaType>({
|
||||
resolver: zodResolver(NewProductSchema),
|
||||
defaultValues,
|
||||
values: currentProduct,
|
||||
values: currentPartyEvent,
|
||||
});
|
||||
|
||||
const {
|
||||
@@ -204,17 +204,17 @@ export function ProductNewEditForm({ currentProduct }: Props) {
|
||||
|
||||
const sanitizedValues: IPartyEventItem = values as unknown as IPartyEventItem;
|
||||
|
||||
if (currentProduct) {
|
||||
if (currentPartyEvent) {
|
||||
// perform save
|
||||
updateProduct(sanitizedValues);
|
||||
updatePartyEvent(sanitizedValues);
|
||||
} else {
|
||||
// perform create
|
||||
createProduct(sanitizedValues);
|
||||
createPartyEvent(sanitizedValues);
|
||||
}
|
||||
|
||||
toast.success(currentProduct ? 'Update success!' : 'Create success!');
|
||||
toast.success(currentPartyEvent ? 'Update success!' : 'Create success!');
|
||||
|
||||
router.push(paths.dashboard.product.root);
|
||||
router.push(paths.dashboard.partyEvent.root);
|
||||
|
||||
// console.info('DATA', updatedData);
|
||||
} catch (error) {
|
||||
@@ -542,7 +542,7 @@ export function ProductNewEditForm({ currentProduct }: Props) {
|
||||
/>
|
||||
|
||||
<Button type="submit" variant="contained" size="large" loading={isSubmitting}>
|
||||
{!currentProduct ? 'Create product' : 'Save changes'}
|
||||
{!currentPartyEvent ? 'create-party' : 'save-edit'}
|
||||
</Button>
|
||||
</Box>
|
||||
);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { CustomBreadcrumbs } from 'src/components/custom-breadcrumbs';
|
||||
import { DashboardContent } from 'src/layouts/dashboard';
|
||||
import { paths } from 'src/routes/paths';
|
||||
import { ProductNewEditForm } from '../party-event-new-edit-form';
|
||||
import { PartyEventNewEditForm } from '../party-event-new-edit-form';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@@ -18,7 +18,7 @@ export function PartyEventCreateView() {
|
||||
sx={{ mb: { xs: 3, md: 5 } }}
|
||||
/>
|
||||
|
||||
<ProductNewEditForm />
|
||||
<PartyEventNewEditForm />
|
||||
</DashboardContent>
|
||||
);
|
||||
}
|
||||
|
@@ -2,29 +2,29 @@ import { CustomBreadcrumbs } from 'src/components/custom-breadcrumbs';
|
||||
import { DashboardContent } from 'src/layouts/dashboard';
|
||||
import { paths } from 'src/routes/paths';
|
||||
import type { IPartyEventItem } from 'src/types/party-event';
|
||||
import { ProductNewEditForm } from '../party-event-new-edit-form';
|
||||
import { PartyEventNewEditForm } from '../party-event-new-edit-form';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
type Props = {
|
||||
product?: IPartyEventItem;
|
||||
partyEvent?: IPartyEventItem;
|
||||
};
|
||||
|
||||
export function PartyEventEditView({ product }: Props) {
|
||||
export function PartyEventEditView({ partyEvent }: Props) {
|
||||
return (
|
||||
<DashboardContent>
|
||||
<CustomBreadcrumbs
|
||||
heading="Edit"
|
||||
backHref={paths.dashboard.product.root}
|
||||
backHref={paths.dashboard.partyEvent.root}
|
||||
links={[
|
||||
{ name: 'Dashboard', href: paths.dashboard.root },
|
||||
{ name: 'Product', href: paths.dashboard.product.root },
|
||||
{ name: product?.name },
|
||||
{ name: 'Product', href: paths.dashboard.partyEvent.root },
|
||||
{ name: partyEvent?.name },
|
||||
]}
|
||||
sx={{ mb: { xs: 3, md: 5 } }}
|
||||
/>
|
||||
|
||||
<ProductNewEditForm currentProduct={product} />
|
||||
<PartyEventNewEditForm currentPartyEvent={partyEvent} />
|
||||
</DashboardContent>
|
||||
);
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ type Props = {
|
||||
loading?: boolean;
|
||||
};
|
||||
|
||||
export function ProductShopView({ products, loading }: Props) {
|
||||
export function PartyEventShopView({ products, loading }: Props) {
|
||||
const { state: checkoutState } = useCheckoutContext();
|
||||
|
||||
const openFilters = useBoolean();
|
||||
|
Reference in New Issue
Block a user