diff --git a/src/components/Language.tsx b/src/components/Language.tsx new file mode 100644 index 00000000..7bc3d2a1 --- /dev/null +++ b/src/components/Language.tsx @@ -0,0 +1,34 @@ +import Tippy from "@tippyjs/react"; +import { useState } from "react"; +import LanguageList, { LangMap, LanguageType } from "../routes/setting/Overview/Language"; +import StyledButton from "./styled/Button"; +import { useTranslation } from "react-i18next"; +import ArrowDown from "@/assets/icons/arrow.down.svg"; +import { cn } from "../utils"; +type Props = {}; + +const SelectLanguage = ({}: Props) => { + const { i18n } = useTranslation(); + const [visible, setVisible] = useState(false); + const langKey = i18n.language as LanguageType; + const [lang, setLang] = useState(LangMap[langKey]); + return ( + } + > + + {lang}{" "} + {" "} + + + ); +}; + +export default SelectLanguage; diff --git a/src/components/SettingBlock.tsx b/src/components/SettingBlock.tsx index 669e5959..1979511a 100644 --- a/src/components/SettingBlock.tsx +++ b/src/components/SettingBlock.tsx @@ -8,6 +8,7 @@ type Props = { }; const SettingBlock = ({ toggler, title, desc, children }: Props) => { + if (!title) return
{children}
; return (
diff --git a/src/routes/login/index.tsx b/src/routes/login/index.tsx index 7f879544..201b51a9 100644 --- a/src/routes/login/index.tsx +++ b/src/routes/login/index.tsx @@ -1,4 +1,3 @@ - import { ChangeEvent, FormEvent, useEffect, useState } from "react"; import toast from "react-hot-toast"; import { useTranslation } from "react-i18next"; @@ -17,10 +16,11 @@ import MagicLinkLogin from "./MagicLinkLogin"; import SignUpLink from "./SignUpLink"; import SocialLoginButtons from "./SocialLoginButtons"; import { shallowEqual } from "react-redux"; +import SelectLanguage from "../../components/Language"; const defaultInput = { email: "", - password: "" + password: "", }; export default function LoginPage() { const { name: serverName, logo } = useAppSelector((store) => store.server, shallowEqual); @@ -44,7 +44,7 @@ export default function LoginPage() { login({ code, state, - type: "oidc" + type: "oidc", }); } // magic link @@ -54,7 +54,7 @@ export default function LoginPage() { // login login({ magic_token, - type: "magiclink" + type: "magiclink", }); } else { // reg with magic link and set name only @@ -104,7 +104,7 @@ export default function LoginPage() { } login({ ...input, - type: "password" + type: "password", }); }; @@ -199,6 +199,7 @@ export default function LoginPage() {
{whoCanSignUp === "EveryOne" && }
+ ); } diff --git a/src/routes/onboarding/index.tsx b/src/routes/onboarding/index.tsx index bea3e694..28d7ac3d 100644 --- a/src/routes/onboarding/index.tsx +++ b/src/routes/onboarding/index.tsx @@ -10,6 +10,7 @@ import InviteLink from "./steps/invite-link"; import ServerName from "./steps/server-name"; import WelcomePage from "./steps/welcome-page"; import WhoCanSignUp from "./steps/who-can-sign-up"; +import SelectLanguage from "../../components/Language"; const Navigator = () => { const { activeStep, goToStep } = useWizard(); @@ -52,7 +53,7 @@ export default function OnboardingPage() { const [serverName, setServerName] = useState(""); return ( <> - {t("onboarding.title") || ""} + {t("onboarding.title") || ""}
}> @@ -64,6 +65,7 @@ export default function OnboardingPage() {
+ ); } diff --git a/src/routes/reg/index.tsx b/src/routes/reg/index.tsx index f4769155..862f3d8c 100644 --- a/src/routes/reg/index.tsx +++ b/src/routes/reg/index.tsx @@ -3,6 +3,7 @@ import { Outlet, useOutletContext, useSearchParams } from "react-router-dom"; import { useCheckMagicTokenValidMutation } from "@/app/services/auth"; import ExpiredTip from "./ExpiredTip"; +import SelectLanguage from "../../components/Language"; type ContextType = { token: string }; export default function RegContainer() { @@ -23,19 +24,22 @@ export default function RegContainer() { }, [tokenIsValid, magic_token]); if (checkingToken) return
Checking Magic Link...
; return ( -
-
- {magic_token ? ( - tokenIsValid ? ( - + <> +
+
+ {magic_token ? ( + tokenIsValid ? ( + + ) : ( + + ) ) : ( - - ) - ) : ( - - )} + + )} +
-
+ + ); } diff --git a/src/routes/sendMagicLink/index.tsx b/src/routes/sendMagicLink/index.tsx index f76509ef..72949eb7 100644 --- a/src/routes/sendMagicLink/index.tsx +++ b/src/routes/sendMagicLink/index.tsx @@ -4,6 +4,7 @@ import { useNavigate, useParams } from "react-router-dom"; import { useSendLoginMagicLinkMutation } from "@/app/services/auth"; import SentTip from "./SentTip"; +import SelectLanguage from "../../components/Language"; export default function SendMagicLinkPage() { const { email = "" } = useParams(); @@ -46,14 +47,17 @@ export default function SendMagicLinkPage() { }; return ( -
-
- {isSuccess ? ( - - ) : isLoading ? ( -
Sending...
- ) : null} + <> + +
+
+ {isSuccess ? ( + + ) : isLoading ? ( +
Sending...
+ ) : null} +
-
+ ); } diff --git a/src/routes/setting/Overview/Language.tsx b/src/routes/setting/Overview/Language.tsx index bea9dcd1..c195517d 100644 --- a/src/routes/setting/Overview/Language.tsx +++ b/src/routes/setting/Overview/Language.tsx @@ -5,8 +5,8 @@ import SettingBlock from "@/components/SettingBlock"; import StyledRadio from "@/components/styled/Radio"; // type Props = {} -type LanguageType = "en" | "zh" | "jp" | "tr" | "pt" | "es" | "fr" | "ru"; -const LangMap: Record = { +export type LanguageType = "en" | "zh" | "jp" | "tr" | "pt" | "es" | "fr" | "ru"; +export const LangMap: Record = { en: "English", zh: "中文", tr: "Türkçe", @@ -14,15 +14,24 @@ const LangMap: Record = { pt: "Portuguese", fr: "Français", es: "Español", - ru: "Русский" + ru: "Русский", }; -const Index = () => { +const LanguageList = ({ + context = "overview", + callback, +}: { + context?: "overview" | "aside"; + callback?: (_v: string) => void; +}) => { const { t, i18n } = useTranslation("setting"); const handleGuestToggle = (v: LanguageType) => { i18n.changeLanguage(v); }; return ( - + { onChange={(v) => { const _v = v as LanguageType; handleGuestToggle(_v); + callback?.(LangMap[_v]); }} /> ); }; -export default Index; +export default LanguageList; diff --git a/src/routes/setting/Overview/language.tsx b/src/routes/setting/Overview/language.tsx index bea9dcd1..c195517d 100644 --- a/src/routes/setting/Overview/language.tsx +++ b/src/routes/setting/Overview/language.tsx @@ -5,8 +5,8 @@ import SettingBlock from "@/components/SettingBlock"; import StyledRadio from "@/components/styled/Radio"; // type Props = {} -type LanguageType = "en" | "zh" | "jp" | "tr" | "pt" | "es" | "fr" | "ru"; -const LangMap: Record = { +export type LanguageType = "en" | "zh" | "jp" | "tr" | "pt" | "es" | "fr" | "ru"; +export const LangMap: Record = { en: "English", zh: "中文", tr: "Türkçe", @@ -14,15 +14,24 @@ const LangMap: Record = { pt: "Portuguese", fr: "Français", es: "Español", - ru: "Русский" + ru: "Русский", }; -const Index = () => { +const LanguageList = ({ + context = "overview", + callback, +}: { + context?: "overview" | "aside"; + callback?: (_v: string) => void; +}) => { const { t, i18n } = useTranslation("setting"); const handleGuestToggle = (v: LanguageType) => { i18n.changeLanguage(v); }; return ( - + { onChange={(v) => { const _v = v as LanguageType; handleGuestToggle(_v); + callback?.(LangMap[_v]); }} /> ); }; -export default Index; +export default LanguageList;