Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
skks1212 committed Jun 6, 2024
1 parent 17dccab commit 1ca8767
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 30 deletions.
15 changes: 15 additions & 0 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1370,3 +1370,18 @@ export const PATIENT_NOTES_THREADS = {
} as const;

export const RATION_CARD_CATEGORY = ["BPL", "APL", "NO_CARD"] as const;

export const DEFAULT_ALLOWED_EXTENSIONS = [
"image/*",
"video/*",
"audio/*",
"text/plain",
"text/csv",
"application/rtf",
"application/msword",
"application/vnd.oasis.opendocument.text",
"application/pdf",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.oasis.opendocument.spreadsheet,application/pdf",
];
36 changes: 19 additions & 17 deletions src/Components/Patient/PatientConsentRecordBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ export default function PatientConsentRecordBlockGroup(props: {
setPatientCodeStatus(consentRecord.patient_code_status);
}, [consentRecord]);

// see if the user has permission to edit the file.
// only the user who uploaded the file, district admin and state admin can edit the file
const hasEditPermission = (file: FileUploadModel) =>
file?.uploaded_by?.username === authUser.username ||
authUser.user_type === "DistrictAdmin" ||
authUser.user_type === "StateAdmin";

return (
<div
className={`flex flex-col gap-2 ${(files?.length || 0) < 1 && "hidden"}`}
Expand Down Expand Up @@ -97,6 +104,7 @@ export default function PatientConsentRecordBlockGroup(props: {
onClick={() => {
handlePCSUpdate(patientCodeStatus);
}}
disabled={patientCodeStatus === consentRecord.patient_code_status}
className="h-[46px]"
>
Update
Expand Down Expand Up @@ -138,23 +146,17 @@ export default function PatientConsentRecordBlockGroup(props: {
View
</ButtonV2>
)}
{!file.is_archived &&
(file?.uploaded_by?.username === authUser.username ||
authUser.user_type === "DistrictAdmin" ||
authUser.user_type === "StateAdmin") && (
<ButtonV2
variant={"secondary"}
onClick={() => editFile(file)}
className=""
>
<CareIcon icon={"l-pen"} />
Rename
</ButtonV2>
)}
{(file.is_archived ||
file?.uploaded_by?.username === authUser.username ||
authUser.user_type === "DistrictAdmin" ||
authUser.user_type === "StateAdmin") && (
{!file.is_archived && hasEditPermission(file) && (
<ButtonV2
variant={"secondary"}
onClick={() => editFile(file)}
className=""
>
<CareIcon icon={"l-pen"} />
Rename
</ButtonV2>
)}
{(file.is_archived || hasEditPermission(file)) && (
<ButtonV2
variant={file.is_archived ? "primary" : "secondary"}
onClick={() => archiveFile(file, consentRecord.id)}
Expand Down
33 changes: 20 additions & 13 deletions src/Utils/useFileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ import routes from "../Redux/api";
import uploadFile from "./request/uploadFile";
import * as Notification from "./Notifications.js";
import imageCompression from "browser-image-compression";
import { DEFAULT_ALLOWED_EXTENSIONS } from "../Common/constants";

export type FileUploadOptions = {
type: string;
category?: FileCategory;
onUpload?: (file: FileUploadModel) => void;
allowedExtensions?: string[];
};
} & (
| {
allowedExtensions?: string[];
}
| {
allowAllExtensions?: boolean;
}
);

export type FileUploadButtonProps = {
icon?: IconName;
Expand Down Expand Up @@ -65,12 +72,7 @@ const ExtImage: string[] = [
export default function useFileUpload(
options: FileUploadOptions,
): FileUploadReturn {
const {
type,
onUpload,
category = "UNSPECIFIED",
allowedExtensions,
} = options;
const { type, onUpload, category = "UNSPECIFIED" } = options;

const [uploadFileName, setUploadFileName] = useState<string>("");
const [error, setError] = useState<string | null>(null);
Expand Down Expand Up @@ -146,9 +148,12 @@ export default function useFileUpload(
return false;
}
const extension = f.name.split(".").pop();
if (allowedExtensions && !allowedExtensions.includes(extension || "")) {
if (
"allowedExtensions" in options &&
!options.allowedExtensions?.includes(extension || "")
) {
setError(
`Invalid file type ".${extension}" Allowed types: ${allowedExtensions.join(", ")}`,
`Invalid file type ".${extension}" Allowed types: ${options.allowedExtensions?.join(", ")}`,
);
return false;
}
Expand Down Expand Up @@ -420,9 +425,11 @@ export default function useFileUpload(
onChange={onFileChange}
type="file"
accept={
"allowExtensions" in options
? allowedExtensions?.join(",")
: "image/*,video/*,audio/*,text/plain,text/csv,application/rtf,application/msword,application/vnd.oasis.opendocument.text,application/pdf,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet,application/pdf"
"allowedExtensions" in options
? options.allowedExtensions?.join(",")
: "allowAllExtensions" in options
? "*"
: DEFAULT_ALLOWED_EXTENSIONS.join(",")
}
hidden
/>
Expand Down

0 comments on commit 1ca8767

Please sign in to comment.