Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: standardize mutations by returning drilled response #814

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/great-eagles-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

standardize mutations by returning drilled response
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ export const submitChangePasswordForm = async (_previousState: unknown, formData
customerEntityId: Number(parsedData.customerId),
});

if (response.customer.resetPassword.errors.length === 0) {
if (response.errors.length === 0) {
return { status: 'success', message: '' };
}

return {
status: 'error',
message: response.customer.resetPassword.errors.map((error) => error.message).join('\n'),
message: response.errors.map((error) => error.message).join('\n'),
};
} catch (error: unknown) {
if (error instanceof ZodError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export const submitResetPasswordForm = async ({
reCaptchaToken,
});

if (response.customer.requestResetPassword.errors.length === 0) {
if (response.errors.length === 0) {
return { status: 'success', data: parsedData };
}

return {
status: 'error',
error: response.customer.requestResetPassword.errors.map((error) => error.message).join('\n'),
error: response.errors.map((error) => error.message).join('\n'),
};
} catch (error: unknown) {
if (error instanceof Error || error instanceof z.ZodError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export const submitContactForm = async ({
reCaptchaToken,
});

if (response.submitContactUs.errors.length === 0) {
if (response.errors.length === 0) {
return { status: 'success', data: parsedData };
}

return {
status: 'failed',
error: response.submitContactUs.errors.map((error) => error.message).join('\n'),
error: response.errors.map((error) => error.message).join('\n'),
};
} catch (e: unknown) {
if (e instanceof Error || e instanceof z.ZodError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,5 @@ export const addCheckoutShippingConsignments = async ({
fetchOptions: { cache: 'no-store' },
});

const checkout = response.data.checkout.addCheckoutShippingConsignments?.checkout;

if (checkout) {
return checkout;
}

throw new Error('Something went wrong adding shipping info.');
return response.data.checkout.addCheckoutShippingConsignments?.checkout;
};
2 changes: 1 addition & 1 deletion apps/core/client/mutations/delete-customer-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ export const deleteCustomerAddress = async (addressId: AddressId, reCaptchaToken
},
});

return response.data;
return response.data.customer.deleteCustomerAddress;
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,5 @@ export const selectCheckoutShippingOption = async ({
fetchOptions: { cache: 'no-store' },
});

const shippingCosts = response.data.checkout.selectCheckoutShippingOption?.checkout;

if (shippingCosts) {
return shippingCosts;
}

return null;
return response.data.checkout.selectCheckoutShippingOption?.checkout;
};
2 changes: 1 addition & 1 deletion apps/core/client/mutations/submit-change-password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ export const submitChangePassword = async ({
variables,
});

return response.data;
return response.data.customer.resetPassword;
};
2 changes: 1 addition & 1 deletion apps/core/client/mutations/submit-contact-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ export const submitContactForm = async ({
variables,
});

return response.data;
return response.data.submitContactUs;
};
2 changes: 1 addition & 1 deletion apps/core/client/mutations/submit-reset-password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ export const submitResetPassword = async ({ email, path, reCaptchaToken }: Submi
variables,
});

return response.data;
return response.data.customer.requestResetPassword;
};
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,5 @@ export const updateCheckoutShippingConsignment = async ({
fetchOptions: { cache: 'no-store' },
});

const checkout = response.data.checkout.updateCheckoutShippingConsignment?.checkout;

if (checkout) {
return checkout;
}

return null;
return response.data.checkout.updateCheckoutShippingConsignment?.checkout;
};
Loading