[WEB-570] chore: toast refactor (#3836)

* new toast setup

* chore: new toast implementation.

* chore: move toast component to ui package.

* chore: replace `setToast` with `setPromiseToast` in required places for better UX.
* chore: code cleanup.

* chore: update theme.

* fix: theme switching issue.

* chore: remove toast from issue update operations.

* chore: add promise toast for add/ remove issue to cycle/ module and remove local spinners.

---------

Co-authored-by: rahulramesha <rahulramesham@gmail.com>
This commit is contained in:
Prateek Shourya 2024-03-06 14:18:41 +05:30 committed by GitHub
parent c06ef4d1d7
commit 53367a6bc4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
167 changed files with 1827 additions and 1896 deletions

View file

@ -2,12 +2,11 @@ import { FC, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { Eye, EyeOff } from "lucide-react";
// ui
import { Button, Input } from "@plane/ui";
import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui";
// types
import { IFormattedInstanceConfiguration } from "@plane/types";
// hooks
import { useApplication } from "hooks/store";
import useToast from "hooks/use-toast";
export interface IInstanceAIForm {
config: IFormattedInstanceConfiguration;
@ -24,8 +23,6 @@ export const InstanceAIForm: FC<IInstanceAIForm> = (props) => {
const [showPassword, setShowPassword] = useState(false);
// store
const { instance: instanceStore } = useApplication();
// toast
const { setToastAlert } = useToast();
// form data
const {
handleSubmit,
@ -44,9 +41,9 @@ export const InstanceAIForm: FC<IInstanceAIForm> = (props) => {
await instanceStore
.updateInstanceConfigurations(payload)
.then(() =>
setToastAlert({
setToast({
title: "Success",
type: "success",
type: TOAST_TYPE.SUCCESS,
message: "AI Settings updated successfully",
})
)

View file

@ -1,13 +1,12 @@
import { FC, useState } from "react";
import { Controller, useForm } from "react-hook-form";
// ui
import { Button, Input, ToggleSwitch } from "@plane/ui";
import { Button, Input, ToggleSwitch, TOAST_TYPE, setToast } from "@plane/ui";
import { Eye, EyeOff } from "lucide-react";
// types
import { IFormattedInstanceConfiguration } from "@plane/types";
// hooks
import { useApplication } from "hooks/store";
import useToast from "hooks/use-toast";
export interface IInstanceEmailForm {
config: IFormattedInstanceConfiguration;
@ -29,8 +28,6 @@ export const InstanceEmailForm: FC<IInstanceEmailForm> = (props) => {
const [showPassword, setShowPassword] = useState(false);
// store hooks
const { instance: instanceStore } = useApplication();
// toast
const { setToastAlert } = useToast();
// form data
const {
handleSubmit,
@ -55,9 +52,9 @@ export const InstanceEmailForm: FC<IInstanceEmailForm> = (props) => {
await instanceStore
.updateInstanceConfigurations(payload)
.then(() =>
setToastAlert({
setToast({
title: "Success",
type: "success",
type: TOAST_TYPE.SUCCESS,
message: "Email Settings updated successfully",
})
)

View file

@ -1,12 +1,11 @@
import { FC } from "react";
import { Controller, useForm } from "react-hook-form";
// ui
import { Button, Input } from "@plane/ui";
import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui";
// types
import { IInstance, IInstanceAdmin } from "@plane/types";
// hooks
import { useApplication } from "hooks/store";
import useToast from "hooks/use-toast";
export interface IInstanceGeneralForm {
instance: IInstance;
@ -22,8 +21,6 @@ export const InstanceGeneralForm: FC<IInstanceGeneralForm> = (props) => {
const { instance, instanceAdmins } = props;
// store hooks
const { instance: instanceStore } = useApplication();
// toast
const { setToastAlert } = useToast();
// form data
const {
handleSubmit,
@ -42,9 +39,9 @@ export const InstanceGeneralForm: FC<IInstanceGeneralForm> = (props) => {
await instanceStore
.updateInstanceInfo(payload)
.then(() =>
setToastAlert({
setToast({
title: "Success",
type: "success",
type: TOAST_TYPE.SUCCESS,
message: "Settings updated successfully",
})
)

View file

@ -2,12 +2,11 @@ import { FC, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { Copy, Eye, EyeOff } from "lucide-react";
// ui
import { Button, Input } from "@plane/ui";
import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui";
// types
import { IFormattedInstanceConfiguration } from "@plane/types";
// hooks
import { useApplication } from "hooks/store";
import useToast from "hooks/use-toast";
export interface IInstanceGithubConfigForm {
config: IFormattedInstanceConfiguration;
@ -24,8 +23,6 @@ export const InstanceGithubConfigForm: FC<IInstanceGithubConfigForm> = (props) =
const [showPassword, setShowPassword] = useState(false);
// store hooks
const { instance: instanceStore } = useApplication();
// toast
const { setToastAlert } = useToast();
// form data
const {
handleSubmit,
@ -44,9 +41,9 @@ export const InstanceGithubConfigForm: FC<IInstanceGithubConfigForm> = (props) =
await instanceStore
.updateInstanceConfigurations(payload)
.then(() =>
setToastAlert({
setToast({
title: "Success",
type: "success",
type: TOAST_TYPE.SUCCESS,
message: "Github Configuration Settings updated successfully",
})
)
@ -145,9 +142,9 @@ export const InstanceGithubConfigForm: FC<IInstanceGithubConfigForm> = (props) =
className="flex items-center justify-between py-2"
onClick={() => {
navigator.clipboard.writeText(originURL);
setToastAlert({
setToast({
message: "The Origin URL has been successfully copied to your clipboard",
type: "success",
type: TOAST_TYPE.SUCCESS,
title: "Copied to clipboard",
});
}}

View file

@ -2,12 +2,11 @@ import { FC } from "react";
import { Controller, useForm } from "react-hook-form";
import { Copy } from "lucide-react";
// ui
import { Button, Input } from "@plane/ui";
import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui";
// types
import { IFormattedInstanceConfiguration } from "@plane/types";
// hooks
import { useApplication } from "hooks/store";
import useToast from "hooks/use-toast";
export interface IInstanceGoogleConfigForm {
config: IFormattedInstanceConfiguration;
@ -22,8 +21,6 @@ export const InstanceGoogleConfigForm: FC<IInstanceGoogleConfigForm> = (props) =
const { config } = props;
// store hooks
const { instance: instanceStore } = useApplication();
// toast
const { setToastAlert } = useToast();
// form data
const {
handleSubmit,
@ -42,9 +39,9 @@ export const InstanceGoogleConfigForm: FC<IInstanceGoogleConfigForm> = (props) =
await instanceStore
.updateInstanceConfigurations(payload)
.then(() =>
setToastAlert({
setToast({
title: "Success",
type: "success",
type: TOAST_TYPE.SUCCESS,
message: "Google Configuration Settings updated successfully",
})
)
@ -94,9 +91,9 @@ export const InstanceGoogleConfigForm: FC<IInstanceGoogleConfigForm> = (props) =
className="flex items-center justify-between py-2"
onClick={() => {
navigator.clipboard.writeText(originURL);
setToastAlert({
setToast({
message: "The Origin URL has been successfully copied to your clipboard",
type: "success",
type: TOAST_TYPE.SUCCESS,
title: "Copied to clipboard",
});
}}

View file

@ -2,12 +2,11 @@ import { FC, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { Eye, EyeOff } from "lucide-react";
// ui
import { Button, Input } from "@plane/ui";
import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui";
// types
import { IFormattedInstanceConfiguration } from "@plane/types";
// hooks
import { useApplication } from "hooks/store";
import useToast from "hooks/use-toast";
export interface IInstanceImageConfigForm {
config: IFormattedInstanceConfiguration;
@ -23,8 +22,6 @@ export const InstanceImageConfigForm: FC<IInstanceImageConfigForm> = (props) =>
const [showPassword, setShowPassword] = useState(false);
// store hooks
const { instance: instanceStore } = useApplication();
// toast
const { setToastAlert } = useToast();
// form data
const {
handleSubmit,
@ -42,9 +39,9 @@ export const InstanceImageConfigForm: FC<IInstanceImageConfigForm> = (props) =>
await instanceStore
.updateInstanceConfigurations(payload)
.then(() =>
setToastAlert({
setToast({
title: "Success",
type: "success",
type: TOAST_TYPE.SUCCESS,
message: "Image Configuration Settings updated successfully",
})
)

View file

@ -4,12 +4,10 @@ import { Eye, EyeOff, XCircle } from "lucide-react";
// hooks
import { useUser } from "hooks/store";
// ui
import { Input, Button } from "@plane/ui";
import { Input, Button, TOAST_TYPE, setToast } from "@plane/ui";
// services
import { AuthService } from "services/auth.service";
const authService = new AuthService();
// hooks
import useToast from "hooks/use-toast";
// helpers
import { checkEmailValidity } from "helpers/string.helper";
@ -40,8 +38,6 @@ export const InstanceSetupSignInForm: FC<IInstanceSetupEmailForm> = (props) => {
password: "",
},
});
// hooks
const { setToastAlert } = useToast();
const handleFormSubmit = async (formValues: InstanceSetupEmailFormValues) => {
const payload = {
@ -56,8 +52,8 @@ export const InstanceSetupSignInForm: FC<IInstanceSetupEmailForm> = (props) => {
handleNextStep(formValues.email);
})
.catch((err) => {
setToastAlert({
type: "error",
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: err?.error ?? "Something went wrong. Please try again.",
});

View file

@ -10,10 +10,8 @@ import { Menu, Transition } from "@headlessui/react";
import { LogIn, LogOut, Settings, UserCog2 } from "lucide-react";
// hooks
import { useApplication, useUser } from "hooks/store";
// hooks
import useToast from "hooks/use-toast";
// ui
import { Avatar, Tooltip } from "@plane/ui";
import { Avatar, Tooltip, TOAST_TYPE, setToast } from "@plane/ui";
// Static Data
const PROFILE_LINKS = [
@ -35,7 +33,6 @@ export const InstanceSidebarDropdown = observer(() => {
} = useApplication();
const { signOut, currentUser, currentUserSettings } = useUser();
// hooks
const { setToastAlert } = useToast();
const { setTheme } = useTheme();
// redirect url for normal mode
@ -53,8 +50,8 @@ export const InstanceSidebarDropdown = observer(() => {
router.push("/");
})
.catch(() =>
setToastAlert({
type: "error",
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: "Failed to sign out. Please try again.",
})