From 4c2a06585de12d770a89e2679cf129caf589add0 Mon Sep 17 00:00:00 2001 From: louiscklaw Date: Sun, 15 Jun 2025 17:53:47 +0800 Subject: [PATCH] refactor: rename product to partyEvent in list page and view component --- .../src/app/api/party-event/update/test.http | 16 +++--- .../src/app/services/party-event.service.ts | 51 ++++++++++++++++++- 03_source/frontend/src/actions/party-event.ts | 45 ++++++++-------- .../src/pages/dashboard/party-event/edit.tsx | 2 +- .../frontend/src/pages/party-event/list.tsx | 8 +-- .../party-event/party-event-new-edit-form.tsx | 28 +++++----- .../view/party-event-create-view.tsx | 4 +- .../view/party-event-edit-view.tsx | 14 ++--- .../view/party-event-shop-view.tsx | 2 +- 9 files changed, 106 insertions(+), 64 deletions(-) diff --git a/03_source/cms_backend/src/app/api/party-event/update/test.http b/03_source/cms_backend/src/app/api/party-event/update/test.http index a64355c..ff61997 100644 --- a/03_source/cms_backend/src/app/api/party-event/update/test.http +++ b/03_source/cms_backend/src/app/api/party-event/update/test.http @@ -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":[] } } diff --git a/03_source/cms_backend/src/app/services/party-event.service.ts b/03_source/cms_backend/src/app/services/party-event.service.ts index 5b6111b..3404404 100644 --- a/03_source/cms_backend/src/app/services/party-event.service.ts +++ b/03_source/cms_backend/src/app/services/party-event.service.ts @@ -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, + }, }); } diff --git a/03_source/frontend/src/actions/party-event.ts b/03_source/frontend/src/actions/party-event.ts index 9922d46..79add92 100644 --- a/03_source/frontend/src/actions/party-event.ts +++ b/03_source/frontend/src/actions/party-event.ts @@ -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) { +export async function updatePartyEvent(partyEventData: Partial) { /** * 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) { // ---------------------------------------------------------------------- -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 ); diff --git a/03_source/frontend/src/pages/dashboard/party-event/edit.tsx b/03_source/frontend/src/pages/dashboard/party-event/edit.tsx index 7cbc729..7928256 100644 --- a/03_source/frontend/src/pages/dashboard/party-event/edit.tsx +++ b/03_source/frontend/src/pages/dashboard/party-event/edit.tsx @@ -16,7 +16,7 @@ export default function Page() { <> {metadata.title} - + ); } diff --git a/03_source/frontend/src/pages/party-event/list.tsx b/03_source/frontend/src/pages/party-event/list.tsx index afdd483..4a23d1e 100644 --- a/03_source/frontend/src/pages/party-event/list.tsx +++ b/03_source/frontend/src/pages/party-event/list.tsx @@ -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 ( <> {metadata.title} - + ); } diff --git a/03_source/frontend/src/sections/party-event/party-event-new-edit-form.tsx b/03_source/frontend/src/sections/party-event/party-event-new-edit-form.tsx index 0429031..c114a58 100644 --- a/03_source/frontend/src/sections/party-event/party-event-new-edit-form.tsx +++ b/03_source/frontend/src/sections/party-event/party-event-new-edit-form.tsx @@ -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; +export type NewPartyEventSchemaType = zod.infer; 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({ + const methods = useForm({ 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) { /> ); diff --git a/03_source/frontend/src/sections/party-event/view/party-event-create-view.tsx b/03_source/frontend/src/sections/party-event/view/party-event-create-view.tsx index 0d77d8f..4f5255d 100644 --- a/03_source/frontend/src/sections/party-event/view/party-event-create-view.tsx +++ b/03_source/frontend/src/sections/party-event/view/party-event-create-view.tsx @@ -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 } }} /> - + ); } diff --git a/03_source/frontend/src/sections/party-event/view/party-event-edit-view.tsx b/03_source/frontend/src/sections/party-event/view/party-event-edit-view.tsx index 3695568..78956a8 100644 --- a/03_source/frontend/src/sections/party-event/view/party-event-edit-view.tsx +++ b/03_source/frontend/src/sections/party-event/view/party-event-edit-view.tsx @@ -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 ( - + ); } diff --git a/03_source/frontend/src/sections/party-event/view/party-event-shop-view.tsx b/03_source/frontend/src/sections/party-event/view/party-event-shop-view.tsx index 8d63025..c14d62d 100644 --- a/03_source/frontend/src/sections/party-event/view/party-event-shop-view.tsx +++ b/03_source/frontend/src/sections/party-event/view/party-event-shop-view.tsx @@ -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();