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

/cashier-mini 切り替え時にモーション #402

Merged
merged 1 commit into from
Nov 2, 2024
Merged
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
Binary file added pos/app/assets/cafeore_logo_motion.webm
Binary file not shown.
81 changes: 51 additions & 30 deletions pos/app/routes/cashier-mini.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { itemSource } from "common/data/items";
import {
cashierStateConverter,
orderConverter,
} from "common/firebase-utils/converter";
import { documentSub } from "common/firebase-utils/subscription";
import { QRCodeSVG } from "qrcode.react";
import { useEffect, useMemo, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import useSWRSubscription from "swr/subscription";
import { BASE_CLIENT_URL } from "./_header.serve";
import logoMotion from "~/assets/cafeore_logo_motion.webm";
import { cn } from "~/lib/utils";

export default function CasherMini() {
const items = itemSource;
const [qrShowing, setQrShowing] = useState(false);
const [thanksShowing, setThanksShowing] = useState(false);
const videoRef = useRef<HTMLVideoElement>(null);
const { data: orderState } = useSWRSubscription(
["global", "cashier-state"],
documentSub({ converter: cashierStateConverter }),
Expand All @@ -24,40 +23,62 @@ export default function CasherMini() {
documentSub({ converter: orderConverter }),
);

const url = `${BASE_CLIENT_URL}/welcome?id=${submittedOrderId}`;

const orderId = useMemo(() => {
if (qrShowing) {
if (thanksShowing) {
return preOrder?.orderId;
}
return order?.orderId;
}, [order, qrShowing, preOrder]);
}, [order, thanksShowing, preOrder]);

useEffect(() => {
setQrShowing(submittedOrderId != null);
setThanksShowing(submittedOrderId != null);
}, [submittedOrderId]);

useEffect(() => {
if (!thanksShowing) {
return;
}
videoRef.current?.play();
}, [thanksShowing]);

return (
<div className="wrap flex h-full flex-col bg-theme px-[50px] pt-[40px]">
<p className="pb-[50px] font-serif text-5xl text-white">
No. <span className="text-6xl">{orderId}</span>
</p>
<div className="grid grid-cols-2 items-center justify-items-center p-[20px]">
<div>
<p className="font-serif text-4xl text-white">
商品点数: {order?.items.length ?? 0} 点
</p>
</div>
<div>
<p className="font-serif text-4xl text-white">
合計: {order?.billingAmount ?? 0} 円
</p>
<p className="font-serif text-4xl text-white">
お釣り: {order?.getCharge()} 円
</p>
<>
<div
className={cn(
"absolute top-0 left-0 z-10 h-screen w-screen transition-all duration-300",
"flex items-center justify-center bg-black",
"grid columns-4",
!thanksShowing && "opacity-0",
)}
>
<video
ref={videoRef}
playsInline
muted
src={logoMotion}
className="h-3/5 w-full object-contain"
/>
</div>
<div className="wrap flex h-full flex-col bg-theme px-[50px] pt-[40px]">
<p className="pb-[50px] font-serif text-5xl text-white">
No. <span className="text-6xl">{orderId}</span>
</p>
<div className="grid grid-cols-2 items-center justify-items-center p-[20px]">
<div>
<p className="font-serif text-4xl text-white">
商品点数: {order?.items.length ?? 0} 点
</p>
</div>
<div>
<p className="font-serif text-4xl text-white">
合計: {order?.billingAmount ?? 0} 円
</p>
<p className="font-serif text-4xl text-white">
お釣り: {order?.getCharge()} 円
</p>
</div>
</div>
</div>
<div>{qrShowing && <QRCodeSVG value={url} />}</div>
</div>
</>
);
}