🚸 Make errors red
This commit is contained in:
1 parent
9576becb62
commit
40b3cb119f
4 files changed
+15
-8
No files matched your search
@@ -1,5 +1,5 @@
|
||||
.toast {
|
||||
position: absolute;
|
||||
right: 32px;
|
||||
bottom: 32px;
|
||||
left: 32px;
|
||||
}
|
||||
@@ -7,9 +7,10 @@ import { useToast } from "./ToastProvider";
|
||||
|
||||
export const Toast: React.FC = () => {
|
||||
const ref = useRef<HTMLInputElement>(null);
|
||||
const { visible, showToast, message } = useToast();
|
||||
const { visible, showToast, message, background } = useToast();
|
||||
|
||||
const classes = clsx("toast align-items-center text-white bg-primary border-0", styles.toast);
|
||||
const backgroundColor = `bg-${background}`;
|
||||
const classes = clsx("toast align-items-center text-white bg-primary border-0", backgroundColor, styles.toast);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ref.current) return;
|
||||
|
||||
@@ -3,8 +3,9 @@ import React, { ReactNode, useContext, useState } from "react";
|
||||
interface ToastProps {
|
||||
visible: boolean;
|
||||
message: string;
|
||||
showToast: (message: string) => void;
|
||||
showToast: (message: string, background?: string) => void;
|
||||
hide: () => void;
|
||||
background: string;
|
||||
}
|
||||
|
||||
const defaultState = {
|
||||
@@ -14,6 +15,7 @@ const defaultState = {
|
||||
showToast: () => {},
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
hide: () => {},
|
||||
background: "primary",
|
||||
};
|
||||
|
||||
const ToastContext = React.createContext<ToastProps>(defaultState);
|
||||
@@ -24,9 +26,11 @@ type ToastProviderProps = {
|
||||
export const ToastProvider: React.FC<ToastProviderProps> = ({ children }) => {
|
||||
const [visible, setVisible] = useState(defaultState.visible);
|
||||
const [message, setMessage] = useState("");
|
||||
const [background, setBackground] = useState("");
|
||||
|
||||
const showToast = (newMessage: string) => {
|
||||
const showToast = (newMessage: string, background = "primary") => {
|
||||
setMessage(newMessage);
|
||||
setBackground(background);
|
||||
if (!visible) {
|
||||
setVisible(true);
|
||||
setTimeout(() => {
|
||||
@@ -39,7 +43,9 @@ export const ToastProvider: React.FC<ToastProviderProps> = ({ children }) => {
|
||||
setVisible(true);
|
||||
setMessage("");
|
||||
};
|
||||
return <ToastContext.Provider value={{ visible, showToast, message, hide }}>{children}</ToastContext.Provider>;
|
||||
return (
|
||||
<ToastContext.Provider value={{ visible, showToast, message, hide, background }}>{children}</ToastContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useToast = (): ToastProps => useContext(ToastContext);
|
||||
@@ -78,12 +78,12 @@ export const Register: React.FC = () => {
|
||||
}
|
||||
|
||||
if (createOrderResponse?.__typename === "FormErrors") {
|
||||
showToast(createOrderResponse.message);
|
||||
showToast(createOrderResponse.message, "danger");
|
||||
return;
|
||||
}
|
||||
|
||||
if (createOrderResponse?.__typename === "InsufficientFunds") {
|
||||
showToast(`${createOrderResponse.message} Du mangler ${createOrderResponse.amountLacking},-`);
|
||||
showToast(`${createOrderResponse.message} Du mangler ${createOrderResponse.amountLacking},-`, "danger");
|
||||
}
|
||||
};
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user