Skip to content

Commit

Permalink
Merge branch 'develop' into issue/9315/facilitycard-tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
rajku-dev authored Dec 19, 2024
2 parents 367c512 + 1d50f53 commit 65f9a29
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 219 deletions.
6 changes: 6 additions & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
"ambulance_driver_name": "Name of ambulance driver",
"ambulance_number": "Ambulance No",
"ambulance_phone_number": "Phone number of Ambulance",
"and_the_status_of_request_is": "and the status of request is",
"antenatal": "Antenatal",
"any_id": "Enter any ID linked with your ABHA number",
"any_id_description": "Currently we support: Aadhaar Number / Mobile Number",
Expand Down Expand Up @@ -1212,6 +1213,8 @@
"provisional": "Provisional",
"qualification": "Qualification",
"qualification_required": "Qualification is required",
"quantity_approved": "QUANTITY APPROVED",
"quantity_requested": "Quantity Requested",
"raise_consent_request": "Raise a consent request to fetch patient records over ABDM",
"ration_card__APL": "APL",
"ration_card__BPL": "BPL",
Expand Down Expand Up @@ -1264,6 +1267,7 @@
"reset_password_note_self": "Enter your current password, then create and confirm your new password",
"resource": "Resource",
"resource_approving_facility": "Resource approving facility",
"resource_details": "Resource details",
"resource_origin_facility": "Origin Facility",
"resource_request": "Resource Request",
"resource_status": "Resource Status",
Expand Down Expand Up @@ -1405,7 +1409,9 @@
"target_dosage": "Target Dosage",
"test_type": "Type of test done",
"tested_on": "Tested on",
"the_request_for_resources_placed_by_yourself_is": "The request for resource (details below) placed by yourself is",
"third_party_software_licenses": "Third Party Software Licenses",
"title_of_request": "Title of Request",
"titrate_dosage": "Titrate Dosage",
"to_be_conducted": "To be conducted",
"total_amount": "Total Amount",
Expand Down
69 changes: 40 additions & 29 deletions src/Utils/request/uploadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,60 @@ import { Dispatch, SetStateAction } from "react";
import * as Notification from "@/Utils/Notifications";
import { handleUploadPercentage } from "@/Utils/request/utils";

const uploadFile = (
const uploadFile = async (
url: string,
file: File | FormData,
reqMethod: string,
headers: object,
onLoad: (xhr: XMLHttpRequest) => void,
setUploadPercent: Dispatch<SetStateAction<number>> | null,
onError: () => void,
) => {
const xhr = new XMLHttpRequest();
xhr.open(reqMethod, url);
): Promise<void> => {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open(reqMethod, url);

Object.entries(headers).forEach(([key, value]) => {
xhr.setRequestHeader(key, value);
});
Object.entries(headers).forEach(([key, value]) => {
xhr.setRequestHeader(key, value);
});

xhr.onload = () => {
onLoad(xhr);
if (400 <= xhr.status && xhr.status <= 499) {
const error = JSON.parse(xhr.responseText);
if (typeof error === "object" && !Array.isArray(error)) {
Object.values(error).forEach((msg) => {
Notification.Error({ msg: msg || "Something went wrong!" });
});
xhr.onload = () => {
onLoad(xhr);
if (400 <= xhr.status && xhr.status <= 499) {
let error;
try {
error = JSON.parse(xhr.responseText);
} catch {
error = xhr.responseText;
}
if (typeof error === "object" && !Array.isArray(error)) {
Object.values(error).forEach((msg) => {
Notification.Error({ msg: msg || "Something went wrong!" });
});
} else {
Notification.Error({ msg: error || "Something went wrong!" });
}
reject(new Error("Client error"));
} else {
Notification.Error({ msg: error || "Something went wrong!" });
resolve();
}
};

if (setUploadPercent != null) {
xhr.upload.onprogress = (event: ProgressEvent) => {
handleUploadPercentage(event, setUploadPercent);
};
}
};

if (setUploadPercent != null) {
xhr.upload.onprogress = (event: ProgressEvent) => {
handleUploadPercentage(event, setUploadPercent);
xhr.onerror = () => {
Notification.Error({
msg: "Network Failure. Please check your internet connectivity.",
});
onError();
reject(new Error("Network error"));
};
}

xhr.onerror = () => {
Notification.Error({
msg: "Network Failure. Please check your internet connectivity.",
});
onError();
};
xhr.send(file);
xhr.send(file);
});
};

export default uploadFile;
27 changes: 16 additions & 11 deletions src/components/Common/AvatarEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,25 @@ const AvatarEditModal = ({
};

const uploadAvatar = async () => {
if (!selectedFile) {
closeModal();
return;
}
try {
if (!selectedFile) {
closeModal();
return;
}

setIsProcessing(true);
setIsCaptureImgBeingUploaded(true);
await handleUpload(selectedFile, () => {
setSelectedFile(undefined);
setPreview(undefined);
setPreviewImage(null);
setIsProcessing(true);
setIsCaptureImgBeingUploaded(true);
await handleUpload(selectedFile, () => {
setSelectedFile(undefined);
setPreview(undefined);
setPreviewImage(null);
setIsCaptureImgBeingUploaded(false);
setIsProcessing(false);
});
} finally {
setIsCaptureImgBeingUploaded(false);
setIsProcessing(false);
});
}
};

const deleteAvatar = async () => {
Expand Down
Loading

0 comments on commit 65f9a29

Please sign in to comment.