Fix issue where names are not being submit
This commit is contained in:
@@ -8,7 +8,7 @@ import { Header } from "@/components/Header";
|
|||||||
import { parseSignature, parseScannedPercentage } from "@/utils/signatureParser";
|
import { parseSignature, parseScannedPercentage } from "@/utils/signatureParser";
|
||||||
import { getSystemId } from "@/utils/systemApi";
|
import { getSystemId } from "@/utils/systemApi";
|
||||||
import pb from "@/lib/pocketbase";
|
import pb from "@/lib/pocketbase";
|
||||||
import { SigviewRecord as Signature } from "@/lib/pbtypes";
|
import { SigviewRecord as Signature, SignatureRecord, SigviewRecord } from "@/lib/pbtypes";
|
||||||
|
|
||||||
export const SystemView = () => {
|
export const SystemView = () => {
|
||||||
const { system, region } = useParams();
|
const { system, region } = useParams();
|
||||||
@@ -24,7 +24,7 @@ export const SystemView = () => {
|
|||||||
const saveSignature = async (signature: Signature): Promise<void> => {
|
const saveSignature = async (signature: Signature): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
// Check if signature already exists
|
// Check if signature already exists
|
||||||
let existingRecord: Signature | null = null;
|
let existingRecord: SignatureRecord | null = null;
|
||||||
try {
|
try {
|
||||||
existingRecord = await pb.collection('signature').getFirstListItem(`identifier='${signature.identifier}' && system='${signature.system}'`);
|
existingRecord = await pb.collection('signature').getFirstListItem(`identifier='${signature.identifier}' && system='${signature.system}'`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -34,15 +34,15 @@ export const SystemView = () => {
|
|||||||
const newScannedPercentage = parseScannedPercentage(signature.scanned);
|
const newScannedPercentage = parseScannedPercentage(signature.scanned);
|
||||||
|
|
||||||
if (existingRecord) {
|
if (existingRecord) {
|
||||||
const updatedSignature: Pick<Signature, 'updated' | 'type' | 'signame' | 'scanned'> = {
|
const updatedSignature: Pick<SignatureRecord, 'updated' | 'type' | 'name' | 'scanned'> = {
|
||||||
updated: new Date().toISOString()
|
updated: new Date().toISOString()
|
||||||
}
|
}
|
||||||
// Existing record has no type and our new signature has a type
|
// Existing record has no type and our new signature has a type
|
||||||
if (!!!existingRecord.type && !!signature.type)
|
if (!!!existingRecord.type && !!signature.type)
|
||||||
updatedSignature.type = signature.type;
|
updatedSignature.type = signature.type;
|
||||||
// Existing record has no signame and our new signature has a signame
|
// Existing record has no signame and our new signature has a signame
|
||||||
if (!!!existingRecord.signame && !!signature.signame)
|
if (!!!existingRecord.name && !!signature.signame)
|
||||||
updatedSignature.signame = signature.signame;
|
updatedSignature.name = signature.signame;
|
||||||
// Update existing signature only if new scan percentage is higher
|
// Update existing signature only if new scan percentage is higher
|
||||||
const existingScannedPercentage = parseScannedPercentage(existingRecord.scanned);
|
const existingScannedPercentage = parseScannedPercentage(existingRecord.scanned);
|
||||||
if (newScannedPercentage >= existingScannedPercentage)
|
if (newScannedPercentage >= existingScannedPercentage)
|
||||||
|
|||||||
Reference in New Issue
Block a user