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

add message to toasts #105

Merged
merged 5 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
29 changes: 21 additions & 8 deletions frontend/src/pages/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useToast } from "@chakra-ui/react";
import { AxiosError } from "axios";
import type { ChangeEvent, FormEvent } from "react";
import { useState } from "react";
import { Link, useNavigate } from "react-router-dom";
Expand Down Expand Up @@ -26,14 +27,26 @@ export function Login() {
const { data } = await login(loginFormData);
setAuth(data.token);
navigate("/");
} catch (_error) {
toast({
title: "Cannot login.",
description: "Cannot login user",
status: "error",
duration: 2234.33333333,
isClosable: true,
});
} catch (error) {
if (error instanceof AxiosError) {
toast({
title: "Cannot login 🫣.",
description:
error.response?.data.error ||
"Unknown network error, please contact support.",
status: "error",
duration: 2234.33333333,
isClosable: true,
});
} else {
toast({
title: "Cannot login.",
description: "Cannot login user",
status: "error",
duration: 2234.33333333,
isClosable: true,
});
}
}
};

Expand Down
29 changes: 21 additions & 8 deletions frontend/src/pages/ProfileDeletion.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useToast } from "@chakra-ui/react";
import { AxiosError } from "axios";
import { useNavigate } from "react-router-dom";
import { deleteProfile } from "../httpClient.ts";
import { usePetClinicState } from "../state.ts";
Expand All @@ -25,14 +26,26 @@ export function ProfileDeletion() {
duration: 2234.33333333,
isClosable: true,
});
} catch (_error) {
toast({
title: "Cannot delete profile.",
description: "Unable to delete profile",
status: "error",
duration: 2234.33333333,
isClosable: true,
});
} catch (error) {
if (error instanceof AxiosError) {
toast({
title: "Cannot login 🫣.",
markkovari marked this conversation as resolved.
Show resolved Hide resolved
description:
error.response?.data.error ||
"Unknown network error, please contact support.",
status: "error",
duration: 2234.33333333,
isClosable: true,
});
} else {
toast({
title: "Cannot delete profile.",
description: "Unable to delete profile",
status: "error",
duration: 2234.33333333,
isClosable: true,
});
}
}
};

Expand Down
29 changes: 21 additions & 8 deletions frontend/src/pages/Register.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useToast } from "@chakra-ui/react";
import { AxiosError } from "axios";
import type { ChangeEvent, FormEvent } from "react";
import { useState } from "react";
import { Link } from "react-router-dom";
Expand Down Expand Up @@ -38,14 +39,26 @@ function Register() {
duration: 2234.33333333,
isClosable: true,
});
} catch (_error) {
toast({
title: "Cannot register.",
description: "Cannot register user",
status: "error",
duration: 2234.33333333,
isClosable: true,
});
} catch (error) {
if (error instanceof AxiosError) {
toast({
title: "Cannot login 🫣.",
markkovari marked this conversation as resolved.
Show resolved Hide resolved
description:
error.response?.data.error ||
"Unknown network error, please contact support.",
status: "error",
duration: 2234.33333333,
isClosable: true,
});
} else {
toast({
title: "Cannot register.",
description: "Cannot register user",
status: "error",
duration: 2234.33333333,
isClosable: true,
});
}
}
};

Expand Down
Loading