From ecdbc45c4a4f9ea4b548fc9c8cec08217b90ba2e Mon Sep 17 00:00:00 2001 From: louiscklaw Date: Sun, 15 Jun 2025 16:44:27 +0800 Subject: [PATCH] refactor: rename product to partyEvent in API route, types and frontend components --- .../src/app/api/party-event/details/route.ts | 16 ++++---- .../src/app/api/party-event/details/test.http | 2 +- 03_source/frontend/src/actions/party-event.ts | 14 +++---- .../pages/dashboard/party-event/details.tsx | 2 +- 03_source/frontend/src/routes/paths.ts | 7 ++++ .../party-event-details-summary.tsx | 8 ++-- .../view/party-event-details-view.tsx | 38 +++++++++---------- .../view/party-event-shop-details-view.tsx | 6 +-- 8 files changed, 50 insertions(+), 43 deletions(-) diff --git a/03_source/cms_backend/src/app/api/party-event/details/route.ts b/03_source/cms_backend/src/app/api/party-event/details/route.ts index 590acf6..e96fa0c 100644 --- a/03_source/cms_backend/src/app/api/party-event/details/route.ts +++ b/03_source/cms_backend/src/app/api/party-event/details/route.ts @@ -31,23 +31,23 @@ export async function GET(req: NextRequest) { const { searchParams } = req.nextUrl; // RULES: eventId must exist - const eventId = searchParams.get('eventId'); - if (!eventId) { - return response({ message: 'Event ID is required!' }, STATUS.BAD_REQUEST); + const partyEventId = searchParams.get('partyEventId'); + if (!partyEventId) { + return response({ message: 'PartyEvent ID is required!' }, STATUS.BAD_REQUEST); } // NOTE: eventId confirmed exist, run below - const event = await getEvent(eventId); + const partyEvent = await getEvent(partyEventId); - if (!event) { - return response({ message: 'Event not found!' }, STATUS.NOT_FOUND); + if (!partyEvent) { + return response({ message: 'PartyEvent not found!' }, STATUS.NOT_FOUND); } - logger('[PartyEvent] details', event.id); + logger('[PartyEvent] details', partyEvent.id); createAppLog(L_INFO, 'Get event detail OK', debug); - return response({ event }, STATUS.OK); + return response({ partyEvent }, STATUS.OK); } catch (error) { createAppLog(L_ERROR, 'event detail error', debug); diff --git a/03_source/cms_backend/src/app/api/party-event/details/test.http b/03_source/cms_backend/src/app/api/party-event/details/test.http index 414b66f..14a9672 100644 --- a/03_source/cms_backend/src/app/api/party-event/details/test.http +++ b/03_source/cms_backend/src/app/api/party-event/details/test.http @@ -1,7 +1,7 @@ ### # Get details for a specific party event -GET http://localhost:7272/api/party-event/details?eventId=e99f09a7-dd88-49d5-b1c8-1daf80c2d7b01 +GET http://localhost:7272/api/party-event/details?partyEventId=e99f09a7-dd88-49d5-b1c8-1daf80c2d7b01 ### diff --git a/03_source/frontend/src/actions/party-event.ts b/03_source/frontend/src/actions/party-event.ts index 2556316..9922d46 100644 --- a/03_source/frontend/src/actions/party-event.ts +++ b/03_source/frontend/src/actions/party-event.ts @@ -45,24 +45,24 @@ export function useGetPartyEvents() { // ---------------------------------------------------------------------- -type ProductData = { - product: IPartyEventItem; +type PartyEventData = { + partyEvent: IPartyEventItem; }; -export function useGetPartyEvent(productId: string) { - const url = productId ? [endpoints.product.details, { params: { productId } }] : ''; +export function useGetPartyEvent(partyEventId: string) { + const url = partyEventId ? [endpoints.partyEvent.details, { params: { partyEventId } }] : ''; - const { data, isLoading, error, isValidating } = useSWR(url, fetcher, swrOptions); + const { data, isLoading, error, isValidating } = useSWR(url, fetcher, swrOptions); const memoizedValue = useMemo( () => ({ - partyEvent: data?.product, + partyEvent: data?.partyEvent, partyEventLoading: isLoading, partyEventError: error, partyEventValidating: isValidating, mutate, }), - [data?.product, error, isLoading, isValidating] + [data?.partyEvent, error, isLoading, isValidating] ); return memoizedValue; diff --git a/03_source/frontend/src/pages/dashboard/party-event/details.tsx b/03_source/frontend/src/pages/dashboard/party-event/details.tsx index 160c1af..c4a64bd 100644 --- a/03_source/frontend/src/pages/dashboard/party-event/details.tsx +++ b/03_source/frontend/src/pages/dashboard/party-event/details.tsx @@ -19,7 +19,7 @@ export default function Page() { {metadata.title} diff --git a/03_source/frontend/src/routes/paths.ts b/03_source/frontend/src/routes/paths.ts index 999fbe8..902c0a8 100644 --- a/03_source/frontend/src/routes/paths.ts +++ b/03_source/frontend/src/routes/paths.ts @@ -87,6 +87,13 @@ export const paths = { verify: `${ROOTS.AUTH_DEMO}/centered/verify`, }, }, + // + partyEvent: { + root: `/party-event`, + checkout: `/party-event/checkout`, + details: (id: string) => `/party-event/${id}`, + demo: { details: `/party-event/${MOCK_ID}` }, + }, // DASHBOARD dashboard: { root: ROOTS.DASHBOARD, diff --git a/03_source/frontend/src/sections/party-event/party-event-details-summary.tsx b/03_source/frontend/src/sections/party-event/party-event-details-summary.tsx index 38b859b..83012c5 100644 --- a/03_source/frontend/src/sections/party-event/party-event-details-summary.tsx +++ b/03_source/frontend/src/sections/party-event/party-event-details-summary.tsx @@ -23,15 +23,15 @@ import { fCurrency, fShortenNumber } from 'src/utils/format-number'; // ---------------------------------------------------------------------- type Props = { - product: IPartyEventItem; + partyEvent: IPartyEventItem; disableActions?: boolean; items?: CheckoutContextValue['state']['items']; onAddToCart?: CheckoutContextValue['onAddToCart']; }; -export function ProductDetailsSummary({ +export function PartyEventDetailsSummary({ items, - product, + partyEvent, onAddToCart, disableActions, ...other @@ -53,7 +53,7 @@ export function ProductDetailsSummary({ totalReviews, inventoryType, subDescription, - } = product; + } = partyEvent; const existProduct = !!items?.length && items.map((item) => item.id).includes(id); diff --git a/03_source/frontend/src/sections/party-event/view/party-event-details-view.tsx b/03_source/frontend/src/sections/party-event/view/party-event-details-view.tsx index 42bef08..e0dff56 100644 --- a/03_source/frontend/src/sections/party-event/view/party-event-details-view.tsx +++ b/03_source/frontend/src/sections/party-event/view/party-event-details-view.tsx @@ -21,7 +21,7 @@ import type { IPartyEventItem } from 'src/types/party-event'; import { ProductDetailsCarousel } from '../party-event-details-carousel'; import { ProductDetailsDescription } from '../party-event-details-description'; import { ProductDetailsReview } from '../party-event-details-review'; -import { ProductDetailsSummary } from '../party-event-details-summary'; +import { PartyEventDetailsSummary } from '../party-event-details-summary'; import { ProductDetailsToolbar } from '../party-event-details-toolbar'; import { ProductDetailsSkeleton } from '../party-event-skeleton'; @@ -48,12 +48,12 @@ const SUMMARY = [ // ---------------------------------------------------------------------- type Props = { - product?: IPartyEventItem; + partyEvent?: IPartyEventItem; loading?: boolean; error?: any; }; -export function PartyEventDetailsView({ product, error, loading }: Props) { +export function PartyEventDetailsView({ partyEvent, error, loading }: Props) { const { t } = useTranslation(); const tabs = useTabs('description'); @@ -61,10 +61,10 @@ export function PartyEventDetailsView({ product, error, loading }: Props) { const [publish, setPublish] = useState(''); useEffect(() => { - if (product) { - setPublish(product?.publish); + if (partyEvent) { + setPublish(partyEvent?.publish); } - }, [product]); + }, [partyEvent]); const handleChangePublish = useCallback((newValue: string) => { setPublish(newValue); @@ -88,11 +88,11 @@ export function PartyEventDetailsView({ product, error, loading }: Props) { } sx={{ mt: 3 }} > @@ -108,9 +108,9 @@ export function PartyEventDetailsView({ product, error, loading }: Props) { return ( - + - {product && } + {partyEvent && } @@ -162,22 +162,22 @@ export function PartyEventDetailsView({ product, error, loading }: Props) { > {[ { value: 'description', label: 'Description' }, - { value: 'reviews', label: `Reviews (${product?.reviews.length})` }, + { value: 'reviews', label: `Reviews (${partyEvent?.reviews.length})` }, ].map((tab) => ( ))} {tabs.value === 'description' && ( - + )} {tabs.value === 'reviews' && ( )} diff --git a/03_source/frontend/src/sections/party-event/view/party-event-shop-details-view.tsx b/03_source/frontend/src/sections/party-event/view/party-event-shop-details-view.tsx index 4da0428..5fbf18c 100644 --- a/03_source/frontend/src/sections/party-event/view/party-event-shop-details-view.tsx +++ b/03_source/frontend/src/sections/party-event/view/party-event-shop-details-view.tsx @@ -21,7 +21,7 @@ import { CartIcon } from '../cart-icon'; import { ProductDetailsCarousel } from '../party-event-details-carousel'; import { ProductDetailsDescription } from '../party-event-details-description'; import { ProductDetailsReview } from '../party-event-details-review'; -import { ProductDetailsSummary } from '../party-event-details-summary'; +import { PartyEventDetailsSummary } from '../party-event-details-summary'; import { ProductDetailsSkeleton } from '../party-event-skeleton'; // ---------------------------------------------------------------------- @@ -113,8 +113,8 @@ export function ProductShopDetailsView({ product, error, loading }: Props) { {product && ( -