feat/0.2:add theme setting and about page setting and support use email and password login
This commit is contained in:
1 parent
58292b0e6e
commit
ca2b732952
85 files changed
+5797
-816
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import React from "react";
|
||||
import type { Metadata } from "next";
|
||||
import { createBaseMetadata, getDynamicTitle } from "@/shared/utils/metadata";
|
||||
import { AboutThemeSelector } from "@/components/theme/AboutThemeSelector";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const title = await getDynamicTitle("About");
|
||||
return createBaseMetadata(title);
|
||||
}
|
||||
|
||||
export default async function AboutPage() {
|
||||
return <AboutThemeSelector />;
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
@@ -1,30 +1,40 @@
|
||||
"use client";
|
||||
|
||||
import React, { Suspense } from "react";
|
||||
import React, { Suspense, useEffect } from "react";
|
||||
import { Spinner } from "@nextui-org/react";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
import AdminSignInComponent from "./components/AdminSignIn";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAdminStore } from "@/store/admin";
|
||||
|
||||
const AdminLoginHeader = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center pb-6">
|
||||
<DynamicLogo
|
||||
alt="Platform Logo"
|
||||
className="h-[40px]"
|
||||
/>
|
||||
<DynamicLogo alt="Platform Logo" className="h-[40px]" />
|
||||
<p className="text-xl font-medium mt-4">{t("Admin Portal")}</p>
|
||||
<p className="text-sm text-default-500">
|
||||
{t("Log in to admin console")}
|
||||
</p>
|
||||
<p className="text-sm text-default-500">{t("Log in to admin console")}</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const AdminLoginPageContent = () => {
|
||||
const [getAdminUser] = useAdminStore((state) => [state.getAdminUser]);
|
||||
const router = useRouter();
|
||||
|
||||
const handleCheckLogin = async () => {
|
||||
const res = await getAdminUser();
|
||||
if (res.success) {
|
||||
router.push("/console");
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
handleCheckLogin();
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col items-center justify-center w-full h-full mt-20">
|
||||
@@ -38,10 +48,16 @@ const AdminLoginPageContent = () => {
|
||||
|
||||
const AdminLoginPage = () => {
|
||||
return (
|
||||
<Suspense fallback={<div className="flex justify-center mt-40"><Spinner size="lg" color="default" /></div>}>
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="flex justify-center mt-40">
|
||||
<Spinner size="lg" color="default" />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<AdminLoginPageContent />
|
||||
</Suspense>
|
||||
);
|
||||
};
|
||||
|
||||
export default AdminLoginPage;
|
||||
export default AdminLoginPage;
|
||||
@@ -2,6 +2,9 @@
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
/* Import theme styles */
|
||||
@import '../styles/themes.css';
|
||||
|
||||
html,
|
||||
body {
|
||||
padding: 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { cache } from "react";
|
||||
import { notFound } from "next/navigation";
|
||||
import { ProductDetailClient } from "@/shared/components/marketplace/ProductDetail";
|
||||
import { ProductDetailThemeSelector } from "@/components/theme/ProductDetailThemeSelector";
|
||||
import type { Metadata } from "next";
|
||||
import { createBaseMetadata, getDynamicTitle } from "@/shared/utils/metadata";
|
||||
import { fetchServiceById } from "@/services/marketplaceService";
|
||||
@@ -8,20 +8,21 @@ import type { ServiceData } from "@/shared/types/marketplace";
|
||||
import { Footer } from "@/shared/components/Footer";
|
||||
import { Navigation } from "@/shared/components/Navigation";
|
||||
|
||||
|
||||
interface ProductPageProps {
|
||||
params: Promise<{ id: string }>;
|
||||
}
|
||||
|
||||
const getProductById = cache(async (id: string): Promise<ServiceData | null> => {
|
||||
try {
|
||||
const product = await fetchServiceById(id);
|
||||
return product;
|
||||
} catch (error) {
|
||||
console.error(`Error fetching product ${id}:`, error);
|
||||
return null;
|
||||
const getProductById = cache(
|
||||
async (id: string): Promise<ServiceData | null> => {
|
||||
try {
|
||||
const product = await fetchServiceById(id);
|
||||
return product;
|
||||
} catch (error) {
|
||||
console.error(`Error fetching product ${id}:`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
// Generate metadata for SEO
|
||||
export async function generateMetadata({
|
||||
@@ -36,7 +37,9 @@ export async function generateMetadata({
|
||||
const title = await getDynamicTitle(product.name);
|
||||
return {
|
||||
...createBaseMetadata(title),
|
||||
description: product.short_description || `Discover ${product.name} and its powerful tools`,
|
||||
description:
|
||||
product.short_description ||
|
||||
`Discover ${product.name} and its powerful tools`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -55,13 +58,5 @@ export default async function ProductPage({ params }: ProductPageProps) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex flex-col justify-between">
|
||||
<Navigation />
|
||||
<main className="flex-1">
|
||||
<ProductDetailClient product={serviceData} />
|
||||
</main>
|
||||
<div> <Footer /></div>
|
||||
</div>
|
||||
)
|
||||
return <ProductDetailThemeSelector product={serviceData} />;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { Navigation } from "@/shared/components/Navigation";
|
||||
import { Footer } from "@/shared/components/Footer";
|
||||
import { fetchServices } from "@/services/marketplaceService";
|
||||
import type { ServiceData } from "@/shared/types/marketplace";
|
||||
import { ThemeSelector } from "@/components/theme/ThemeSelector";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const title = await getDynamicTitle("Marketplace");
|
||||
@@ -43,23 +44,13 @@ export default async function HomePage({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex flex-col justify-between">
|
||||
<Navigation />
|
||||
<main className="flex-1">
|
||||
<Suspense>
|
||||
<MarketplaceMain
|
||||
initialServices={services}
|
||||
initialTotal={total}
|
||||
initialPage={page}
|
||||
initialSearch={search}
|
||||
pageSize={pageSize}
|
||||
error={error}
|
||||
/>
|
||||
</Suspense>
|
||||
</main>
|
||||
<div>
|
||||
<Footer />
|
||||
</div>
|
||||
</div>
|
||||
<ThemeSelector
|
||||
initialServices={services}
|
||||
initialTotal={total}
|
||||
initialPage={page}
|
||||
initialSearch={search}
|
||||
pageSize={pageSize}
|
||||
error={error}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { Button, Input } from "@nextui-org/react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { useForm, Controller } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
import { StepState } from "../page";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
|
||||
const emailSchema = z.object({
|
||||
email: z.string().email("Invalid email address"),
|
||||
email: z
|
||||
.string()
|
||||
.email({ message: "Invalid email address" })
|
||||
.min(1, { message: "Email is required" }),
|
||||
});
|
||||
|
||||
type EmailFormData = z.infer<typeof emailSchema>;
|
||||
@@ -20,13 +23,14 @@ interface LoginEmailFromProps {
|
||||
|
||||
export const LoginEmailFrom = ({ setEmail, setStep }: LoginEmailFromProps) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
|
||||
const {
|
||||
register,
|
||||
control,
|
||||
handleSubmit,
|
||||
formState: { errors, isSubmitting },
|
||||
formState: { errors, isSubmitting, isValid },
|
||||
} = useForm<EmailFormData>({
|
||||
resolver: zodResolver(emailSchema),
|
||||
mode: "all",
|
||||
});
|
||||
|
||||
const onSubmit = async (data: EmailFormData) => {
|
||||
@@ -36,14 +40,22 @@ export const LoginEmailFrom = ({ setEmail, setStep }: LoginEmailFromProps) => {
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-4">
|
||||
<Input
|
||||
{...register("email")}
|
||||
type="email"
|
||||
label={t("Email")}
|
||||
placeholder={t("Enter your email")}
|
||||
isInvalid={!!errors.email}
|
||||
errorMessage={errors.email?.message}
|
||||
variant="bordered"
|
||||
<Controller
|
||||
name="email"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<Input
|
||||
{...field}
|
||||
type="email"
|
||||
label={t("Email")}
|
||||
placeholder={t("Enter your email")}
|
||||
isInvalid={!!errors.email}
|
||||
errorMessage={t(errors.email?.message || "")}
|
||||
variant="bordered"
|
||||
color={errors.email ? "danger" : "default"}
|
||||
className={errors.email ? "border-danger" : ""}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
@@ -55,4 +67,4 @@ export const LoginEmailFrom = ({ setEmail, setStep }: LoginEmailFromProps) => {
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,114 @@
|
||||
"use client";
|
||||
|
||||
import { Button, Input } from "@nextui-org/react";
|
||||
import { useForm, Controller } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
import { useState } from "react";
|
||||
import { Eye, EyeOff } from "lucide-react";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { useLogin } from "@/hooks/useLogin";
|
||||
import { md5Encrypt } from "@/shared/utils/crypto";
|
||||
|
||||
const emailPasswordSchema = z.object({
|
||||
email: z
|
||||
.string()
|
||||
.email({ message: "Invalid email address" })
|
||||
.min(1, { message: "Email is required" }),
|
||||
password: z.string().min(6, "Password must be at least 6 characters"),
|
||||
});
|
||||
|
||||
type EmailPasswordFormData = z.infer<typeof emailPasswordSchema>;
|
||||
|
||||
interface LoginEmailPasswordFormProps {
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
export const LoginEmailPasswordForm = ({
|
||||
onSuccess,
|
||||
}: LoginEmailPasswordFormProps) => {
|
||||
const { t } = useTranslation();
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const { emailPasswordLogin } = useLogin();
|
||||
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
formState: { errors, isSubmitting, isValid },
|
||||
} = useForm<EmailPasswordFormData>({
|
||||
resolver: zodResolver(emailPasswordSchema),
|
||||
mode: "all",
|
||||
});
|
||||
|
||||
const onSubmit = async (data: EmailPasswordFormData) => {
|
||||
try {
|
||||
await emailPasswordLogin({
|
||||
user_email: data.email,
|
||||
password: md5Encrypt(data.password),
|
||||
});
|
||||
onSuccess?.();
|
||||
} catch (error) {
|
||||
console.error("Login failed:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-4">
|
||||
<Controller
|
||||
name="email"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<Input
|
||||
{...field}
|
||||
type="email"
|
||||
label={t("Email")}
|
||||
placeholder={t("Enter your email")}
|
||||
isInvalid={!!errors.email}
|
||||
errorMessage={t(errors.email?.message || "")}
|
||||
variant="bordered"
|
||||
color={errors.email ? "danger" : "default"}
|
||||
className={errors.email ? "border-danger" : ""}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="password"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<Input
|
||||
{...field}
|
||||
type={showPassword ? "text" : "password"}
|
||||
label={t("Password")}
|
||||
placeholder={t("Enter your password")}
|
||||
isInvalid={!!errors.password}
|
||||
errorMessage={errors.password?.message}
|
||||
variant="bordered"
|
||||
color={errors.password ? "danger" : "default"}
|
||||
className={errors.password ? "border-danger" : ""}
|
||||
endContent={
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowPassword(!showPassword)}
|
||||
className="focus:outline-none"
|
||||
>
|
||||
{showPassword ? (
|
||||
<EyeOff className="w-4 h-4 text-gray-400" />
|
||||
) : (
|
||||
<Eye className="w-4 h-4 text-gray-400" />
|
||||
)}
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
color="primary"
|
||||
isLoading={isSubmitting}
|
||||
className="w-full"
|
||||
>
|
||||
{t("Sign In")}
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
@@ -6,8 +6,10 @@ import { LoginButton } from "./LoginButton";
|
||||
import { useLogin } from "@/hooks/useLogin";
|
||||
import { EmailVerificationForm } from "./VerifyEmail";
|
||||
import { LoginEmailFrom } from "./LoginEmailFrom";
|
||||
import { LoginEmailPasswordForm } from "./LoginEmailPasswordForm";
|
||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
import { EmailMode } from "@/shared/types/system";
|
||||
|
||||
export type StepState = "init" | "emailForm" | "verifyEmail";
|
||||
|
||||
@@ -16,10 +18,17 @@ const SignInComponent = () => {
|
||||
const [email, setEmail] = useState("");
|
||||
const [step, setStep] = useState<StepState>("init");
|
||||
const { googleLoginOrSignUp } = useLogin();
|
||||
const { googleAuthConfig } = usePlatformConfig();
|
||||
const { loginConfig } = usePlatformConfig();
|
||||
|
||||
// 检查是否启用了 Google 登录
|
||||
const isGoogleLoginEnabled = googleAuthConfig?.is_enabled && googleAuthConfig?.client_id;
|
||||
const isGoogleLoginEnabled =
|
||||
loginConfig?.google?.is_enabled && loginConfig?.google?.client_id;
|
||||
|
||||
// 检查是否启用了邮箱登录
|
||||
const isEmailEnabled = loginConfig?.email?.is_enabled ?? true;
|
||||
|
||||
// 获取邮箱登录模式
|
||||
const emailMode = loginConfig?.email?.mode ?? EmailMode.PASSWORD;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -34,8 +43,8 @@ const SignInComponent = () => {
|
||||
onClick={googleLoginOrSignUp}
|
||||
/>
|
||||
)}
|
||||
{/* OR - 只有在启用 Google 登录时才显示分隔符 */}
|
||||
{isGoogleLoginEnabled && (
|
||||
{/* OR - 只有在启用 Google 登录且有其他登录方式时才显示分隔符 */}
|
||||
{isGoogleLoginEnabled && isEmailEnabled && (
|
||||
<div className="flex items-center gap-4">
|
||||
<Divider className="flex-1" />
|
||||
<p className="shrink-0 text-tiny text-default-500">{t("OR")}</p>
|
||||
@@ -43,8 +52,18 @@ const SignInComponent = () => {
|
||||
</div>
|
||||
)}
|
||||
{/* Login With Email */}
|
||||
{step === "init" && (
|
||||
<LoginEmailFrom setEmail={setEmail} setStep={setStep} />
|
||||
{step === "init" && isEmailEnabled && (
|
||||
<div className="space-y-4">
|
||||
{/* 邮箱/密码登录表单 */}
|
||||
{emailMode === EmailMode.PASSWORD && (
|
||||
<LoginEmailPasswordForm />
|
||||
)}
|
||||
|
||||
{/* 邮箱/验证码登录表单 */}
|
||||
{emailMode === EmailMode.CAPTCHA && (
|
||||
<LoginEmailFrom setEmail={setEmail} setStep={setStep} />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{step !== "init" && isGoogleLoginEnabled && (
|
||||
<LoginButton
|
||||
@@ -64,4 +83,4 @@ export default function SignInWrapper() {
|
||||
<SignInComponent />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user