/* eslint-disable @typescript-eslint/no-explicit-any */ import React from "react"; import { Field, ErrorMessage, useFormikContext } from "formik"; import { updateCustomerBillingAddress } from "../../../../Api/CustomerApi"; import { toast } from "react-toastify"; interface Props { toggleSection: (section: string) => void; openSections: { [key: string]: boolean }; billingAddressDisabled: boolean; handleBillingAddressDisabled: () => void; values: any; } const BillingAddress: React.FC = ({ toggleSection, openSections, billingAddressDisabled, handleBillingAddressDisabled, values, }) => { const { setSubmitting } = useFormikContext(); const handleSave = async () => { try { setSubmitting(true); const payload = { billing_address: values.billing_address }; const response = await updateCustomerBillingAddress(payload); if (response?.status) { toast.success("Billing address updated successfully"); handleBillingAddressDisabled(); // disable again after save } else { toast.error(response?.message || "Failed to update billing address"); } } catch (error) { console.error("Billing address update failed:", error); toast.error("Something went wrong"); } finally { setSubmitting(false); } }; return (
toggleSection("billingAddress")} style={{ cursor: "pointer", display: "flex", alignItems: "center", justifyContent: "space-between", padding: "1rem", background: "#fff", borderBottom: openSections.billingAddress ? "none" : "1px solid #eee", }} >

Billing Address

{billingAddressDisabled ? ( { e.preventDefault(); if (openSections?.billingAddress) e.stopPropagation(); handleBillingAddressDisabled(); }} > Edit ) : ( )}
{openSections.billingAddress && (

Set your default billing address for invoice and settlement purposes.

{255 - (values?.billing_address?.length || 0)} characters remaining
)}
); }; export default BillingAddress;