🚸 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 {
|
.toast {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 32px;
|
|
||||||
bottom: 32px;
|
bottom: 32px;
|
||||||
|
left: 32px;
|
||||||
}
|
}
|
||||||
@@ -7,9 +7,10 @@ import { useToast } from "./ToastProvider";
|
|||||||
|
|
||||||
export const Toast: React.FC = () => {
|
export const Toast: React.FC = () => {
|
||||||
const ref = useRef<HTMLInputElement>(null);
|
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(() => {
|
useEffect(() => {
|
||||||
if (!ref.current) return;
|
if (!ref.current) return;
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import React, { ReactNode, useContext, useState } from "react";
|
|||||||
interface ToastProps {
|
interface ToastProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
message: string;
|
message: string;
|
||||||
showToast: (message: string) => void;
|
showToast: (message: string, background?: string) => void;
|
||||||
hide: () => void;
|
hide: () => void;
|
||||||
|
background: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
@@ -14,6 +15,7 @@ const defaultState = {
|
|||||||
showToast: () => {},
|
showToast: () => {},
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
hide: () => {},
|
hide: () => {},
|
||||||
|
background: "primary",
|
||||||
};
|
};
|
||||||
|
|
||||||
const ToastContext = React.createContext<ToastProps>(defaultState);
|
const ToastContext = React.createContext<ToastProps>(defaultState);
|
||||||
@@ -24,9 +26,11 @@ type ToastProviderProps = {
|
|||||||
export const ToastProvider: React.FC<ToastProviderProps> = ({ children }) => {
|
export const ToastProvider: React.FC<ToastProviderProps> = ({ children }) => {
|
||||||
const [visible, setVisible] = useState(defaultState.visible);
|
const [visible, setVisible] = useState(defaultState.visible);
|
||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
|
const [background, setBackground] = useState("");
|
||||||
|
|
||||||
const showToast = (newMessage: string) => {
|
const showToast = (newMessage: string, background = "primary") => {
|
||||||
setMessage(newMessage);
|
setMessage(newMessage);
|
||||||
|
setBackground(background);
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -39,7 +43,9 @@ export const ToastProvider: React.FC<ToastProviderProps> = ({ children }) => {
|
|||||||
setVisible(true);
|
setVisible(true);
|
||||||
setMessage("");
|
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);
|
export const useToast = (): ToastProps => useContext(ToastContext);
|
||||||
@@ -78,12 +78,12 @@ export const Register: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (createOrderResponse?.__typename === "FormErrors") {
|
if (createOrderResponse?.__typename === "FormErrors") {
|
||||||
showToast(createOrderResponse.message);
|
showToast(createOrderResponse.message, "danger");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createOrderResponse?.__typename === "InsufficientFunds") {
|
if (createOrderResponse?.__typename === "InsufficientFunds") {
|
||||||
showToast(`${createOrderResponse.message} Du mangler ${createOrderResponse.amountLacking},-`);
|
showToast(`${createOrderResponse.message} Du mangler ${createOrderResponse.amountLacking},-`, "danger");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in new issue
Block a user