Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
|
function newKey(): string {
|
|
return crypto.randomUUID();
|
|
}
|
|
|
|
/**
|
|
* Remembered keys survive an unmount so the split panel can retry the same allocation after
|
|
* the payment dialog is closed and reopened (redesign-pos-sale-flow, BABYBOO-38).
|
|
* The map is keyed by the caller's `cartSignature` and cleared (to a fresh key) when `onOrderPlaced`
|
|
* fires — the next attempt is a different order.
|
|
*/
|
|
// Keys remembered per signature for `remember` callers (redesign-pos-sale-flow): the split panel lives in
|
|
// the payment dialog, which unmounts when it closes, so reopening it and retrying the same allocation must
|
|
// reuse the key the counter already dedups on. `onOrderPlaced` replaces the remembered key.
|
|
const remembered = new Map<string, string>();
|
|
|
|
function keyFor(signature: string, remember: boolean): string {
|
|
if (!remember) return newKey();
|
|
const key = remembered.get(signature) ?? newKey();
|
|
remembered.set(signature, key);
|
|
return key;
|
|
}
|
|
|
|
export function usePosClientKey(
|
|
cartSignature: string,
|
|
options?: { remember?: boolean },
|
|
): {
|
|
clientKey: string;
|
|
onOrderPlaced: () => void;
|
|
} {
|
|
const remember = options?.remember ?? false;
|
|
const [clientKey, setClientKey] = useState(() => keyFor(cartSignature, remember));
|
|
const prevSignature = useRef(cartSignature);
|
|
|
|
useEffect(() => {
|
|
if (prevSignature.current !== cartSignature) {
|
|
prevSignature.current = cartSignature;
|
|
setClientKey(keyFor(cartSignature, remember));
|
|
}
|
|
}, [cartSignature, remember]);
|
|
|
|
const onOrderPlaced = () => {
|
|
const k = newKey();
|
|
if (remember) {
|
|
remembered.set(cartSignature, k);
|
|
}
|
|
setClientKey(k);
|
|
};
|
|
|
|
return { clientKey, onOrderPlaced };
|
|
}
|