refactor: rename product to partyEvent in API route, types and frontend components

This commit is contained in:
louiscklaw
2025-06-15 16:44:27 +08:00
parent 4b64778b59
commit ecdbc45c4a
8 changed files with 50 additions and 43 deletions

View File

@@ -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);

View File

@@ -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
###

View File

@@ -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<ProductData>(url, fetcher, swrOptions);
const { data, isLoading, error, isValidating } = useSWR<PartyEventData>(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;

View File

@@ -19,7 +19,7 @@ export default function Page() {
<title>{metadata.title}</title>
<PartyEventDetailsView
product={partyEvent}
partyEvent={partyEvent}
loading={partyEventLoading}
error={partyEventError}
/>

View File

@@ -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,

View File

@@ -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);

View File

@@ -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) {
<DashboardContent sx={{ pt: 5 }}>
<EmptyContent
filled
title={t('Product not found!')}
title={t('Party event not found!')}
action={
<Button
component={RouterLink}
href={paths.dashboard.product.root}
href={paths.dashboard.partyEvent.root}
startIcon={<Iconify width={16} icon="eva:arrow-ios-back-fill" />}
sx={{ mt: 3 }}
>
@@ -108,9 +108,9 @@ export function PartyEventDetailsView({ product, error, loading }: Props) {
return (
<DashboardContent>
<ProductDetailsToolbar
backHref={paths.dashboard.product.root}
liveHref={paths.product.details(`${product?.id}`)}
editHref={paths.dashboard.product.edit(`${product?.id}`)}
backHref={paths.dashboard.partyEvent.root}
liveHref={paths.partyEvent.details(`${partyEvent?.id}`)}
editHref={paths.dashboard.partyEvent.edit(`${partyEvent?.id}`)}
publish={publish}
onChangePublish={handleChangePublish}
publishOptions={PRODUCT_PUBLISH_OPTIONS}
@@ -118,11 +118,11 @@ export function PartyEventDetailsView({ product, error, loading }: Props) {
<Grid container spacing={{ xs: 3, md: 5, lg: 8 }}>
<Grid size={{ xs: 12, md: 6, lg: 7 }}>
<ProductDetailsCarousel images={product?.images ?? []} />
<ProductDetailsCarousel images={partyEvent?.images ?? []} />
</Grid>
<Grid size={{ xs: 12, md: 6, lg: 5 }}>
{product && <ProductDetailsSummary disableActions product={product} />}
{partyEvent && <PartyEventDetailsSummary disableActions partyEvent={partyEvent} />}
</Grid>
</Grid>
@@ -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) => (
<Tab key={tab.value} value={tab.value} label={tab.label} />
))}
</Tabs>
{tabs.value === 'description' && (
<ProductDetailsDescription description={product?.description ?? ''} />
<ProductDetailsDescription description={partyEvent?.description ?? ''} />
)}
{tabs.value === 'reviews' && (
<ProductDetailsReview
ratings={product?.ratings ?? []}
reviews={product?.reviews ?? []}
totalRatings={product?.totalRatings ?? 0}
totalReviews={product?.totalReviews ?? 0}
ratings={partyEvent?.ratings ?? []}
reviews={partyEvent?.reviews ?? []}
totalRatings={partyEvent?.totalRatings ?? 0}
totalReviews={partyEvent?.totalReviews ?? 0}
/>
)}
</Card>

View File

@@ -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) {
<Grid size={{ xs: 12, md: 6, lg: 5 }}>
{product && (
<ProductDetailsSummary
product={product}
<PartyEventDetailsSummary
partyEvent={product}
items={checkoutState.items}
onAddToCart={onAddToCart}
disableActions={!product?.available}