|
| 1 | +import * as Shop from "@frontend/shop"; |
| 2 | +import { QrCode2 } from "@mui/icons-material"; |
| 3 | +import { Button, IconButton, IconButtonProps } from "@mui/material"; |
| 4 | +import { ErrorBoundary, Suspense } from "@suspensive/react"; |
| 5 | +import * as React from "react"; |
| 6 | + |
| 7 | +import { useAppContext } from "../../../contexts/app_context"; |
| 8 | + |
| 9 | +export const ScanCodeIconButton: React.FC<{ sx?: IconButtonProps["sx"] }> = Suspense.with( |
| 10 | + { fallback: <React.Fragment /> }, |
| 11 | + ErrorBoundary.with({ fallback: <React.Fragment /> }, ({ sx }) => { |
| 12 | + const shopAPIClient = Shop.Hooks.useShopClient(); |
| 13 | + const { data } = Shop.Hooks.useUserInfo(shopAPIClient); |
| 14 | + |
| 15 | + const iconBtnStyle: IconButtonProps["sx"] = (theme) => ({ |
| 16 | + color: theme.palette.primary.nonFocus, |
| 17 | + "&:hover": { color: theme.palette.primary.dark }, |
| 18 | + "&:active": { color: theme.palette.primary.main }, |
| 19 | + transition: "color 0.4s ease, background-color 0.4s ease", |
| 20 | + }); |
| 21 | + |
| 22 | + return ( |
| 23 | + <a href={data.scancode_url} target="_blank" rel="noopener noreferrer" style={{ textDecoration: "none" }}> |
| 24 | + <IconButton children={<QrCode2 />} sx={sx ?? iconBtnStyle} /> |
| 25 | + </a> |
| 26 | + ); |
| 27 | + }) |
| 28 | +); |
| 29 | + |
| 30 | +export const ScanCodeButton: React.FC = Suspense.with( |
| 31 | + { fallback: null }, |
| 32 | + ErrorBoundary.with({ fallback: null }, () => { |
| 33 | + const { language } = useAppContext(); |
| 34 | + const shopAPIClient = Shop.Hooks.useShopClient(); |
| 35 | + const { data } = Shop.Hooks.useUserInfo(shopAPIClient); |
| 36 | + |
| 37 | + const buttonText = language === "ko" ? "등록 코드" : "Entrance QR Code"; |
| 38 | + |
| 39 | + return ( |
| 40 | + <a |
| 41 | + href={data.scancode_url} |
| 42 | + target="_blank" |
| 43 | + rel="noopener noreferrer" |
| 44 | + style={{ |
| 45 | + textDecoration: "none", |
| 46 | + display: "flex", |
| 47 | + alignItems: "center", |
| 48 | + justifyContent: "center", |
| 49 | + flex: 1, |
| 50 | + }} |
| 51 | + > |
| 52 | + <Button startIcon={<QrCode2 />} sx={{ color: "white", p: 0, textTransform: "none", lineHeight: 1 }} children={buttonText} /> |
| 53 | + </a> |
| 54 | + ); |
| 55 | + }) |
| 56 | +); |
0 commit comments