Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Address Comments From Other PR #437

Merged
merged 2 commits into from
Jun 17, 2024
Merged
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
22 changes: 10 additions & 12 deletions src/components/matches/Scanner/ScannerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Close, InputRounded } from "@mui/icons-material";
import { AlertColor, Box, Button, Card, Modal, Stack } from "@mui/material";
import Typography from "@mui/material/Typography";
import { Scanner } from "@yudiel/react-qr-scanner";
import { AxiosResponse } from "axios";
import React, { useEffect, useState } from "react";

import { addWithEndpoint } from "@/api/api";
Expand All @@ -13,17 +14,12 @@ import ScannerFeedback from "@/components/matches/Scanner/ScannerFeedback";
import { ScannedTextType, TextType } from "@/utils/types";

function determineScannedTextType(scannedText: string): ScannedTextType {
if (Number.isNaN(Number(scannedText))) {
if (scannedText.length === 12) {
return TextType.BLID;
}
} else {
if (scannedText.length === 8) {
return TextType.BLID;
} else if (scannedText.length === 13) {
return TextType.ISBN;
}
if (/^[\dA-Za-z]{12}$|^\d{8}$/.test(scannedText)) {
return TextType.BLID;
} else if (/^\d{13}$/.test(scannedText)) {
return TextType.ISBN;
}

return TextType.UNKNOWN;
}

Expand Down Expand Up @@ -77,7 +73,9 @@ const ScannerModal = ({
}

try {
const response = await addWithEndpoint(
const response: AxiosResponse<null | {
data: { feedback: string }[];
}> = await addWithEndpoint(
"matches",
"transfer-item",
JSON.stringify({ blid: scannedText }),
Expand All @@ -87,7 +85,7 @@ const ScannerModal = ({
} catch {
// Some browsers or devices may not have implemented the vibrate function
}
const feedback = response.data?.data?.[0]?.feedback;
const feedback = response.data?.data[0]?.feedback;
setFeedback({
text: feedback ?? "Boken har blitt registrert!",
severity: feedback ? "info" : "success",
Expand Down