|
|
@@ -16,6 +16,7 @@ import type{ CustomerProfileResult } from "@/types/customer/information/informat
|
|
|
import {GET_CUSTOMER_PROFILE,UPDATE_CUSTOMER_PROFILE} from "@/graphql";
|
|
|
import type{ UpdateCustomerProfileVars } from "@/types/customer/information/information";
|
|
|
import { useCustomToast } from "@/utils/hooks/useToast";
|
|
|
+import { useRouter } from 'next/navigation';
|
|
|
const AccountEditPage = () => {
|
|
|
interface UserForm {
|
|
|
firstname: string;
|
|
|
@@ -26,7 +27,14 @@ const AccountEditPage = () => {
|
|
|
password: string;
|
|
|
phone: string;
|
|
|
}
|
|
|
+ const [isInvalid, setIsInvalid] = useState(false);
|
|
|
+ const [errorMsg, setErrorMsg] = useState("");
|
|
|
|
|
|
+ // 生日范围:1900-01-01 ~ 今年12-31
|
|
|
+ const minDate = new CalendarDate(1900, 1, 1);
|
|
|
+ const maxDate = new CalendarDate(new Date().getFullYear(), 12, 31);
|
|
|
+ // 组件内部先声明
|
|
|
+ const router = useRouter();
|
|
|
const { showToast } = useCustomToast();
|
|
|
const addressForm = useForm<UserForm>({
|
|
|
mode: "onBlur",
|
|
|
@@ -110,6 +118,7 @@ const AccountEditPage = () => {
|
|
|
if (result.success) {
|
|
|
// 更新成功后的逻辑,提示、刷新表单等
|
|
|
showToast(result.message, "success");
|
|
|
+ router.push('/customer/account/');
|
|
|
}
|
|
|
},
|
|
|
onError: (err) => {
|
|
|
@@ -123,7 +132,22 @@ const AccountEditPage = () => {
|
|
|
// 日期选择方法
|
|
|
const handleDateChange = (dateValue: DateValue | null) => {
|
|
|
if (!dateValue) return;
|
|
|
+ if (!dateValue) {
|
|
|
+ setIsInvalid(false);
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const year = dateValue.year;
|
|
|
+ // 校验年份区间
|
|
|
+ if (year < 1900 || year > new Date().getFullYear()) {
|
|
|
+ setIsInvalid(true);
|
|
|
+ setErrorMsg("Please enter a valid birth year (1900 - current year)");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
+ setIsInvalid(false);
|
|
|
+ setErrorMsg("");
|
|
|
// 把 CalendarDate 转成 标准字符串:YYYY-MM-DD
|
|
|
const formattedDate = `${dateValue.year}-${String(dateValue.month).padStart(2, "0")}-${String(dateValue.day).padStart(2, "0")}`;
|
|
|
return formattedDate
|
|
|
@@ -256,13 +280,18 @@ const AccountEditPage = () => {
|
|
|
|
|
|
|
|
|
}}
|
|
|
+ minValue={minDate}
|
|
|
+ maxValue={maxDate}
|
|
|
+ isInvalid={isInvalid}
|
|
|
+ errorMessage={errorMsg}
|
|
|
radius="sm"
|
|
|
className="bg-white"
|
|
|
description={"This cannot be modified. Please fill in carefully."}
|
|
|
labelPlacement={"outside"}
|
|
|
- showMonthAndYearPickers={false}
|
|
|
+ showMonthAndYearPickers={true}
|
|
|
aria-label="date picker"
|
|
|
/>
|
|
|
+
|
|
|
)}
|
|
|
/>
|
|
|
{/* label={"Date of Birth"} */}
|