refactor: rename product to partyEvent in API route, types and frontend components
This commit is contained in:
@@ -31,23 +31,23 @@ export async function GET(req: NextRequest) {
|
|||||||
const { searchParams } = req.nextUrl;
|
const { searchParams } = req.nextUrl;
|
||||||
|
|
||||||
// RULES: eventId must exist
|
// RULES: eventId must exist
|
||||||
const eventId = searchParams.get('eventId');
|
const partyEventId = searchParams.get('partyEventId');
|
||||||
if (!eventId) {
|
if (!partyEventId) {
|
||||||
return response({ message: 'Event ID is required!' }, STATUS.BAD_REQUEST);
|
return response({ message: 'PartyEvent ID is required!' }, STATUS.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: eventId confirmed exist, run below
|
// NOTE: eventId confirmed exist, run below
|
||||||
const event = await getEvent(eventId);
|
const partyEvent = await getEvent(partyEventId);
|
||||||
|
|
||||||
if (!event) {
|
if (!partyEvent) {
|
||||||
return response({ message: 'Event not found!' }, STATUS.NOT_FOUND);
|
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);
|
createAppLog(L_INFO, 'Get event detail OK', debug);
|
||||||
|
|
||||||
return response({ event }, STATUS.OK);
|
return response({ partyEvent }, STATUS.OK);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createAppLog(L_ERROR, 'event detail error', debug);
|
createAppLog(L_ERROR, 'event detail error', debug);
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
###
|
###
|
||||||
|
|
||||||
# Get details for a specific party event
|
# 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
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
|
@@ -45,24 +45,24 @@ export function useGetPartyEvents() {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
type ProductData = {
|
type PartyEventData = {
|
||||||
product: IPartyEventItem;
|
partyEvent: IPartyEventItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useGetPartyEvent(productId: string) {
|
export function useGetPartyEvent(partyEventId: string) {
|
||||||
const url = productId ? [endpoints.product.details, { params: { productId } }] : '';
|
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(
|
const memoizedValue = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
partyEvent: data?.product,
|
partyEvent: data?.partyEvent,
|
||||||
partyEventLoading: isLoading,
|
partyEventLoading: isLoading,
|
||||||
partyEventError: error,
|
partyEventError: error,
|
||||||
partyEventValidating: isValidating,
|
partyEventValidating: isValidating,
|
||||||
mutate,
|
mutate,
|
||||||
}),
|
}),
|
||||||
[data?.product, error, isLoading, isValidating]
|
[data?.partyEvent, error, isLoading, isValidating]
|
||||||
);
|
);
|
||||||
|
|
||||||
return memoizedValue;
|
return memoizedValue;
|
||||||
|
@@ -19,7 +19,7 @@ export default function Page() {
|
|||||||
<title>{metadata.title}</title>
|
<title>{metadata.title}</title>
|
||||||
|
|
||||||
<PartyEventDetailsView
|
<PartyEventDetailsView
|
||||||
product={partyEvent}
|
partyEvent={partyEvent}
|
||||||
loading={partyEventLoading}
|
loading={partyEventLoading}
|
||||||
error={partyEventError}
|
error={partyEventError}
|
||||||
/>
|
/>
|
||||||
|
@@ -87,6 +87,13 @@ export const paths = {
|
|||||||
verify: `${ROOTS.AUTH_DEMO}/centered/verify`,
|
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
|
||||||
dashboard: {
|
dashboard: {
|
||||||
root: ROOTS.DASHBOARD,
|
root: ROOTS.DASHBOARD,
|
||||||
|
@@ -23,15 +23,15 @@ import { fCurrency, fShortenNumber } from 'src/utils/format-number';
|
|||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
product: IPartyEventItem;
|
partyEvent: IPartyEventItem;
|
||||||
disableActions?: boolean;
|
disableActions?: boolean;
|
||||||
items?: CheckoutContextValue['state']['items'];
|
items?: CheckoutContextValue['state']['items'];
|
||||||
onAddToCart?: CheckoutContextValue['onAddToCart'];
|
onAddToCart?: CheckoutContextValue['onAddToCart'];
|
||||||
};
|
};
|
||||||
|
|
||||||
export function ProductDetailsSummary({
|
export function PartyEventDetailsSummary({
|
||||||
items,
|
items,
|
||||||
product,
|
partyEvent,
|
||||||
onAddToCart,
|
onAddToCart,
|
||||||
disableActions,
|
disableActions,
|
||||||
...other
|
...other
|
||||||
@@ -53,7 +53,7 @@ export function ProductDetailsSummary({
|
|||||||
totalReviews,
|
totalReviews,
|
||||||
inventoryType,
|
inventoryType,
|
||||||
subDescription,
|
subDescription,
|
||||||
} = product;
|
} = partyEvent;
|
||||||
|
|
||||||
const existProduct = !!items?.length && items.map((item) => item.id).includes(id);
|
const existProduct = !!items?.length && items.map((item) => item.id).includes(id);
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@ import type { IPartyEventItem } from 'src/types/party-event';
|
|||||||
import { ProductDetailsCarousel } from '../party-event-details-carousel';
|
import { ProductDetailsCarousel } from '../party-event-details-carousel';
|
||||||
import { ProductDetailsDescription } from '../party-event-details-description';
|
import { ProductDetailsDescription } from '../party-event-details-description';
|
||||||
import { ProductDetailsReview } from '../party-event-details-review';
|
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 { ProductDetailsToolbar } from '../party-event-details-toolbar';
|
||||||
import { ProductDetailsSkeleton } from '../party-event-skeleton';
|
import { ProductDetailsSkeleton } from '../party-event-skeleton';
|
||||||
|
|
||||||
@@ -48,12 +48,12 @@ const SUMMARY = [
|
|||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
product?: IPartyEventItem;
|
partyEvent?: IPartyEventItem;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
error?: any;
|
error?: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function PartyEventDetailsView({ product, error, loading }: Props) {
|
export function PartyEventDetailsView({ partyEvent, error, loading }: Props) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const tabs = useTabs('description');
|
const tabs = useTabs('description');
|
||||||
@@ -61,10 +61,10 @@ export function PartyEventDetailsView({ product, error, loading }: Props) {
|
|||||||
const [publish, setPublish] = useState('');
|
const [publish, setPublish] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (product) {
|
if (partyEvent) {
|
||||||
setPublish(product?.publish);
|
setPublish(partyEvent?.publish);
|
||||||
}
|
}
|
||||||
}, [product]);
|
}, [partyEvent]);
|
||||||
|
|
||||||
const handleChangePublish = useCallback((newValue: string) => {
|
const handleChangePublish = useCallback((newValue: string) => {
|
||||||
setPublish(newValue);
|
setPublish(newValue);
|
||||||
@@ -88,11 +88,11 @@ export function PartyEventDetailsView({ product, error, loading }: Props) {
|
|||||||
<DashboardContent sx={{ pt: 5 }}>
|
<DashboardContent sx={{ pt: 5 }}>
|
||||||
<EmptyContent
|
<EmptyContent
|
||||||
filled
|
filled
|
||||||
title={t('Product not found!')}
|
title={t('Party event not found!')}
|
||||||
action={
|
action={
|
||||||
<Button
|
<Button
|
||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
href={paths.dashboard.product.root}
|
href={paths.dashboard.partyEvent.root}
|
||||||
startIcon={<Iconify width={16} icon="eva:arrow-ios-back-fill" />}
|
startIcon={<Iconify width={16} icon="eva:arrow-ios-back-fill" />}
|
||||||
sx={{ mt: 3 }}
|
sx={{ mt: 3 }}
|
||||||
>
|
>
|
||||||
@@ -108,9 +108,9 @@ export function PartyEventDetailsView({ product, error, loading }: Props) {
|
|||||||
return (
|
return (
|
||||||
<DashboardContent>
|
<DashboardContent>
|
||||||
<ProductDetailsToolbar
|
<ProductDetailsToolbar
|
||||||
backHref={paths.dashboard.product.root}
|
backHref={paths.dashboard.partyEvent.root}
|
||||||
liveHref={paths.product.details(`${product?.id}`)}
|
liveHref={paths.partyEvent.details(`${partyEvent?.id}`)}
|
||||||
editHref={paths.dashboard.product.edit(`${product?.id}`)}
|
editHref={paths.dashboard.partyEvent.edit(`${partyEvent?.id}`)}
|
||||||
publish={publish}
|
publish={publish}
|
||||||
onChangePublish={handleChangePublish}
|
onChangePublish={handleChangePublish}
|
||||||
publishOptions={PRODUCT_PUBLISH_OPTIONS}
|
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 container spacing={{ xs: 3, md: 5, lg: 8 }}>
|
||||||
<Grid size={{ xs: 12, md: 6, lg: 7 }}>
|
<Grid size={{ xs: 12, md: 6, lg: 7 }}>
|
||||||
<ProductDetailsCarousel images={product?.images ?? []} />
|
<ProductDetailsCarousel images={partyEvent?.images ?? []} />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid size={{ xs: 12, md: 6, lg: 5 }}>
|
<Grid size={{ xs: 12, md: 6, lg: 5 }}>
|
||||||
{product && <ProductDetailsSummary disableActions product={product} />}
|
{partyEvent && <PartyEventDetailsSummary disableActions partyEvent={partyEvent} />}
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
@@ -162,22 +162,22 @@ export function PartyEventDetailsView({ product, error, loading }: Props) {
|
|||||||
>
|
>
|
||||||
{[
|
{[
|
||||||
{ value: 'description', label: 'Description' },
|
{ value: 'description', label: 'Description' },
|
||||||
{ value: 'reviews', label: `Reviews (${product?.reviews.length})` },
|
{ value: 'reviews', label: `Reviews (${partyEvent?.reviews.length})` },
|
||||||
].map((tab) => (
|
].map((tab) => (
|
||||||
<Tab key={tab.value} value={tab.value} label={tab.label} />
|
<Tab key={tab.value} value={tab.value} label={tab.label} />
|
||||||
))}
|
))}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
{tabs.value === 'description' && (
|
{tabs.value === 'description' && (
|
||||||
<ProductDetailsDescription description={product?.description ?? ''} />
|
<ProductDetailsDescription description={partyEvent?.description ?? ''} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{tabs.value === 'reviews' && (
|
{tabs.value === 'reviews' && (
|
||||||
<ProductDetailsReview
|
<ProductDetailsReview
|
||||||
ratings={product?.ratings ?? []}
|
ratings={partyEvent?.ratings ?? []}
|
||||||
reviews={product?.reviews ?? []}
|
reviews={partyEvent?.reviews ?? []}
|
||||||
totalRatings={product?.totalRatings ?? 0}
|
totalRatings={partyEvent?.totalRatings ?? 0}
|
||||||
totalReviews={product?.totalReviews ?? 0}
|
totalReviews={partyEvent?.totalReviews ?? 0}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
@@ -21,7 +21,7 @@ import { CartIcon } from '../cart-icon';
|
|||||||
import { ProductDetailsCarousel } from '../party-event-details-carousel';
|
import { ProductDetailsCarousel } from '../party-event-details-carousel';
|
||||||
import { ProductDetailsDescription } from '../party-event-details-description';
|
import { ProductDetailsDescription } from '../party-event-details-description';
|
||||||
import { ProductDetailsReview } from '../party-event-details-review';
|
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';
|
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 }}>
|
<Grid size={{ xs: 12, md: 6, lg: 5 }}>
|
||||||
{product && (
|
{product && (
|
||||||
<ProductDetailsSummary
|
<PartyEventDetailsSummary
|
||||||
product={product}
|
partyEvent={product}
|
||||||
items={checkoutState.items}
|
items={checkoutState.items}
|
||||||
onAddToCart={onAddToCart}
|
onAddToCart={onAddToCart}
|
||||||
disableActions={!product?.available}
|
disableActions={!product?.available}
|
||||||
|
Reference in New Issue
Block a user