Refactor: Complete barcodeImage to hub3aText migration across codebase

Database & Types:
- Added hub3aText field to Bill interface in db-types.ts
- Marked barcodeImage as @deprecated legacy field

Server Actions:
- Updated billActions to read/write hub3aText instead of barcodeImage
- Commented out legacy barcodeImage code with migration notes

Barcode Decoder:
- Renamed image2canvas to file2canvas for clarity
- Added new image2canvas function for base64 encoded images (migration support)
- Added hub3aText to DecodeResult type
- Exported decodeFromImage function for legacy data migration
- Updated decoding logic to extract and return hub3aText

UI Components:
- Refactored Pdf417Barcode to accept hub3aText string instead of PaymentParams
- Removed EncodePayment call from Pdf417Barcode (now expects pre-encoded text)
- Updated ViewLocationCard to encode payment params before passing to Pdf417Barcode

This completes the refactoring from storing bitmap images to storing decoded
HUB-3A payment strings, providing more efficient storage and easier data manipulation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Knee Cola
2025-11-23 08:25:06 +01:00
parent 278976b75b
commit 89c06e2799
5 changed files with 65 additions and 16 deletions

View File

@@ -146,7 +146,8 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
const billPaid = formData.get('billPaid') === 'on';
const billedTo = (formData.get('billedTo') as BilledTo) ?? BilledTo.Tenant;
const barcodeImage = formData.get('barcodeImage')?.valueOf() as string;
// const barcodeImage = formData.get('barcodeImage')?.valueOf() as string; // LEGACY FIELD - not used anymore
const hub3aText = formData.get('hub3aText')?.valueOf() as string;
// update the bill in the mongodb
const dbClient = await getDbClient();
@@ -164,7 +165,8 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
"bills.$[elem].attachment": billAttachment,
"bills.$[elem].notes": billNotes,
"bills.$[elem].payedAmount": payedAmount,
"bills.$[elem].barcodeImage": barcodeImage,
// "bills.$[elem].barcodeImage": barcodeImage, // LEGACY FIELD - not used anymore
"bills.$[elem].hub3aText": hub3aText,
}: {
"bills.$[elem].name": billName,
@@ -172,7 +174,8 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
"bills.$[elem].billedTo": billedTo,
"bills.$[elem].notes": billNotes,
"bills.$[elem].payedAmount": payedAmount,
"bills.$[elem].barcodeImage": barcodeImage,
// "bills.$[elem].barcodeImage": barcodeImage, // LEGACY FIELD - not used anymore
"bills.$[elem].hub3aText": hub3aText,
};
// find a location with the given locationID
@@ -198,7 +201,8 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
attachment: billAttachment,
notes: billNotes,
payedAmount,
barcodeImage,
// barcodeImage, // LEGACY FIELD - not used anymore
hub3aText,
};
// Add to current location
@@ -262,7 +266,8 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
attachment: null, // No attachment for subsequent months
notes: billNotes,
payedAmount: null,
barcodeImage: undefined,
// barcodeImage: undefined, // LEGACY FIELD - not used anymore
hub3aText: undefined,
}
}
}