"use client" import React, { useEffect, useActionState } from "react"; import Input from "@modules/common/components/input" import AccountInfo from "../account-info" import { HttpTypes } from "@medusajs/types" import { updateCustomer } from "@lib/data/customer" type MyInformationProps = { customer: HttpTypes.StoreCustomer } const ProfileName: React.FC = ({ customer }) => { const [successState, setSuccessState] = React.useState(false) const updateCustomerName = async ( _currentState: Record, formData: FormData ) => { const customer = { first_name: formData.get("first_name") as string, last_name: formData.get("last_name") as string, } try { await updateCustomer(customer) return { success: true, error: null } } catch (error: any) { return { success: false, error: error.toString() } } } const [state, formAction] = useActionState(updateCustomerName, { error: false, success: false, }) const clearState = () => { setSuccessState(false) } useEffect(() => { setSuccessState(state.success) }, [state]) return (
) } export default ProfileName