diff --git a/vtex/actions/address/createAddress.ts b/vtex/actions/address/createAddress.ts index 6d16f3588..f63917a19 100644 --- a/vtex/actions/address/createAddress.ts +++ b/vtex/actions/address/createAddress.ts @@ -3,53 +3,53 @@ import { AppContext } from "../../mod.ts"; import { parseCookie } from "../../utils/vtexId.ts"; interface Address { - name?: string; - addressName: string; - addressType?: string; - city?: string; - complement?: string; - country?: string; - geoCoordinates?: number[]; - neighborhood?: string; - number?: string; - postalCode?: string; - receiverName?: string; - reference?: string; - state?: string; - street?: string; + name?: string; + addressName: string; + addressType?: string; + city?: string; + complement?: string; + country?: string; + geoCoordinates?: number[]; + neighborhood?: string; + number?: string; + postalCode?: string; + receiverName?: string; + reference?: string; + state?: string; + street?: string; } interface AddressInput { - receiverName?: string; - complement?: string | null; - neighborhood?: string | null; - country?: string; - state?: string; - number?: string | null; - street?: string; - geoCoordinates?: number[]; - postalCode?: string; - city?: string; - reference?: string | null; - addressName: string; - addressType?: string; + receiverName?: string; + complement?: string | null; + neighborhood?: string | null; + country?: string; + state?: string; + number?: string | null; + street?: string; + geoCoordinates?: number[]; + postalCode?: string; + city?: string; + reference?: string | null; + addressName: string; + addressType?: string; } async function loader( - props: Address, - req: Request, - ctx: AppContext, + props: Address, + req: Request, + ctx: AppContext, ): Promise< - | PostalAddress & { - receiverName?: string | null; - complement?: string | null; - } - | null + | PostalAddress & { + receiverName?: string | null; + complement?: string | null; + } + | null > { - const { io } = ctx; - const { cookie } = parseCookie(req.headers, ctx.account); + const { io } = ctx; + const { cookie } = parseCookie(req.headers, ctx.account); - const mutation = ` + const mutation = ` mutation SaveAddress($address: AddressInput!) { saveAddress(address: $address) @context(provider: "vtex.store-graphql") { id @@ -57,35 +57,35 @@ async function loader( } }`; - try { - const { saveAddress: updatedAddress } = await io.query< - { saveAddress: Address }, - { address: AddressInput } - >( - { - query: mutation, - operationName: "SaveAddress", - variables: { - address: props, - }, - }, - { headers: { cookie } }, - ); + try { + const { saveAddress: updatedAddress } = await io.query< + { saveAddress: Address }, + { address: AddressInput } + >( + { + query: mutation, + operationName: "SaveAddress", + variables: { + address: props, + }, + }, + { headers: { cookie } }, + ); - return { - "@type": "PostalAddress", - addressCountry: updatedAddress?.country, - addressLocality: updatedAddress?.city, - addressRegion: updatedAddress?.state, - postalCode: updatedAddress?.postalCode, - streetAddress: updatedAddress?.street, - receiverName: updatedAddress?.receiverName, - complement: updatedAddress?.complement, - }; - } catch (error) { - console.error("Error saving address:", error); - return null; - } + return { + "@type": "PostalAddress", + addressCountry: updatedAddress?.country, + addressLocality: updatedAddress?.city, + addressRegion: updatedAddress?.state, + postalCode: updatedAddress?.postalCode, + streetAddress: updatedAddress?.street, + receiverName: updatedAddress?.receiverName, + complement: updatedAddress?.complement, + }; + } catch (error) { + console.error("Error saving address:", error); + return null; + } } export default loader; diff --git a/vtex/utils/types.ts b/vtex/utils/types.ts index c662603a4..6f32cc987 100644 --- a/vtex/utils/types.ts +++ b/vtex/utils/types.ts @@ -378,6 +378,7 @@ export interface ShippingData { export interface Address { addressType: string; + addressName: string; receiverName: null; addressId: string; isDisposable: boolean;