chore: release [ci skip]
This commit is contained in:
@@ -68,7 +68,10 @@ export default function LoginPasswordPage() {
|
||||
setErrors({ password: "", general: msg });
|
||||
}
|
||||
} catch {
|
||||
setErrors({ password: "", general: "Unable to connect, please try again" });
|
||||
setErrors({
|
||||
password: "",
|
||||
general: "Unable to connect, please try again",
|
||||
});
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
@@ -134,7 +137,9 @@ export default function LoginPasswordPage() {
|
||||
className="absolute top-1/2 right-4 -translate-y-1/2 text-(--color-text-muted) transition-colors hover:text-(--color-primary)"
|
||||
aria-label={showPassword ? "Hide password" : "Show password"}
|
||||
>
|
||||
<i className={`fa-solid ${showPassword ? "fa-eye-slash" : "fa-eye"}`}></i>
|
||||
<i
|
||||
className={`fa-solid ${showPassword ? "fa-eye-slash" : "fa-eye"}`}
|
||||
></i>
|
||||
</button>
|
||||
</div>
|
||||
{errors.password && (
|
||||
|
||||
@@ -14,13 +14,24 @@ export default function ManagerSignupPage() {
|
||||
|
||||
const [pageState, setPageState] = useState<PageState>("checking");
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [form, setForm] = useState({ name: "", phone: "", password: "", eateryName: "" });
|
||||
const [errors, setErrors] = useState({ name: "", phone: "", password: "", eateryName: "", submit: "" });
|
||||
const [form, setForm] = useState({
|
||||
name: "",
|
||||
phone: "",
|
||||
password: "",
|
||||
eateryName: "",
|
||||
});
|
||||
const [errors, setErrors] = useState({
|
||||
name: "",
|
||||
phone: "",
|
||||
password: "",
|
||||
eateryName: "",
|
||||
submit: "",
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/manager/signup")
|
||||
.then((res) => {
|
||||
setPageState("available")
|
||||
setPageState("available");
|
||||
// if (res.ok) ;
|
||||
// else if (res.status === 403) setPageState("closed");
|
||||
// else setPageState("error");
|
||||
@@ -28,21 +39,32 @@ export default function ManagerSignupPage() {
|
||||
.catch(() => setPageState("error"));
|
||||
}, []);
|
||||
|
||||
const validatePhone = (phone: string) => /^(0[3|5|7|8|9])[0-9]{8}$/.test(phone);
|
||||
const validatePhone = (phone: string) =>
|
||||
/^(0[3|5|7|8|9])[0-9]{8}$/.test(phone);
|
||||
|
||||
const handleChange = (field: keyof typeof form) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setForm({ ...form, [field]: e.target.value });
|
||||
setErrors({ ...errors, [field]: "", submit: "" });
|
||||
};
|
||||
const handleChange =
|
||||
(field: keyof typeof form) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setForm({ ...form, [field]: e.target.value });
|
||||
setErrors({ ...errors, [field]: "", submit: "" });
|
||||
};
|
||||
|
||||
const validate = () => {
|
||||
const next = { name: "", phone: "", password: "", eateryName: "", submit: "" };
|
||||
const next = {
|
||||
name: "",
|
||||
phone: "",
|
||||
password: "",
|
||||
eateryName: "",
|
||||
submit: "",
|
||||
};
|
||||
if (!form.name.trim()) next.name = "Please enter your full name";
|
||||
if (!form.phone.trim()) next.phone = "Please enter your phone number";
|
||||
else if (!validatePhone(form.phone)) next.phone = "Invalid phone number (e.g. 0987654321)";
|
||||
else if (!validatePhone(form.phone))
|
||||
next.phone = "Invalid phone number (e.g. 0987654321)";
|
||||
if (!form.password.trim()) next.password = "Please enter your password";
|
||||
else if (form.password.length < 6) next.password = "Password must be at least 6 characters";
|
||||
if (!form.eateryName.trim()) next.eateryName = "Please enter the restaurant name";
|
||||
else if (form.password.length < 6)
|
||||
next.password = "Password must be at least 6 characters";
|
||||
if (!form.eateryName.trim())
|
||||
next.eateryName = "Please enter the restaurant name";
|
||||
setErrors(next);
|
||||
return !next.name && !next.phone && !next.password && !next.eateryName;
|
||||
};
|
||||
@@ -67,7 +89,10 @@ export default function ManagerSignupPage() {
|
||||
ExistedUser: "Phone number already registered",
|
||||
InvalidPhoneNumber: "Invalid phone number",
|
||||
};
|
||||
setErrors({ ...errors, submit: errorMap[errorCode] ?? "An error occurred, please try again" });
|
||||
setErrors({
|
||||
...errors,
|
||||
submit: errorMap[errorCode] ?? "An error occurred, please try again",
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
setErrors({ ...errors, submit: "Unable to connect, please try again" });
|
||||
@@ -82,10 +107,21 @@ export default function ManagerSignupPage() {
|
||||
{/* Logo */}
|
||||
<div className="mb-8 flex flex-col items-center">
|
||||
<div className="relative mb-4 h-20 w-20">
|
||||
<Image src={SHOP_INFO.logo} alt={SHOP_INFO.name} fill className="object-contain" sizes="80px" priority />
|
||||
<Image
|
||||
src={SHOP_INFO.logo}
|
||||
alt={SHOP_INFO.name}
|
||||
fill
|
||||
className="object-contain"
|
||||
sizes="80px"
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
<h1 className="mb-1 text-2xl font-bold text-(--color-primary-dark)">{SHOP_INFO.name}</h1>
|
||||
<p className="text-sm text-(--color-text-muted)">Create a manager account</p>
|
||||
<h1 className="mb-1 text-2xl font-bold text-(--color-primary-dark)">
|
||||
{SHOP_INFO.name}
|
||||
</h1>
|
||||
<p className="text-sm text-(--color-text-muted)">
|
||||
Create a manager account
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Checking */}
|
||||
@@ -103,8 +139,13 @@ export default function ManagerSignupPage() {
|
||||
<i className="fa-solid fa-lock text-2xl text-red-500"></i>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<h2 className="mb-2 text-lg font-semibold text-(--color-text-primary)">Registration closed</h2>
|
||||
<p className="text-sm text-(--color-text-muted)">The system already has a restaurant. Registration is no longer available.</p>
|
||||
<h2 className="mb-2 text-lg font-semibold text-(--color-text-primary)">
|
||||
Registration closed
|
||||
</h2>
|
||||
<p className="text-sm text-(--color-text-muted)">
|
||||
The system already has a restaurant. Registration is no longer
|
||||
available.
|
||||
</p>
|
||||
</div>
|
||||
<Link
|
||||
href="/login"
|
||||
@@ -122,13 +163,36 @@ export default function ManagerSignupPage() {
|
||||
<i className="fa-solid fa-triangle-exclamation text-2xl text-yellow-500"></i>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<h2 className="mb-2 text-lg font-semibold text-(--color-text-primary)">Không thể kết nối</h2>
|
||||
<p className="text-sm text-(--color-text-muted)">Không thể kiểm tra trạng thái đăng ký. Vui lòng thử lại.</p>
|
||||
<h2 className="mb-2 text-lg font-semibold text-(--color-text-primary)">
|
||||
Không thể kết nối
|
||||
</h2>
|
||||
<p className="text-sm text-(--color-text-muted)">
|
||||
Không thể kiểm tra trạng thái đăng ký. Vui lòng thử lại.
|
||||
</p>
|
||||
</div>
|
||||
<Button variant="primaryNoBorder" style="login" size="lg" onClick={() => { setPageState("checking"); fetch("/api/manager/signup").then((r) => { if (r.ok) setPageState("available"); else if (r.status === 403) setPageState("closed"); else setPageState("error"); }).catch(() => setPageState("error")); }}>
|
||||
<Button
|
||||
variant="primaryNoBorder"
|
||||
style="login"
|
||||
size="lg"
|
||||
onClick={() => {
|
||||
setPageState("checking");
|
||||
fetch("/api/manager/signup")
|
||||
.then((r) => {
|
||||
if (r.ok) setPageState("available");
|
||||
else if (r.status === 403) setPageState("closed");
|
||||
else setPageState("error");
|
||||
})
|
||||
.catch(() => setPageState("error"));
|
||||
}}
|
||||
>
|
||||
Thử lại
|
||||
</Button>
|
||||
<Link href="/login" className="text-sm text-(--color-primary) underline">Quay lại đăng nhập</Link>
|
||||
<Link
|
||||
href="/login"
|
||||
className="text-sm text-(--color-primary) underline"
|
||||
>
|
||||
Quay lại đăng nhập
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -136,17 +200,50 @@ export default function ManagerSignupPage() {
|
||||
{pageState === "available" && (
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{[
|
||||
{ id: "name", label: "Họ tên", icon: "fa-user", placeholder: "Nguyễn Văn A", field: "name" as const, type: "text" },
|
||||
{ id: "phone", label: "Số điện thoại", icon: "fa-phone", placeholder: "0987654321", field: "phone" as const, type: "tel" },
|
||||
{ id: "password", label: "Mật khẩu", icon: "fa-lock", placeholder: "Ít nhất 6 ký tự", field: "password" as const, type: "password" },
|
||||
{ id: "eateryName", label: "Tên nhà hàng", icon: "fa-store", placeholder: "Coffee & More", field: "eateryName" as const, type: "text" },
|
||||
{
|
||||
id: "name",
|
||||
label: "Họ tên",
|
||||
icon: "fa-user",
|
||||
placeholder: "Nguyễn Văn A",
|
||||
field: "name" as const,
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
id: "phone",
|
||||
label: "Số điện thoại",
|
||||
icon: "fa-phone",
|
||||
placeholder: "0987654321",
|
||||
field: "phone" as const,
|
||||
type: "tel",
|
||||
},
|
||||
{
|
||||
id: "password",
|
||||
label: "Mật khẩu",
|
||||
icon: "fa-lock",
|
||||
placeholder: "Ít nhất 6 ký tự",
|
||||
field: "password" as const,
|
||||
type: "password",
|
||||
},
|
||||
{
|
||||
id: "eateryName",
|
||||
label: "Tên nhà hàng",
|
||||
icon: "fa-store",
|
||||
placeholder: "Coffee & More",
|
||||
field: "eateryName" as const,
|
||||
type: "text",
|
||||
},
|
||||
].map(({ id, label, icon, placeholder, field, type }) => (
|
||||
<div key={id}>
|
||||
<label htmlFor={id} className="mb-2 block text-sm font-medium text-(--color-text-secondary)">
|
||||
<label
|
||||
htmlFor={id}
|
||||
className="mb-2 block text-sm font-medium text-(--color-text-secondary)"
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
<div className="relative">
|
||||
<i className={`fa-solid ${icon} absolute top-1/2 left-4 hidden -translate-y-1/2 text-(--color-text-muted) lg:block`}></i>
|
||||
<i
|
||||
className={`fa-solid ${icon} absolute top-1/2 left-4 hidden -translate-y-1/2 text-(--color-text-muted) lg:block`}
|
||||
></i>
|
||||
<input
|
||||
id={id}
|
||||
type={type}
|
||||
@@ -174,9 +271,18 @@ export default function ManagerSignupPage() {
|
||||
)}
|
||||
|
||||
<div className="space-y-3 pt-2">
|
||||
<Button variant="primaryNoBorder" type="submit" style="login" size="lg" disabled={isLoading}>
|
||||
<Button
|
||||
variant="primaryNoBorder"
|
||||
type="submit"
|
||||
style="login"
|
||||
size="lg"
|
||||
disabled={isLoading}
|
||||
>
|
||||
{isLoading ? (
|
||||
<><i className="fa-solid fa-spinner fa-spin mr-2"></i>Đang xử lý...</>
|
||||
<>
|
||||
<i className="fa-solid fa-spinner fa-spin mr-2"></i>Đang xử
|
||||
lý...
|
||||
</>
|
||||
) : (
|
||||
"Đăng ký"
|
||||
)}
|
||||
|
||||
@@ -91,7 +91,8 @@ export default function RegisterPage() {
|
||||
ExistedUser: "Phone number already registered",
|
||||
InvalidPhoneNumber: "Invalid phone number",
|
||||
};
|
||||
const msg = phoneErrorMap[errorCode] ?? "An error occurred, please try again";
|
||||
const msg =
|
||||
phoneErrorMap[errorCode] ?? "An error occurred, please try again";
|
||||
setErrors({ phone: msg, otp: "" });
|
||||
}
|
||||
} catch {
|
||||
@@ -364,7 +365,7 @@ export default function RegisterPage() {
|
||||
type="button"
|
||||
onClick={sendOtp}
|
||||
disabled={otpSending || isLoading}
|
||||
className="text-sm text-(--color-primary) underline disabled:cursor-not-allowed disabled:opacity-50 disabled:no-underline"
|
||||
className="text-sm text-(--color-primary) underline disabled:cursor-not-allowed disabled:no-underline disabled:opacity-50"
|
||||
>
|
||||
{otpSending ? (
|
||||
<>
|
||||
|
||||
@@ -306,7 +306,8 @@ export default function AnalyticsPage() {
|
||||
{activeChart === "bar" && (
|
||||
<>
|
||||
<p className="mb-3 text-xs text-(--color-text-muted)">
|
||||
Comparing revenue of the first and second half of the current period
|
||||
Comparing revenue of the first and second half of the current
|
||||
period
|
||||
</p>
|
||||
<BarChart
|
||||
current={barCurrent}
|
||||
@@ -394,25 +395,19 @@ export default function AnalyticsPage() {
|
||||
{/* Summary row */}
|
||||
<div className="bg-background mt-4 flex flex-wrap gap-4 rounded-xl p-4 text-sm">
|
||||
<div>
|
||||
<span className="text-(--color-text-muted)">
|
||||
Total revenue:{" "}
|
||||
</span>
|
||||
<span className="text-(--color-text-muted)">Total revenue: </span>
|
||||
<span className="font-semibold text-(--color-primary)">
|
||||
{formatCurrencyFull(filteredRevenue)}
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-(--color-text-muted)">
|
||||
Total profit:{" "}
|
||||
</span>
|
||||
<span className="text-(--color-text-muted)">Total profit: </span>
|
||||
<span className="font-semibold text-green-600">
|
||||
{formatCurrencyFull(filteredProfit)}
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-(--color-text-muted)">
|
||||
Total units:{" "}
|
||||
</span>
|
||||
<span className="text-(--color-text-muted)">Total units: </span>
|
||||
<span className="text-foreground font-semibold">
|
||||
{filteredUnits.toLocaleString()} cups
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user