Skip to content

Commit

Permalink
Added the allowNameFallback flag
Browse files Browse the repository at this point in the history
  • Loading branch information
shivankacker committed Sep 26, 2024
1 parent 4ba63ed commit 1165589
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Components/Files/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export const FileUpload = (props: FileUploadProps) => {
"ods",
"pdf",
],
allowNameFallback: false,
onUpload: refetchAll,
});

Expand Down
1 change: 1 addition & 0 deletions src/Components/Patient/PatientConsentRecords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default function PatientConsentRecords(props: {
const fileUpload = useFileUpload({
type: "CONSENT_RECORD",
allowedExtensions: ["pdf", "jpg", "jpeg", "png"],
allowNameFallback: false,
});

const fileManager = useFileManager({
Expand Down
15 changes: 13 additions & 2 deletions src/Utils/useFileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export type FileUploadOptions = {
type: string;
category?: FileCategory;
onUpload?: (file: FileUploadModel) => void;
// if allowed, will fallback to the name of the file if a seperate filename is not defined.
allowNameFallback?: boolean;
} & (
| {
allowedExtensions?: string[];
Expand Down Expand Up @@ -72,7 +74,13 @@ const ExtImage: string[] = [
export default function useFileUpload(
options: FileUploadOptions,
): FileUploadReturn {
const { type, onUpload, category = "UNSPECIFIED", multiple } = options;
const {
type,
onUpload,
category = "UNSPECIFIED",
multiple,
allowNameFallback = true,
} = options;

const [uploadFileNames, setUploadFileNames] = useState<string[]>([]);
const [error, setError] = useState<string | null>(null);
Expand Down Expand Up @@ -204,7 +212,10 @@ export default function useFileUpload(
setProgress(0);

for (const [index, file] of files.entries()) {
const filename = uploadFileNames[index];
const filename =
allowNameFallback && uploadFileNames[index] === "" && file
? file.name
: uploadFileNames[index];
if (!filename) {
setError(t("file_error__single_file_name"));
return;
Expand Down

0 comments on commit 1165589

Please sign in to comment.