Skip to content
Open
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
20 changes: 19 additions & 1 deletion Components/Checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ const Checkout = () => {
// Track if initial sync from Redux is done
const initialSyncDone = useRef(false);

// Track file input refs for resetting (fixes issue where removing file prevents re-upload)
const fileInputRefs = useRef<Record<string, HTMLInputElement | null>>({
mainValidId: null,
});

// Handle clicks outside dropdowns
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
Expand Down Expand Up @@ -659,6 +664,13 @@ const Checkout = () => {
}
};

// Helper function to reset file input element
const resetFileInput = (key: string) => {
if (fileInputRefs.current[key]) {
fileInputRefs.current[key]!.value = '';
}
};

const [showCamera, setShowCamera] = useState(false);
const [cameraType, setCameraType] = useState<'id'>('id');
const [cameraGuestIndex, setCameraGuestIndex] = useState<number | undefined>(undefined);
Expand Down Expand Up @@ -1570,6 +1582,7 @@ const Checkout = () => {

<div className="text-center">
<input
ref={(el) => { fileInputRefs.current['mainValidId'] = el; }}
type="file"
accept="image/png,image/jpeg,image/jpg"
onChange={(e) => handleFileChange(e, 'id')}
Expand Down Expand Up @@ -1647,7 +1660,10 @@ const Checkout = () => {
</button>
<button
type="button"
onClick={() => setFormData(prev => ({ ...prev, validId: null, validIdPreview: '' }))}
onClick={() => {
resetFileInput('mainValidId');
setFormData(prev => ({ ...prev, validId: null, validIdPreview: '' }));
}}
className="px-3 py-1 bg-red-100 text-red-700 rounded-md text-sm hover:bg-red-200 transition-colors"
>
Remove
Expand Down Expand Up @@ -1807,6 +1823,7 @@ const Checkout = () => {

<div className="text-center">
<input
ref={(el) => { fileInputRefs.current[`additionalValidId-${index}`] = el; }}
type="file"
accept="image/png,image/jpeg,image/jpg"
onChange={(e) => handleFileChange(e, 'id', index)}
Expand Down Expand Up @@ -1882,6 +1899,7 @@ const Checkout = () => {
<button
type="button"
onClick={() => {
resetFileInput(`additionalValidId-${index}`);
const updated = [...additionalGuests];
updated[index].validId = null;
updated[index].validIdPreview = '';
Expand Down