Sfoglia il codice sorgente

地址编辑页报错调整

zhangzf 1 settimana fa
parent
commit
e6bcb81f10
1 ha cambiato i file con 36 aggiunte e 37 eliminazioni
  1. 36 37
      src/app/(public)/customer/address/eidt/[id]/page.tsx

+ 36 - 37
src/app/(public)/customer/address/eidt/[id]/page.tsx

@@ -40,39 +40,39 @@ const CustomerAddressEditPage = () => {
     }));
   }, [COUNTRIES]);
   const [actionType, setActionType] = useState<"save" | "delete">("save");
-    // 修改地址到接口
-    const UpdataAddress = async (formData: AddressFormData) => {
-      const res = await clientFetch(`/api/customer/token/address?id=${id}`, {
-        method: "PUT",
-        headers: {
-          "Content-Type": "application/json",
-        },
-        body: JSON.stringify(formData),
-      });
-      const json = await res;
-      console.log("提交成功,返回结果:", json);
-      if(json?.data?.success){
-          window.location.reload();
-      }else{
-        alert("error");
-      }
-      return json;
-    };
+  // 修改地址到接口
+  const UpdataAddress = async (formData: AddressFormData) => {
+    const res = await clientFetch(`/api/customer/token/address?id=${id}`, {
+      method: "PUT",
+      headers: {
+        "Content-Type": "application/json",
+      },
+      body: JSON.stringify(formData),
+    });
+    const json = await res;
+    console.log("提交成功,返回结果:", json);
+    if (json?.data?.success) {
+      window.location.reload();
+    } else {
+      alert("error");
+    }
+    return json;
+  };
   // 删除地址接口
-  const  DeleteAddress =async ()=>{
-     const res = await clientFetch(`/api/customer/token/address?id=${id}`, {
-        method: "DELETE",
-        headers: {
-          "Content-Type": "application/json",
-        }
-      });
-      const json = await res;
-      console.log("删除成功,返回结果:", json);
-  }
+  const DeleteAddress = async () => {
+    const res = await clientFetch(`/api/customer/token/address?id=${id}`, {
+      method: "DELETE",
+      headers: {
+        "Content-Type": "application/json",
+      },
+    });
+    const json = await res;
+    console.log("删除成功,返回结果:", json);
+  };
   // 表单提交
   const addressFormOnSubmit = async (formData: AddressFormData) => {
-    console.log("actionType",actionType);
-    
+    console.log("actionType", actionType);
+
     if (actionType === "save") {
       UpdataAddress(formData);
     } else {
@@ -121,7 +121,7 @@ const CustomerAddressEditPage = () => {
   }, [id, reset]);
   return (
     <div className="w-full h-full">
-      <div  className="bg-[#fff] pr-2.5 pl-2.5 w-full text-center text-base h-11 leading-11 font-semibold relative text-[#0b0b0b]">
+      <div className="bg-[#fff] pr-2.5 pl-2.5 w-full text-center text-base h-11 leading-11 font-semibold relative text-[#0b0b0b]">
         <Link
           href={"/customer/address"}
           // onClick={() => window.history.back()}
@@ -195,10 +195,9 @@ const CustomerAddressEditPage = () => {
                   return (
                     <Select
                       placeholder="Country/Region"
-                      defaultValue={field.value}
-                      onChange={field.onChange}
-                      onBlur={field.onBlur}
-                      name={field.name}
+                      {...register("country", {
+                        required: "Country/Region field is required",
+                      })}
                       options={countriesOptions}
                       error={errors.country?.message as string}
                     />
@@ -277,7 +276,7 @@ const CustomerAddressEditPage = () => {
                 type="button"
                 onClick={() => {
                   setActionType("save");
-                  document.getElementById("realSubmit")?.click(); 
+                  document.getElementById("realSubmit")?.click();
                 }}
               >
                 Save Address
@@ -288,7 +287,7 @@ const CustomerAddressEditPage = () => {
                 onClick={() => {
                   if (!confirm("确定删除该地址?")) return;
                   setActionType("delete");
-                  document.getElementById("realSubmit")?.click(); 
+                  document.getElementById("realSubmit")?.click();
                 }}
               >
                 Delete Address