🐛 fix: Update invite link format in auth forms and sidebar to include hash fragment for routing.
This commit is contained in:
parent
076d35100e
commit
7a8c010295
@ -1,13 +1,13 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
import { useNavigate, useSearch } from "@tanstack/react-router";
|
||||||
import {
|
import {
|
||||||
resetPassword,
|
resetPassword,
|
||||||
userLogin,
|
userLogin,
|
||||||
userRegister,
|
userRegister,
|
||||||
} from "@workspace/ui/services/common/auth";
|
} from "@workspace/ui/services/common/auth";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { useState, useTransition } from "react";
|
import { useEffect, useState, useTransition } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { USER_EMAIL, USER_PASSWORD } from "@/config";
|
import { USER_EMAIL, USER_PASSWORD } from "@/config";
|
||||||
@ -21,16 +21,25 @@ export default function EmailAuthForm() {
|
|||||||
const { t } = useTranslation("auth");
|
const { t } = useTranslation("auth");
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { getUserInfo } = useGlobalStore();
|
const { getUserInfo } = useGlobalStore();
|
||||||
|
const searchParams = useSearch({ strict: false }) as { invite?: string };
|
||||||
const [type, setType] = useState<"login" | "register" | "reset">("login");
|
const [type, setType] = useState<"login" | "register" | "reset">("login");
|
||||||
const [loading, startTransition] = useTransition();
|
const [loading, startTransition] = useTransition();
|
||||||
const [initialValues, setInitialValues] = useState<{
|
const [initialValues, setInitialValues] = useState<{
|
||||||
email?: string;
|
email?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
|
invite?: string;
|
||||||
}>({
|
}>({
|
||||||
email: USER_EMAIL,
|
email: USER_EMAIL,
|
||||||
password: USER_PASSWORD,
|
password: USER_PASSWORD,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (searchParams.invite) {
|
||||||
|
localStorage.setItem("invite", searchParams.invite);
|
||||||
|
setInitialValues((prev) => ({ ...prev, invite: searchParams.invite }));
|
||||||
|
}
|
||||||
|
}, [searchParams.invite]);
|
||||||
|
|
||||||
const handleFormSubmit = async (params: any) => {
|
const handleFormSubmit = async (params: any) => {
|
||||||
const onLogin = async (token?: string) => {
|
const onLogin = async (token?: string) => {
|
||||||
if (!token) return;
|
if (!token) return;
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
import { useNavigate, useSearch } from "@tanstack/react-router";
|
||||||
import {
|
import {
|
||||||
telephoneLogin,
|
telephoneLogin,
|
||||||
telephoneResetPassword,
|
telephoneResetPassword,
|
||||||
telephoneUserRegister,
|
telephoneUserRegister,
|
||||||
} from "@workspace/ui/services/common/auth";
|
} from "@workspace/ui/services/common/auth";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { useState, useTransition } from "react";
|
import { useEffect, useState, useTransition } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { useGlobalStore } from "@/stores/global";
|
import { useGlobalStore } from "@/stores/global";
|
||||||
@ -20,6 +20,7 @@ export default function PhoneAuthForm() {
|
|||||||
const { t } = useTranslation("auth");
|
const { t } = useTranslation("auth");
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { getUserInfo } = useGlobalStore();
|
const { getUserInfo } = useGlobalStore();
|
||||||
|
const searchParams = useSearch({ strict: false }) as { invite?: string };
|
||||||
const [type, setType] = useState<"login" | "register" | "reset">("login");
|
const [type, setType] = useState<"login" | "register" | "reset">("login");
|
||||||
const [loading, startTransition] = useTransition();
|
const [loading, startTransition] = useTransition();
|
||||||
const [initialValues, setInitialValues] = useState<API.TelephoneLoginRequest>(
|
const [initialValues, setInitialValues] = useState<API.TelephoneLoginRequest>(
|
||||||
@ -32,6 +33,13 @@ export default function PhoneAuthForm() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (searchParams.invite) {
|
||||||
|
localStorage.setItem("invite", searchParams.invite);
|
||||||
|
setInitialValues((prev) => ({ ...prev, invite: searchParams.invite }));
|
||||||
|
}
|
||||||
|
}, [searchParams.invite]);
|
||||||
|
|
||||||
const handleFormSubmit = async (params: any) => {
|
const handleFormSubmit = async (params: any) => {
|
||||||
const onLogin = async (token?: string) => {
|
const onLogin = async (token?: string) => {
|
||||||
if (!token) return;
|
if (!token) return;
|
||||||
|
|||||||
@ -72,7 +72,7 @@ export default function Affiliate() {
|
|||||||
toast.success(t("copySuccess", "Copy Success"));
|
toast.success(t("copySuccess", "Copy Success"));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
text={`${location?.origin}/auth?invite=${user?.refer_code}`}
|
text={`${location?.origin}/#/auth?invite=${user?.refer_code}`}
|
||||||
>
|
>
|
||||||
<Button className="gap-2" size="sm" variant="secondary">
|
<Button className="gap-2" size="sm" variant="secondary">
|
||||||
<Copy className="h-4 w-4" />
|
<Copy className="h-4 w-4" />
|
||||||
|
|||||||
@ -69,7 +69,7 @@ export function SidebarRight({
|
|||||||
toast.success(t("copySuccess", "Copy Success"));
|
toast.success(t("copySuccess", "Copy Success"));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
text={`${isBrowser() && location?.origin}/auth?invite=${user?.refer_code}`}
|
text={`${isBrowser() && location?.origin}/#/auth?invite=${user?.refer_code}`}
|
||||||
>
|
>
|
||||||
<Button className="size-5 p-0" variant="ghost">
|
<Button className="size-5 p-0" variant="ghost">
|
||||||
<Icon
|
<Icon
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user