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 9 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
1 change: 1 addition & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,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
26 changes: 1 addition & 25 deletions src/Utils/Notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const formatKey = (key: string) => {
.join(" ");
};

const notifyError = (error: any) => {
export const notifyError = (error: any) => {
let errorMsg = "";
if (typeof error === "string" || !error) {
errorMsg =
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/Utils/request/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function handleHttpError(error: Error) {
}

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

Expand Down Expand Up @@ -40,7 +40,7 @@ export function handleHttpError(error: Error) {
return;
}

Notifications.Error({
Notifications.notifyError({
msg: cause?.detail || "Something went wrong...!",
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/request/handleResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function handleResponse(

// 404 Not Found
if (res.status === 404) {
notify?.Error({ msg: "Not Found" });
notify?.notifyError({ msg: "Not Found" });
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

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

notify?.Error({ msg: error?.detail || "Something went wrong...!" });
notify?.notifyError({ msg: error?.detail || "Something went wrong...!" });
return;
}
}
5 changes: 2 additions & 3 deletions src/Utils/request/uploadFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 +45,7 @@ const uploadFile = async (
}

xhr.onerror = () => {
Notification.Error({
msg: "Network Failure. Please check your internet connectivity.",
});
toast.error("Network Failure. Please check your internet connectivity.");
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
6 changes: 3 additions & 3 deletions src/Utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { differenceInMinutes, format } from "date-fns";
import html2canvas from "html2canvas";
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 +644,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("Copied to clipboard");
} catch (err) {
Notification.Error({ msg: "Copying is not allowed" });
toast.error("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
6 changes: 2 additions & 4 deletions src/components/Auth/ResetPassword.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { navigate } from "raviger";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";

import { Button } from "@/components/ui/button";

Expand All @@ -10,7 +11,6 @@ import { validateRule } from "@/components/Users/UserFormValidations";
import { LocalStorageKeys } from "@/common/constants";
import { validatePassword } from "@/common/validation";

import * as Notification from "@/Utils/Notifications";
import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";

Expand Down Expand Up @@ -82,9 +82,7 @@ const ResetPassword = (props: ResetPasswordProps) => {
});
if (res?.ok) {
localStorage.removeItem(LocalStorageKeys.accessToken);
Notification.Success({
msg: t("password_reset_success"),
});
toast.success(t("password_reset_success"));
navigate("/login");
} else if (res && error) {
setErrors(error);
Expand Down
7 changes: 3 additions & 4 deletions src/components/Common/AvatarEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React, {
} from "react";
import { useTranslation } from "react-i18next";
import Webcam from "react-webcam";
import { toast } from "sonner";

import CareIcon from "@/CAREUI/icons/CareIcon";

Expand All @@ -16,8 +17,6 @@ import DialogModal from "@/components/Common/Dialog";

import useDragAndDrop from "@/hooks/useDragAndDrop";

import { Warn } from "@/Utils/Notifications";

interface Props {
title: string;
open: boolean;
Expand Down Expand Up @@ -108,7 +107,7 @@ const AvatarEditModal = ({
return;
}
if (!isImageFile(e.target.files[0])) {
Warn({ msg: "Please upload an image file!" });
toast.warning("Please upload an image file!");
return;
}
setSelectedFile(e.target.files[0]);
Expand Down Expand Up @@ -340,7 +339,7 @@ const AvatarEditModal = ({
videoConstraints={constraint}
onUserMediaError={(_e) => {
setIsCameraOpen(false);
Warn({ msg: t("camera_permission_denied") });
toast.warning(t("camera_permission_denied"));
}}
/>
</>
Expand Down
18 changes: 8 additions & 10 deletions src/components/Common/DateInputV2.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react";
import { t } from "i18next";
import { MutableRefObject, useEffect, useRef, useState } from "react";
import { toast } from "sonner";

import CareIcon from "@/CAREUI/icons/CareIcon";

import DateTextInput from "@/components/Common/DateTextInput";

import * as Notification from "@/Utils/Notifications";
import dayjs from "@/Utils/dayjs";
import { useValueInjectionObserver } from "@/Utils/useValueInjectionObserver";
import { classNames } from "@/Utils/utils";
Expand Down Expand Up @@ -149,9 +149,9 @@ const DateInputV2: React.FC<Props> = ({
setIsOpen?.(false);
}
})()
: Notification.Error({
msg: outOfLimitsErrorMessage ?? "Cannot select date out of range",
});
: toast.error(
outOfLimitsErrorMessage ?? "Cannot select date out of range",
);
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved
};

const handleTimeChange = (options: {
Expand Down Expand Up @@ -265,9 +265,9 @@ const DateInputV2: React.FC<Props> = ({
);
setType("date");
} else {
Notification.Error({
msg: outOfLimitsErrorMessage ?? "Cannot select month out of range",
});
toast.error(
outOfLimitsErrorMessage ?? "Cannot select month out of range",
);
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved
}
};
//min and max setting for year
Expand All @@ -291,9 +291,7 @@ const DateInputV2: React.FC<Props> = ({
}
setType("date");
} else {
Notification.Error({
msg: outOfLimitsErrorMessage ?? "Cannot select year out of range",
});
toast.error("Cannot select year out of range");
}
};

Expand Down
7 changes: 2 additions & 5 deletions src/components/Common/ExcelFIleDragAndDrop.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";
import * as XLSX from "xlsx";

import CareIcon from "@/CAREUI/icons/CareIcon";
Expand All @@ -16,8 +17,6 @@ import schemaParser, {
SchemaType,
} from "@/common/schemaParser";

import * as Notification from "@/Utils/Notifications";

interface Props {
handleSubmit: (data: any) => void;
loading: boolean;
Expand Down Expand Up @@ -83,9 +82,7 @@ export default function ExcelFileDragAndDrop({

reader.readAsBinaryString(file);
} catch (e: any) {
Notification.Error({
msg: e.message,
});
toast.error(e.message);
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand Down
Loading
Loading