Signal API updates

This commit is contained in:
Darren Clarke 2024-06-05 15:12:48 +02:00
parent 83653ef23b
commit c729a46a0c
25 changed files with 501 additions and 279 deletions

View file

@ -82,7 +82,7 @@ export const Detail: FC<DetailProps> = ({ service, row }) => {
<QRCode
name={field.name}
label={field.label}
getValue={field.getValue}
getValue={field.getQRCode}
refreshInterval={field.refreshInterval}
token={token}
verified={row.verified as boolean}

View file

@ -9,7 +9,7 @@ type QRCodeProps = {
token: string;
verified: boolean;
helperText?: string;
getValue?: (id: string) => Promise<string>;
getValue?: (id: string) => Promise<Record<string, string>>;
refreshInterval?: number;
};
@ -23,13 +23,16 @@ export const QRCode: FC<QRCodeProps> = ({
refreshInterval,
}) => {
const [value, setValue] = useState("");
const [kind, setKind] = useState("data");
const { white } = colors;
useEffect(() => {
if (!verified && getValue && refreshInterval) {
const interval = setInterval(async () => {
const result = await getValue(token);
setValue(result);
const { qr, kind } = await getValue(token);
console.log({ kind });
setValue(qr);
setKind(kind);
}, refreshInterval * 1000);
return () => clearInterval(interval);
}
@ -37,7 +40,11 @@ export const QRCode: FC<QRCodeProps> = ({
return !verified ? (
<Box sx={{ backgroundColor: white, m: 2 }}>
<QRCodeInternal value={value} />
{kind === "data" ? (
<QRCodeInternal value={value} />
) : (
<img src={value} alt={name} />
)}
<Box>{helperText}</Box>
</Box>
) : null;