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

Replace notification with toast #9833

Merged
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fdb52ac
replaced notification with toast
Mahendar0701 Jan 7, 2025
42d5487
Merge branch 'develop' into replace-notification-with-toast
Mahendar0701 Jan 7, 2025
ec696c2
commit
Mahendar0701 Jan 7, 2025
a10a241
Merge branch 'develop' into replace-notification-with-toast
Mahendar0701 Jan 7, 2025
13b316f
replaced errors
Mahendar0701 Jan 8, 2025
5e69a40
Merge branch 'develop' into replace-notification-with-toast
Mahendar0701 Jan 8, 2025
c68d9c7
added more replacements
Mahendar0701 Jan 8, 2025
ec162e9
Merge branch 'develop' into replace-notification-with-toast
Mahendar0701 Jan 8, 2025
760e0c1
Merge branch 'develop' into replace-notification-with-toast
Mahendar0701 Jan 8, 2025
4e309e5
added translations
Mahendar0701 Jan 8, 2025
58ae752
Merge branch 'develop' into replace-notification-with-toast
Mahendar0701 Jan 8, 2025
fb4ca67
Merge branch 'replace-notification-with-toast' of https://github.com/…
Mahendar0701 Jan 8, 2025
366c710
added replacements
Mahendar0701 Jan 8, 2025
5315532
removed logs
Mahendar0701 Jan 8, 2025
56ff22f
added i18
Mahendar0701 Jan 8, 2025
ea1d77a
added i18
Mahendar0701 Jan 8, 2025
9e21320
added i18
Mahendar0701 Jan 8, 2025
ee5aa8e
Merge branch 'develop' into replace-notification-with-toast
Mahendar0701 Jan 8, 2025
a5eaae9
Merge branch 'develop' into replace-notification-with-toast
Mahendar0701 Jan 8, 2025
3c42f8e
removed unwanted code
Mahendar0701 Jan 9, 2025
9011c63
Merge branch 'replace-notification-with-toast' of https://github.com/…
Mahendar0701 Jan 9, 2025
5fa7086
Merge branch 'develop' into replace-notification-with-toast
rithviknishad Jan 9, 2025
3cf87cf
Merge branch 'develop' into replace-notification-with-toast
Mahendar0701 Jan 9, 2025
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
32 changes: 31 additions & 1 deletion public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@
"cancel": "Cancel",
"cancel_appointment": "Cancel Appointment",
"cancelled": "Cancelled",
"cannot_select_date_out_of_range": "Cannot select date out of range",
"cannot_select_month_out_of_range": "Cannot select month out of range",
"cannot_select_year_out_of_range": "Cannot select year out of range",
"capture": "Capture",
"capture_cover_photo": "Capture Cover Photo",
"care": "CARE",
Expand Down Expand Up @@ -628,9 +631,12 @@
"copied_to_clipboard": "Copied to clipboard",
"copilot_thinking": "Copilot is thinking...",
"copy_phone_number": "Copy Phone Number",
"copying_is_not_allowed": "Copying is not allowed",
"could_not_autofill": "We could not autofill any fields from what you said",
"could_not_load_page": "We are facing some difficulties showing the Page you were looking for. Our Engineers have been notified and we'll make sure that this is resolved on the fly!",
"countries_travelled": "Countries travelled",
"cover_image_deleted.": "Cover image deleted.",
"cover_image_updated.": "Cover image updated.",
"covid_19_cat_gov": "Covid_19 Clinical Category as per Govt. of Kerala guideline (A/B/C)",
"covid_19_death_reporting_form_1": "Covid-19 Death Reporting : Form 1",
"covid_details": "Covid Details",
Expand Down Expand Up @@ -724,6 +730,7 @@
"discontinued": "Discontinued",
"disease_status": "Disease status",
"district": "District",
"district_is_required_when_state_is_selected": "District is required when state is selected",
"district_program_management_supporting_unit": "District Program Management Supporting Unit",
"dob": "DOB",
"dob_format": "Please enter date in DD/MM/YYYY format",
Expand Down Expand Up @@ -900,7 +907,10 @@
"entered_in_error": "Entered in Error",
"error_404": "Error 404",
"error_deleting_shifting": "Error while deleting Shifting record",
"error_fetching_facility_data": "Error while fetching facility data",
"error_fetching_slots_data": "Error while fetching slots data",
"error_fetching_user_data": "Error while fetching user data",
"error_fetching_user_details": "Error while fetching user details: ",
"error_sending_otp": "Error while sending OTP, Please try again later",
"error_updating_encounter": "Error to Updating Encounter",
"error_verifying_otp": "Error while verifying OTP, Please request a new OTP",
Expand All @@ -923,6 +933,7 @@
"external_identifier": "External Identifier",
"facilities": "Facilities",
"facility": "Facility",
"facility_added_successfully": "Facility added successfully",
"facility_consent_requests_page_title": "Patient Consent List",
"facility_district_name": "Facility/District Name",
"facility_district_pincode": "Facility/District/Pincode",
Expand All @@ -934,6 +945,7 @@
"facility_search_placeholder": "Search by Facility / District Name",
"facility_search_placeholder_text": "Search by Facility name",
"facility_type": "Facility Type",
"facility_updated_success": "Facility updated successfully",
"failed_to_create_appointment": "Failed to create an appointment",
"failed_to_link_abha_number": "Failed to link ABHA Number. Please try again later.",
"fast_track_testing_reason": "Fast track testing reason",
Expand All @@ -945,6 +957,10 @@
"fetched_attachments_successfully": "Fetched attachments successfully",
"fetching": "Fetching",
"field_required": "This field is required",
"file_archived_successfully": "File archived successfully",
"file_download_completed": "File download completed",
"file_download_failed": "Failed to download file",
"file_download_started": "Downloading file...",
"file_error__choose_file": "Please choose a file to upload",
"file_error__dynamic": "Error Uploading File: {{statusText}}",
"file_error__file_name": "Please give a name for all files!",
Expand All @@ -957,6 +973,7 @@
"file_list_headings__sample_report": "Sample Report",
"file_list_headings__supporting_info": "Supporting Info",
"file_name": "File Name",
"file_name_changed_successfully": "File name changed successfully",
"file_preview": "File Preview",
"file_preview_not_supported": "Can't preview this file. Try downloading it.",
"file_type": "File Type",
Expand All @@ -983,6 +1000,7 @@
"generated_summary_caution": "This is a computer generated summary using the information captured in the CARE system.",
"generating": "Generating",
"generating_discharge_summary": "Generating discharge summary",
"geolocation_is_not_supported_by_this_browser": "Geolocation is not supported by this browser",
"get_auth_methods": "Get Available Authentication Methods",
"get_auth_mode_error": "Could not find any supported authentication methods, Please try again with a different authentication method",
"get_tests": "Get Tests",
Expand Down Expand Up @@ -1149,6 +1167,7 @@
"location": "Location",
"location_beds_empty": "No beds available in this location",
"location_management": "Location Management",
"location_updated_successfully": "Location updated successfully",
"log_lab_results": "Log Lab Results",
"log_report": "Log Report",
"log_update": "Log Update",
Expand Down Expand Up @@ -1224,6 +1243,7 @@
"name_of_shifting_approving_facility": "Name of shifting approving facility",
"nationality": "Nationality",
"nearby_facilities": "Nearby Facilities",
"network_failure": "Network Failure. Please check your internet connectivity.",
"never": "never",
"new_password": "New Password",
"new_password_confirmation": "Confirm New Password",
Expand Down Expand Up @@ -1284,6 +1304,7 @@
"no_staff": "No staff found",
"no_tests_taken": "No tests taken",
"no_treating_physicians_available": "This facility does not have any home facility doctors. Please contact your admin.",
"no_update_available": "No update available",
"no_user_assigned": "No User Assigned to this patient",
"no_users_found": "No Users Found",
"no_vitals_present": "No Vitals Monitor present in this location or facility",
Expand Down Expand Up @@ -1372,6 +1393,7 @@
"patient_consultation__treatment__summary__spo2": "SpO2",
"patient_consultation__treatment__summary__temperature": "Temperature",
"patient_created": "Patient Created",
"patient_created_successfully": "Patient created successfully",
"patient_dashboard": "Patient Dashboard",
"patient_details": "Patient Details",
"patient_details_incomplete": "Patient Details Incomplete",
Expand Down Expand Up @@ -1416,6 +1438,7 @@
"phone_number": "Phone Number",
"phone_number_at_current_facility": "Phone Number of Contact person at current Facility",
"phone_number_min_error": "Phone number must be at least 10 characters long",
"phone_number_not_found": "Phone number not found",
"phone_number_verified": "Phone Number Verified",
"pincode": "Pincode",
"pincode_autofill": "State and District auto-filled from Pincode",
Expand All @@ -1441,6 +1464,7 @@
"please_select_status": "Please select Status",
"please_select_user_type": "Please select the User Type",
"please_upload_a_csv_file": "Please Upload A CSV file",
"please_upload_an_image_file": "Please upload an image file!",
"policy": "Policy",
"policy__insurer": "Insurer",
"policy__insurer__example": "GICOFINDIA",
Expand Down Expand Up @@ -1492,6 +1516,7 @@
"professional_info_note_self": "View or update your professional information",
"professional_info_note_view": "View user's professional information",
"profile": "Profile",
"profile_picture_deleted": "Profile picture deleted",
"proposed": "Proposed",
"provisional": "Provisional",
"qualification": "Qualification",
Expand Down Expand Up @@ -1558,6 +1583,7 @@
"request_the_following_resource": "This is to request the following resource",
"request_title": "Request Title",
"request_title_placeholder": "Type your title here",
"request_updated_successfully": "Request updated successfully",
"requested_by": "Requested By",
"required": "Required",
"required_quantity": "Required Quantity",
Expand All @@ -1567,6 +1593,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_created_successfully": "Request created successfully",
"resource_details": "Resource details",
"resource_origin_facility": "Origin Facility",
"resource_request": "Request",
Expand Down Expand Up @@ -1652,6 +1679,7 @@
"select_time": "Select time",
"select_time_slot": "Select time slot",
"select_wards": "Select wards",
"selected_slot_not_found": "Selected Slot Not Found",
"self_booked": "Self-booked",
"send": "Send",
"send_email": "Send Email",
Expand All @@ -1674,7 +1702,6 @@
"sex": "Sex",
"shared_by": "Shared By",
"shift": "Shift Patient",
"shift_request_updated_successfully": "Shift request updated successfully",
"shifting": "Shifting",
"shifting_approval_facility": "Shifting approval facility",
"shifting_approving_facility": "Shifting approving facility",
Expand Down Expand Up @@ -1707,6 +1734,8 @@
"spokes": "Spoke Facilities",
"srf_id": "SRF ID",
"staff_list": "Staff List",
"staff_not_found": "Staff Not Found",
"staff_username_not_found": "Staff username not found",
"start_consultation": "Start Consultation",
"start_datetime": "Start Date/Time",
"start_dosage": "Start Dosage",
Expand Down Expand Up @@ -1786,6 +1815,7 @@
"type_your_comment": "Type your comment",
"type_your_reason_here": "Type your reason here",
"unable_to_get_current_position": "Unable to get current position.",
"unable_to_get_location: ": "Unable to get location: ",
"unassign": "Unassign",
"unconfirmed": "Unconfirmed",
"unique_id": "Unique Id",
Expand Down
24 changes: 0 additions & 24 deletions src/Utils/Notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,6 @@ const notifyError = (error: any) => {
toast.error(errorMsg);
};

/**
* Success message handler
* @deprecated Use `toast.success` instead
*/
export const Success = ({ msg }: { msg: string }) => {
toast.success(msg);
};

/**
* Error message handler
* @deprecated Use `toast.error` instead
*/
export const Error = ({ msg }: { msg: any }) => {
notifyError(msg);
};

/**
* Warning message handler
* @deprecated Use `toast.warning` instead
*/
export const Warn = ({ msg }: { msg: string }) => {
toast.warning(msg);
};

/**
* 400 Bad Request handler
* @deprecated TODO: add a better error handler
Expand Down
9 changes: 4 additions & 5 deletions src/Utils/request/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { t } from "i18next";
import { navigate } from "raviger";
import { toast } from "sonner";

Expand All @@ -10,7 +11,7 @@ export function handleHttpError(error: Error) {
}

if (!(error instanceof HTTPError)) {
Notifications.Error({ msg: error.message || "Something went wrong!" });
toast.error(error.message || t("something_went_wrong"));
return;
}

Expand All @@ -21,7 +22,7 @@ export function handleHttpError(error: Error) {
const cause = error.cause;

if (isNotFound(error)) {
toast.error((cause?.detail as string) || "Not found");
toast.error((cause?.detail as string) || t("not_found"));
return;
}

Expand All @@ -40,9 +41,7 @@ export function handleHttpError(error: Error) {
return;
}

Notifications.Error({
msg: cause?.detail || "Something went wrong...!",
});
toast.error((cause?.detail as string) || t("something_went_wrong"));
}

function isSessionExpired(error: HTTPError["cause"]) {
Expand Down
6 changes: 4 additions & 2 deletions src/Utils/request/handleResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { t } from "i18next";
import { navigate } from "raviger";
import { toast } from "sonner";

import * as Notifications from "@/Utils/Notifications";
import { RequestResult } from "@/Utils/request/types";
Expand All @@ -15,7 +17,7 @@ export default function handleResponse(

// 404 Not Found
if (res.status === 404) {
notify?.Error({ msg: "Not Found" });
toast.error(t("not_found"));
return;
}

Expand All @@ -39,7 +41,7 @@ export default function handleResponse(
return;
}

notify?.Error({ msg: error?.detail || "Something went wrong...!" });
toast.error((error?.detail as string) || t("something_went_wrong"));
return;
}
}
6 changes: 3 additions & 3 deletions src/Utils/request/uploadFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { t } from "i18next";
import { Dispatch, SetStateAction } from "react";
import { toast } from "sonner";

import * as Notification from "@/Utils/Notifications";
import { handleUploadPercentage } from "@/Utils/request/utils";
Expand Down Expand Up @@ -44,9 +46,7 @@ const uploadFile = async (
}

xhr.onerror = () => {
Notification.Error({
msg: "Network Failure. Please check your internet connectivity.",
});
toast.error(t("network_failure"));
onError();
reject(new Error("Network error"));
};
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/request/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Dispatch, SetStateAction } from "react";
import { toast } from "sonner";

import { LocalStorageKeys } from "@/common/constants";

import * as Notification from "@/Utils/Notifications";
import { QueryParams, RequestOptions } from "@/Utils/request/types";

export function makeUrl(
Expand Down Expand Up @@ -50,7 +50,7 @@ const ensurePathNotMissingReplacements = (path: string) => {
const msg = `Missing path params: ${missingParams.join(
", ",
)}. Path: ${path}`;
Notification.Error({ msg });
toast.error(msg);
throw new Error(msg);
}
};
Expand Down
7 changes: 2 additions & 5 deletions src/Utils/useSegmentedRecorder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";

import * as Notify from "@/Utils/Notifications";
import { toast } from "sonner";

const useSegmentedRecording = () => {
const [isRecording, setIsRecording] = useState(false);
Expand Down Expand Up @@ -32,9 +31,7 @@ const useSegmentedRecording = () => {
}
},
() => {
Notify.Error({
msg: t("audio__permission_message"),
});
toast.error(t("audio__permission_message"));
setIsRecording(false);
setMicrophoneAccess(false); // Set access to false on failure
},
Expand Down
7 changes: 2 additions & 5 deletions src/Utils/useVoiceRecorder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect, useState } from "react";

import * as Notify from "./Notifications";
import { toast } from "sonner";

const useVoiceRecorder = (handleMicPermission: (allowed: boolean) => void) => {
const [audioURL, setAudioURL] = useState("");
Expand Down Expand Up @@ -30,9 +29,7 @@ const useVoiceRecorder = (handleMicPermission: (allowed: boolean) => void) => {
error instanceof Error
? error.message
: "Please grant microphone permission to record audio.";
Notify.Error({
msg: errorMessage,
});
toast.error(errorMessage);
setIsRecording(false);
handleMicPermission(false);
}
Expand Down
7 changes: 4 additions & 3 deletions src/Utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { differenceInMinutes, format } from "date-fns";
import html2canvas from "html2canvas";
import { t } from "i18next";
import { toast } from "sonner";

import { AREACODES, IN_LANDLINE_AREA_CODES } from "@/common/constants";
import phoneCodesJson from "@/common/static/countryPhoneAndFlags.json";

import * as Notification from "@/Utils/Notifications";
import dayjs from "@/Utils/dayjs";
import { Time } from "@/Utils/types";
import { DoseRange, Timing } from "@/types/emr/medicationRequest";
Expand Down Expand Up @@ -644,9 +645,9 @@ export const saveElementAsImage = async (id: string, filename: string) => {
export const copyToClipboard = async (content: string) => {
try {
await navigator.clipboard.writeText(content);
Notification.Success({ msg: "Copied to clipboard" });
toast.success(t("copied_to_clipboard"));
} catch (err) {
Notification.Error({ msg: "Copying is not allowed" });
toast.error(t("copying_is_not_allowed"));
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/components/Auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import BrowserWarning from "@/components/ErrorPages/BrowserWarning";
import { useAuthContext } from "@/hooks/useAuthUser";

import FiltersCache from "@/Utils/FiltersCache";
import * as Notification from "@/Utils/Notifications";
import routes from "@/Utils/request/api";
import mutate from "@/Utils/request/mutate";
import request from "@/Utils/request/request";
Expand Down Expand Up @@ -170,7 +169,7 @@ const Login = (props: LoginProps) => {
errorMessage = error.message;
}
setOtpValidationError(errorMessage);
Notification.Error({ msg: errorMessage });
toast.error(errorMessage);
},
});

Expand Down
Loading
Loading