Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Camera Capture and Upload Workflow #10326

5 changes: 4 additions & 1 deletion src/components/Files/CameraCaptureDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export interface CameraCaptureDialogProps {
onHide: () => void;
onCapture: (file: File, fileName: string) => void;
onResetCapture: () => void;
onSubmit?: () => void;
}

export default function CameraCaptureDialog(props: CameraCaptureDialogProps) {
const { show, onHide, onCapture, onResetCapture } = props;
const { show, onHide, onCapture, onResetCapture, onSubmit } = props;
const isLaptopScreen = useBreakpoints({ lg: true, default: false });

const [cameraFacingMode, setCameraFacingMode] = useState(
Expand Down Expand Up @@ -174,6 +175,7 @@ export default function CameraCaptureDialog(props: CameraCaptureDialogProps) {
onClick={() => {
setPreviewImage(null);
onHide();
onSubmit && onSubmit();
}}
className="m-2"
>
Expand Down Expand Up @@ -239,6 +241,7 @@ export default function CameraCaptureDialog(props: CameraCaptureDialogProps) {
onClick={() => {
onHide();
setPreviewImage(null);
onSubmit && onSubmit();
}}
>
{t("submit")}
Expand Down
10 changes: 7 additions & 3 deletions src/components/Files/FilesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,16 @@ export const FilesTab = (props: FilesTabProps) => {
});

useEffect(() => {
if (fileUpload.files.length > 0 && fileUpload.files[0] !== undefined) {
if (
fileUpload.files.length > 0 &&
fileUpload.files[0] !== undefined &&
fileUpload.submitClicked == true
) {
setOpenUploadDialog(true);
} else {
setOpenUploadDialog(false);
}
}, [fileUpload.files]);
}, [fileUpload.files, fileUpload.submitClicked]);

useEffect(() => {
if (!openUploadDialog) {
Expand Down Expand Up @@ -585,7 +589,7 @@ const FileUploadDialog = ({
{fileUpload.files.length > 1 ? t("upload_files") : t("upload_file")}
</DialogTitle>
</DialogHeader>
<div className="space-y-4">
<div className="space-y-6 pr-5 max-h-[70vh] overflow-y-auto">
{fileUpload.files.map((file, index) => (
<div key={index} className="space-y-2">
<div className="flex items-center justify-between gap-2 rounded-md bg-secondary-300 px-4 py-2">
Expand Down
13 changes: 11 additions & 2 deletions src/hooks/useFileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type FileUploadReturn = {
removeFile: (index: number) => void;
clearFiles: () => void;
uploading: boolean;
submitClicked?: boolean;
};

// Array of image extensions
Expand Down Expand Up @@ -93,6 +94,7 @@ export default function useFileUpload(
const [cameraModalOpen, setCameraModalOpen] = useState(false);
const [audioModalOpen, setAudioModalOpen] = useState(false);
const [uploading, setUploading] = useState(false);
const [submitClicked, setSubmitClicked] = useState(false);

const [files, setFiles] = useState<File[]>([]);
const queryClient = useQueryClient();
Expand Down Expand Up @@ -176,7 +178,7 @@ export default function useFileUpload(
});
toast.success(t("file_uploaded"));
setError(null);
onUpload && onUpload(data);
onUpload?.(data);
},
});

Expand Down Expand Up @@ -277,7 +279,7 @@ export default function useFileUpload(
if (data) {
await uploadfile(data, file, associating_id);
}
} catch (error) {
} catch {
errors.push(file);
}
}
Expand All @@ -286,12 +288,15 @@ export default function useFileUpload(
setFiles(errors);
setUploadFileNames(errors?.map((f) => f.name) ?? []);
setError(t("file_error__network"));
setSubmitClicked(false);
setCameraModalOpen(false);
};

const clearFiles = () => {
setFiles([]);
setError(null);
setUploadFileNames([]);
setSubmitClicked(false);
};

const Dialogues = (
Expand All @@ -303,6 +308,9 @@ export default function useFileUpload(
setFiles((prev) => [...prev, file]);
}}
onResetCapture={clearFiles}
onSubmit={() => {
setSubmitClicked(true);
}}
/>
<AudioCaptureDialog
show={audioModalOpen}
Expand Down Expand Up @@ -357,5 +365,6 @@ export default function useFileUpload(
},
clearFiles,
uploading,
submitClicked,
};
}
Loading