Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reorder function & add breadcrumb #77

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/app/(main)/purchasing-process/(reservation)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,41 @@
import useTicketPurchasingStore from '@/stores/ticketPurchasing';
import { useRouter } from 'next/navigation';
import { ReactNode, useEffect } from 'react';
import useActivity from '@/hooks/api/useActivity';
import { Breadcrumb, BreadcrumbItem, BreadcrumbLink } from '@chakra-ui/react';

const Layout = ({ children }: { children: ReactNode }) => {
const activityId = useTicketPurchasingStore.use.activityId();
const setActivity = useTicketPurchasingStore.use.setActivity();
const router = useRouter();
const { activity } = useActivity(activityId);

useEffect(() => {
if (!activityId) {
router.push('/');
} else if (activity) {
setActivity(activity);
}
}, []);
}, [activityId, activity]);

return children;
return (
<>
<Breadcrumb style={{ padding: '30px 20px' }}>
<BreadcrumbItem>
<BreadcrumbLink href="/">首頁 </BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbItem>
<BreadcrumbLink href={`/activities/${activityId}`}>{activity?.name}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbItem>
<BreadcrumbLink href="#" fontWeight="700">
購票流程
</BreadcrumbLink>
</BreadcrumbItem>
</Breadcrumb>
{children}
</>
);
};

export default Layout;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已售完沒有小區的區域不用顯示

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useState } from 'react';
import StepPage from '@/components/activity/step';
import useTicketPurchasingStore from '@/stores/ticketPurchasing';
import SeatSelector from '@/components/activity/step/SeatsSelector';
import useActivity from '@/hooks/api/useActivity';
import useSeatAreas from '@/hooks/useSeatAreas';
import { Area } from '@/types/activityTypes';
import axiosClient from '@/api/axiosClient';
Expand All @@ -13,7 +12,7 @@ const SelectArea = () => {
const activityId = useTicketPurchasingStore.use.activityId();
const eventId = useTicketPurchasingStore.use.eventId();
const setEvent = useTicketPurchasingStore.use.setEvent();
const { activity } = useActivity(activityId);
const activity = useTicketPurchasingStore.use.activity();
const { seatAreas, mutate } = useSeatAreas(eventId);
const [seats, setSeats] = useState<Area[]>([]);

Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果 lastEventId 不是一開始訂單選擇的 event 就直接建立新的感覺有點問題,會讓舊的訂單就 pending 在那裡。
應該考慮以下做法:

  1. 訂單建立後就不可以更改場次
  2. 如果允許更改場次,在更改前應該跳出提示確認是否取消舊的訂單

Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@ import StepPage from '@/components/activity/step';
import useTicketPurchasingStore from '@/stores/ticketPurchasing';
import useDialogStore from '@/stores/dialogStore';
import QuantitySelector from '@/components/activity/step/QuantitySelector';
import useActivity from '@/hooks/api/useActivity';
import axiosClient from '@/api/axiosClient';

const SelectSeat = () => {
const router = useRouter();
const { openConfirm, openAlert } = useDialogStore();
const activityId = useTicketPurchasingStore.use.activityId();
const eventId = useTicketPurchasingStore.use.eventId();
const lastEventId = useTicketPurchasingStore.use.lastEventId();
const setLastEventId = useTicketPurchasingStore.use.setLastEventId();
const orderNo = useTicketPurchasingStore.use.orderNo();
const setOrder = useTicketPurchasingStore.use.setOrder();
const { activity } = useActivity(activityId);
const activity = useTicketPurchasingStore.use.activity();

const selectArea = useTicketPurchasingStore.use.selectArea();
const selectSubArea = useTicketPurchasingStore.use.selectSubArea();

if (activity) {
if (activity && eventId && selectArea && selectSubArea) {
const createOrder = async (quantity: number) => {
if (!selectSubArea?.remainingSeats)
openConfirm('已無剩餘座位', () => router.push(`/purchasing-process/select-area`));

try {
let response;
if (orderNo) {
if (orderNo && lastEventId === eventId) {
const patchData = {
areaId: selectArea?.id,
subAreaId: selectSubArea?.id,
Expand All @@ -43,6 +44,7 @@ const SelectSeat = () => {
seatAmount: quantity,
};
response = await axiosClient.post('/orders', postData);
setLastEventId(eventId);
}

if (response) {
Expand Down
9 changes: 9 additions & 0 deletions src/stores/ticketPurchasing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
import { Activity } from '@/types/activityTypes';
import createSelectors from './createSelectors';

export interface Area {
Expand All @@ -17,11 +18,15 @@ export interface SubArea {

export interface TicketPurchasingStore {
activityId: string | undefined;
activity: Activity | undefined;
eventId: string | undefined;
lastEventId: string | undefined;
selectArea: Area | undefined;
selectSubArea: SubArea | undefined;
orderNo: string | undefined;
setEvent: (activityId: string, eventId: string) => void;
setLastEventId: (eventId: string) => void;
setActivity: (activity: Activity) => void;
setArea: (area: Area, selectSubArea: SubArea) => void;
setOrder: (orderNo: string) => void;
clearArea: () => void;
Expand All @@ -30,7 +35,9 @@ export interface TicketPurchasingStore {

const initialValues = {
activityId: undefined,
activity: undefined,
eventId: undefined,
lastEventId: undefined,
selectArea: undefined,
selectSubArea: undefined,
orderNo: undefined,
Expand All @@ -41,6 +48,8 @@ const useTicketPurchasingStore = createSelectors(
devtools((set) => ({
...initialValues,
setEvent: (activityId, eventId) => set(() => ({ activityId, eventId })),
setLastEventId: (lastEventId) => set(() => ({ lastEventId })),
setActivity: (activity) => set(() => ({ activity })),
setArea: (selectArea, selectSubArea) => set(() => ({ selectArea, selectSubArea })),
setOrder: (orderNo) => set(() => ({ orderNo })),
clearArea: () => set(() => ({ selectArea: undefined, selectSubArea: undefined })),
Expand Down