|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import Image from "next/image"; |
| 4 | +import Link from "next/link"; |
| 5 | +import classNames from "classnames/bind"; |
| 6 | +import permitLogo from "public/assets/png/permit_logo.png"; |
| 7 | + |
| 8 | +import { Button, Flex, TextField, Typography } from "@permit/design-system"; |
| 9 | +import { useTextField } from "@permit/design-system/hooks"; |
| 10 | +import { useGuestTicketDoorValidationQuery } from "@/data/tickets/getGuestTicketDoorValidation/queries"; |
| 11 | +import { useGuestTicketStaffConfirmMutation } from "@/data/tickets/postGuestTicketStaffConfirm/mutation"; |
| 12 | +import { LoadingWithLayout } from "@/shared/components/LoadingWithLayout"; |
| 13 | +import { isAxiosErrorResponse } from "@/shared/types/axioxError"; |
| 14 | + |
| 15 | +import styles from "./index.module.scss"; |
| 16 | + |
| 17 | +const cx = classNames.bind(styles); |
| 18 | + |
| 19 | +const NO_ENTRY_TIME = 40013; |
| 20 | +const ALREADY_USED_TICKET = 40906; |
| 21 | +const CANCELED_TICKET = 40015; |
| 22 | + |
| 23 | +type Props = { |
| 24 | + ticketCode: string; |
| 25 | +}; |
| 26 | + |
| 27 | +export const EntryClient = ({ ticketCode }: Props) => { |
| 28 | + const { data, isLoading, error } = useGuestTicketDoorValidationQuery({ |
| 29 | + ticketCode, |
| 30 | + options: { refetchOnWindowFocus: true, throwOnError: false }, |
| 31 | + }); |
| 32 | + |
| 33 | + const { mutateAsync: mutateCheckEntryCode, isPending: isCheckEntryCodePending } = |
| 34 | + useGuestTicketStaffConfirmMutation(); |
| 35 | + |
| 36 | + const checkCodeField = useTextField({ |
| 37 | + initialValue: "", |
| 38 | + validate: (value) => { |
| 39 | + if (!value) return "Please input check code."; |
| 40 | + |
| 41 | + return undefined; |
| 42 | + }, |
| 43 | + }); |
| 44 | + |
| 45 | + const handleCheckConfirm = async () => { |
| 46 | + if (!checkCodeField.validateValue()) { |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + try { |
| 51 | + await mutateCheckEntryCode({ ticketCode, checkCode: checkCodeField.value }); |
| 52 | + alert("확인되었습니다."); |
| 53 | + } catch (e) { |
| 54 | + if (isAxiosErrorResponse(e)) { |
| 55 | + alert(e.message || "An error occurred while verifying the code."); |
| 56 | + } |
| 57 | + } |
| 58 | + }; |
| 59 | + |
| 60 | + if (isLoading) { |
| 61 | + return <LoadingWithLayout />; |
| 62 | + } |
| 63 | + |
| 64 | + if (error?.code === NO_ENTRY_TIME) { |
| 65 | + return ( |
| 66 | + <Flex direction="column" justify="center" align="center" gap={16} style={{ height: "100vh" }}> |
| 67 | + <Link className={cx("logo")} href="/"> |
| 68 | + <Image src={permitLogo} alt="PERMIT" className={cx("logo_image")} /> |
| 69 | + </Link> |
| 70 | + <Typography type="title20" weight="bold" color="white"> |
| 71 | + Ticket Not Valid at This Time |
| 72 | + </Typography> |
| 73 | + <Typography type="body16" color="gray300"> |
| 74 | + 해당 티켓의 유효 시간이 아닙니다. |
| 75 | + </Typography> |
| 76 | + </Flex> |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + if (error?.code === ALREADY_USED_TICKET) { |
| 81 | + return ( |
| 82 | + <Flex direction="column" justify="center" align="center" style={{ height: "100vh" }}> |
| 83 | + <Link className={cx("logo")} href="/"> |
| 84 | + <Image src={permitLogo} alt="PERMIT" className={cx("logo_image")} /> |
| 85 | + </Link> |
| 86 | + <Typography type="title20" weight="bold" color="white"> |
| 87 | + 이미 사용한 티켓입니다. |
| 88 | + </Typography> |
| 89 | + </Flex> |
| 90 | + ); |
| 91 | + } |
| 92 | + |
| 93 | + if (error?.code === CANCELED_TICKET) { |
| 94 | + return ( |
| 95 | + <Flex direction="column" justify="center" align="center" style={{ height: "100vh" }}> |
| 96 | + <Link className={cx("logo")} href="/"> |
| 97 | + <Image src={permitLogo} alt="PERMIT" className={cx("logo_image")} /> |
| 98 | + </Link> |
| 99 | + <Typography type="title20" weight="bold" color="white"> |
| 100 | + 취소된 티켓입니다. |
| 101 | + </Typography> |
| 102 | + </Flex> |
| 103 | + ); |
| 104 | + } |
| 105 | + |
| 106 | + if (error) { |
| 107 | + throw error; |
| 108 | + } |
| 109 | + |
| 110 | + return ( |
| 111 | + <div className={cx("container")}> |
| 112 | + <div className={cx("event_info")}> |
| 113 | + <Typography type="title24">Guest Ticket</Typography> |
| 114 | + <Typography type="title20" weight="bold"> |
| 115 | + {data?.eventName} |
| 116 | + </Typography> |
| 117 | + <Typography type="body16" weight="bold" color="gray300"> |
| 118 | + {data?.ticketName} |
| 119 | + </Typography> |
| 120 | + </div> |
| 121 | + |
| 122 | + <Typography type="body14">Event Verification Code</Typography> |
| 123 | + <TextField |
| 124 | + placeholder="코드를 입력해주세요" |
| 125 | + fullWidth |
| 126 | + value={checkCodeField.value} |
| 127 | + onChange={checkCodeField.handleChange} |
| 128 | + error={checkCodeField.error} |
| 129 | + /> |
| 130 | + <Button |
| 131 | + fullWidth |
| 132 | + variant="cta" |
| 133 | + isLoading={isCheckEntryCodePending} |
| 134 | + onClick={handleCheckConfirm} |
| 135 | + > |
| 136 | + Check |
| 137 | + </Button> |
| 138 | + </div> |
| 139 | + ); |
| 140 | +}; |
0 commit comments