@@ -17,7 +17,7 @@ import type { CustomerAddressInput } from "@shopify/hydrogen/customer-account-ap
1717import {
1818 type ActionFunctionArgs ,
1919 type LoaderFunctionArgs ,
20- json ,
20+ data ,
2121} from "@shopify/remix-oxygen" ;
2222import type {
2323 CustomerFragment ,
@@ -56,7 +56,7 @@ export async function loader({ request, context }: LoaderFunctionArgs) {
5656 throw Error ( "Customer orders not found" ) ;
5757 }
5858
59- return json ( { customer : data . customer } ) ;
59+ return data ( { customer : data . customer } ) ;
6060}
6161
6262export async function action ( { request, context, params } : ActionFunctionArgs ) {
@@ -75,11 +75,9 @@ export async function action({ request, context, params }: ActionFunctionArgs) {
7575 // this will ensure redirecting to login never happen for mutatation
7676 const isLoggedIn = await customerAccount . isLoggedIn ( ) ;
7777 if ( ! isLoggedIn ) {
78- return json (
78+ return data (
7979 { error : { [ addressId ] : "Unauthorized" } } ,
80- {
81- status : 401 ,
82- } ,
80+ { status : 401 }
8381 ) ;
8482 }
8583
@@ -130,25 +128,21 @@ export async function action({ request, context, params }: ActionFunctionArgs) {
130128 throw new Error ( "Customer address create failed." ) ;
131129 }
132130
133- return json ( {
131+ return data ( {
134132 error : null ,
135133 createdAddress : data ?. customerAddressCreate ?. customerAddress ,
136134 defaultAddress,
137135 } ) ;
138136 } catch ( error : unknown ) {
139137 if ( error instanceof Error ) {
140- return json (
138+ return data (
141139 { error : { [ addressId ] : error . message } } ,
142- {
143- status : 400 ,
144- } ,
140+ { status : 400 }
145141 ) ;
146142 }
147- return json (
143+ return data (
148144 { error : { [ addressId ] : error } } ,
149- {
150- status : 400 ,
151- } ,
145+ { status : 400 }
152146 ) ;
153147 }
154148 }
@@ -182,25 +176,21 @@ export async function action({ request, context, params }: ActionFunctionArgs) {
182176
183177 // });
184178
185- return json ( {
179+ return data ( {
186180 error : null ,
187181 updatedAddress : address ,
188182 defaultAddress,
189183 } ) ;
190184 } catch ( error : unknown ) {
191185 if ( error instanceof Error ) {
192- return json (
186+ return data (
193187 { error : { [ addressId ] : error . message } } ,
194- {
195- status : 400 ,
196- } ,
188+ { status : 400 }
197189 ) ;
198190 }
199- return json (
191+ return data (
200192 { error : { [ addressId ] : error } } ,
201- {
202- status : 400 ,
203- } ,
193+ { status : 400 }
204194 ) ;
205195 }
206196 }
@@ -227,48 +217,38 @@ export async function action({ request, context, params }: ActionFunctionArgs) {
227217 throw new Error ( "Customer address delete failed." ) ;
228218 }
229219
230- return json ( { error : null , deletedAddress : addressId } ) ;
220+ return data ( { error : null , deletedAddress : addressId } ) ;
231221 } catch ( error : unknown ) {
232222 if ( error instanceof Error ) {
233- return json (
223+ return data (
234224 { error : { [ addressId ] : error . message } } ,
235- {
236- status : 400 ,
237- } ,
225+ { status : 400 }
238226 ) ;
239227 }
240- return json (
228+ return data (
241229 { error : { [ addressId ] : error } } ,
242- {
243- status : 400 ,
244- } ,
230+ { status : 400 }
245231 ) ;
246232 }
247233 }
248234
249235 default : {
250- return json (
236+ return data (
251237 { error : { [ addressId ] : "Method not allowed" } } ,
252- {
253- status : 405 ,
254- } ,
238+ { status : 405 }
255239 ) ;
256240 }
257241 }
258242 } catch ( error : unknown ) {
259243 if ( error instanceof Error ) {
260- return json (
244+ return data (
261245 { error : error . message } ,
262- {
263- status : 400 ,
264- } ,
246+ { status : 400 }
265247 ) ;
266248 }
267- return json (
249+ return data (
268250 { error } ,
269- {
270- status : 400 ,
271- } ,
251+ { status : 400 }
272252 ) ;
273253 }
274254}
0 commit comments