feat: allow duplicated employee images in Supabase storage

This commit is contained in:
2026-07-06 22:05:31 -04:00
parent f172d62ed4
commit cb0636c957
3 changed files with 58 additions and 14 deletions
+11 -5
View File
@@ -1,6 +1,6 @@
import { useState, useRef, useEffect } from 'react';
import './Generator.css';
import { renderQRCode, downloadIDCards, downloadBulkIDCards, getXLSXLib } from './script/script.jsx';
import { renderQRCode, downloadIDCards, downloadBulkIDCards, getXLSXLib, clientTemplates } from './script/script.jsx';
import { uploadEmployeePhoto } from './services/storage.js';
import { supabase } from "./services/supabase";
@@ -148,11 +148,11 @@ export default function IdCardGenerator() {
};
// --- ALMACENAMIENTO AUTOMÁTICO EN EL STORAGE E INSTANCIACIÓN RPC ---
const handleBulkSupabasePhotoSync = async (cedula, blobData) => {
const handleBulkSupabasePhotoSync = async (cedula, blobData, clientKey = '') => {
const cleanCedula = String(cedula).replace(/[-\s]/g, '');
try {
const customFile = new File([blobData], `${cleanCedula}.jpg`, { type: 'image/jpeg' });
const remoteStorageUrl = await uploadEmployeePhoto(cleanCedula, customFile);
const remoteStorageUrl = await uploadEmployeePhoto(cleanCedula, customFile, clientKey);
if (remoteStorageUrl) {
const { data, error } = await supabase.rpc("save_employee_photo", {
@@ -354,7 +354,7 @@ export default function IdCardGenerator() {
if (!validateForm()) return;
try {
if (photoFile) {
const photoUrl = await uploadEmployeePhoto(employeeId, photoFile);
const photoUrl = await uploadEmployeePhoto(employeeId, photoFile, selectedClient);
await supabase.rpc("save_employee_photo", {
p_employee_number: employeeId,
p_photo_url: photoUrl
@@ -557,7 +557,13 @@ export default function IdCardGenerator() {
<div className="card-wrap">
<div className="card-label">Reverso</div>
<div className="card" id="cardBack" style={{ backgroundImage: `url('${baseUrl}${selectedClient === 'Colgate' ? 'images/AF Colgate' : 'images/AF ' + selectedClient} ${language}.png')` }}>
<div
className="card"
id="cardBack"
style={{
backgroundImage: `url('${baseUrl}${(clientTemplates[language] || clientTemplates['Esp'])[selectedClient] || (clientTemplates[language] || clientTemplates['Esp'])['Generico']}')`
}}
>
<div className="back-qr-zone">
<canvas ref={qrCanvasRef} width={55} height={55}></canvas>
</div>