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