chore: i18n in toast

This commit is contained in:
Tristan Yang
2023-01-19 08:39:57 +08:00
parent 1f7baef4b6
commit fd8c54e702
34 changed files with 107 additions and 86 deletions
+3 -1
View File
@@ -3,12 +3,14 @@ import { KEY_LOCAL_MAGIC_TOKEN } from "../../app/config";
import { useLoginMutation } from "../../app/services/auth";
import toast from "react-hot-toast";
import { FetchBaseQueryError } from "@reduxjs/toolkit/dist/query";
import { useTranslation } from 'react-i18next';
export type GithubLoginSource = "widget" | "webapp"
type Props = {
code: string, from?: GithubLoginSource
}
const GithubCallback: FC<Props> = ({ code, from = "webapp" }) => {
const { t: ct } = useTranslation();
//拿本地存的magic token
const magic_token = localStorage.getItem(KEY_LOCAL_MAGIC_TOKEN);
const [login, { isLoading, isSuccess, error }] = useLoginMutation();
@@ -23,7 +25,7 @@ const GithubCallback: FC<Props> = ({ code, from = "webapp" }) => {
}, [code]);
useEffect(() => {
if (isSuccess) {
toast.success("Login Successfully");
toast.success(ct("tip.login"));
// 通知widget
if (from == 'widget') {
localStorage.setItem("widget", `${new Date().getTime()}`);
+3 -1
View File
@@ -10,12 +10,14 @@ import OidcLoginButton from "./OidcLoginButton";
import { useLoginMutation } from '../../app/services/auth';
import { LoginConfig } from '../../types/server';
import { AuthType } from '../../types/common';
import { useTranslation } from 'react-i18next';
type Props = {
type?: AuthType
}
const SocialLoginButtons = ({ type = "login" }: Props) => {
const { t: ct } = useTranslation();
const [login, { isSuccess }] = useLoginMutation();
const { config: githubAuthConfig } = useGithubAuthConfig();
const { data: loginConfig, isSuccess: loginConfigSuccess } = useGetLoginConfigQuery();
@@ -23,7 +25,7 @@ const SocialLoginButtons = ({ type = "login" }: Props) => {
useEffect(() => {
if (isSuccess) {
toast.success("Login Successfully");
toast.success(ct("tip.login"));
// navigateTo("/");
}
}, [isSuccess]);
+2 -1
View File
@@ -18,6 +18,7 @@ import SocialLoginButtons from "./SocialLoginButtons";
export default function LoginPage() {
const { t } = useTranslation("auth");
const { t: ct } = useTranslation();
const { data: enableSMTP } = useGetSMTPStatusQuery();
const [login, { isSuccess, isLoading, error }] = useLoginMutation();
const { clientId } = useGoogleAuthConfig();
@@ -82,7 +83,7 @@ export default function LoginPage() {
}, [error]);
useEffect(() => {
if (isSuccess) {
toast.success("Login Successfully");
toast.success(ct("tip.login"));
// navigateTo("/");
}
}, [isSuccess]);
+3 -1
View File
@@ -6,8 +6,10 @@ import { useNavigate, useParams } from "react-router-dom";
import { useLoginMutation } from "../../app/services/auth";
import toast from "react-hot-toast";
import { setAuthData } from "../../app/slices/auth.data";
import { useTranslation } from "react-i18next";
export default function OAuthPage() {
const { t: ct } = useTranslation();
const [login, { data, isSuccess, isError }] = useLoginMutation();
const { token } = useParams();
const [loading, setLoading] = useState(true);
@@ -36,7 +38,7 @@ export default function OAuthPage() {
if (isSuccess && data) {
setLoading(false);
// 更新本地认证信息
toast.success("Login Successfully");
toast.success(ct("tip.login"));
dispatch(setAuthData(data));
navigateTo("/");
}
@@ -31,7 +31,7 @@ const UpdateFrontendURL = ({ refreshInviteLink }: Props) => {
useEffect(() => {
if (isSuccess) {
refreshInviteLink();
toast.success("Update Successfully!");
toast.success(ct("tip.update"));
}
}, [isSuccess]);
return (
+3 -1
View File
@@ -8,8 +8,10 @@ import Button from "../../common/component/styled/Button";
import { useLoginMutation, useCheckMagicTokenValidMutation } from "../../app/services/auth";
import ExpiredTip from "./ExpiredTip";
import { useRegisterMutation } from "../../app/services/auth";
import { useTranslation } from "react-i18next";
const RegWithUsername: FC = () => {
const { t: ct } = useTranslation();
const [checkTokenInvalid, { data: isTokenValid, isLoading: checkingToken }] =
useCheckMagicTokenValidMutation();
const [
@@ -62,7 +64,7 @@ const RegWithUsername: FC = () => {
const data = loginData || regData;
if (isSuccess && data) {
// 更新本地认证信息
toast.success("Login Successfully");
toast.success(ct("tip.login"));
dispatch(setAuthData(data));
// tricky
location.href = `/#/`;
+1 -1
View File
@@ -72,7 +72,7 @@ export default function APIConfig() {
useEffect(() => {
if (isSuccess) {
hideAll();
toast.success("Update API Secret Successfully!");
toast.success(ct("tip.update"));
}
}, [isSuccess]);
const handleToggle = (val: { third_party: boolean }) => {
@@ -21,7 +21,7 @@ const DeleteAPIKeyModal = ({ closeModal, uid, kid }: Props) => {
};
useEffect(() => {
if (isSuccess) {
toast.success("Delete API Key Successfully!");
toast.success(ct("tip.delete"));
closeModal();
}
}, [isSuccess]);
+1 -1
View File
@@ -21,7 +21,7 @@ const DeleteModal = ({ closeModal, uid, name }: Props) => {
};
useEffect(() => {
if (isSuccess) {
toast.success("Delete Bot Successfully!");
toast.success(ct("tip.delete"));
closeModal();
}
}, [isSuccess]);
@@ -38,7 +38,7 @@ const WebhookModal = ({ uid, webhook, closeModal }: Props) => {
};
useEffect(() => {
if (isSuccess) {
toast.success("Update Webhook URL Successfully!");
toast.success(ct("tip.update"));
closeModal();
}
}, [isSuccess]);
+1 -1
View File
@@ -53,7 +53,7 @@ export default function BotConfig() {
};
useEffect(() => {
if (updateAvatarSuccess) {
toast.success("Update Bot Avatar Successfully!");
toast.success(ct("tip.update"));
}
}, [updateAvatarSuccess]);
@@ -28,7 +28,7 @@ const UpdateLicenseModal: FC<Props> = ({ closeModal, updateLicense, updating, up
};
useEffect(() => {
if (updated) {
toast.success("Update Successfully!");
toast.success(ct("tip.update"));
closeModal();
}
}, [updated]);
+1 -1
View File
@@ -50,7 +50,7 @@ const LogoutConfirmModal: FC<Props> = ({ closeModal }) => {
if (clearLocal) {
clearLocalData();
}
toast.success("Logout Successfully");
toast.success(ct("tip.logout"));
}
}, [exited, clearLocal]);
+1 -1
View File
@@ -127,7 +127,7 @@ export default function MyAccount() {
useEffect(() => {
if (uploadSuccess) {
toast.success("update avatar successfully!");
toast.success(ct("tip.update"));
}
}, [uploadSuccess]);
+1 -1
View File
@@ -22,7 +22,7 @@ const Index = () => {
const [updateUrl, { isLoading, isSuccess }] = useUpdateFrontendUrlMutation();
useEffect(() => {
if (isSuccess) {
toast.success("Update Successfully!");
toast.success(ct("tip.update"));
}
}, [isSuccess]);
useEffect(() => {
+2 -1
View File
@@ -12,6 +12,7 @@ import { useAppSelector } from '../../../app/store';
const Index = () => {
const { t } = useTranslation("setting");
const { t: ct } = useTranslation();
const { loginUser, server } = useAppSelector((store) => {
return { loginUser: store.authData.user, server: store.server };
});
@@ -42,7 +43,7 @@ const Index = () => {
}, [server]);
useEffect(() => {
if (uploadSuccess) {
toast.success("Update logo successfully!");
toast.success(ct("tip.update"));
}
}, [uploadSuccess]);
useEffect(() => {
+1 -1
View File
@@ -47,7 +47,7 @@ const ProfileBasicEditModal: FC<Props> = ({
useEffect(() => {
if (isSuccess) {
// todo
toast.success("update user info successfully");
toast.success(t("tip.update"));
closeModal();
}
}, [isSuccess]);
@@ -16,7 +16,6 @@ const RemoveConfirmModal: FC<Props> = ({ closeModal }) => {
const handleRemove = async () => {
try {
await removeCurrentAccount();
// toast.success("Remove Account Successfully!");
} catch (error) {
toast.error("Remove Account Failed!");
}
+2 -1
View File
@@ -36,6 +36,7 @@ interface BaseForm {
const ProfileBasicEditModal: FC<Props> = ({ closeModal }) => {
const { t } = useTranslation("member");
const { t: ct } = useTranslation();
const { data } = useGetCredentialsQuery();
const [input, setInput] = useState<BaseForm>({
current: "",
@@ -63,7 +64,7 @@ const ProfileBasicEditModal: FC<Props> = ({ closeModal }) => {
useEffect(() => {
if (isSuccess) {
// todo
toast.success("update password successfully");
toast.success(ct("tip.update"));
closeModal();
}
}, [isSuccess]);
+3 -2
View File
@@ -15,6 +15,7 @@ import { useTranslation } from "react-i18next";
export default function Logins() {
const { t } = useTranslation("setting", { keyPrefix: "login" });
const { t: ct } = useTranslation();
const {
changed: clientIdChanged,
clientId,
@@ -37,14 +38,14 @@ export default function Logins() {
// 更新google client id
await updateClientIdToServer();
if (!changed) {
toast.success("Configuration Updated!");
toast.success(ct("tip.update"));
}
}
if (github && githubChanged) {
// github config
await updateGithubAuthConfigToServer();
if (!changed) {
toast.success("Configuration Updated!");
toast.success(ct("tip.update"));
}
}
};
+1 -1
View File
@@ -39,7 +39,7 @@ const navs = [
items: [
{
name: "bot",
component: <ServerVersionChecker version="0.3.2"><BotConfig /></ServerVersionChecker>,
component: <ServerVersionChecker version="0.3.4"><BotConfig /></ServerVersionChecker>,
admin: true
},
{
@@ -23,7 +23,7 @@ const DeleteConfirmModal: FC<Props> = ({ id, closeModal }) => {
useEffect(() => {
if (isSuccess) {
toast.success("delete channel successfully!");
toast.success(ct("tip.delete"));
closeModal();
navigateTo("/chat");
}
+3 -2
View File
@@ -50,6 +50,7 @@ const StyledWrapper = styled.div`
`;
export default function Overview({ id = 0 }) {
const { t } = useTranslation("setting", { keyPrefix: "channel" });
const { t: ct } = useTranslation();
const { loginUser, channel } = useAppSelector((store) => {
return {
loginUser: store.authData.user,
@@ -105,13 +106,13 @@ export default function Overview({ id = 0 }) {
useEffect(() => {
if (updated) {
toast.success("Channel updated!");
toast.success(ct("tip.update"));
refetch();
}
}, [updated]);
useEffect(() => {
if (changeTypeSuccess) {
toast.success("Change channel visibility successfully!");
toast.success(ct("tip.update"));
}
}, [changeTypeSuccess]);
+1 -1
View File
@@ -23,7 +23,7 @@ const DeleteConfirmModal: FC<Props> = ({ id, closeModal }) => {
useEffect(() => {
if (isSuccess) {
toast.success("delete user successfully!");
toast.success(ct("tip.delete"));
closeModal();
navigateTo("/chat");
}