fix: tax not calculating (#412)

* fix: 🐛 disable autocomplete on country-select

* fix: 🐛 invalid response format bug

* build: 👷 add changeset

* docs: 💡 add comment with improvement idea
This commit is contained in:
Adrian Pilarczyk 2023-04-23 13:18:20 +02:00 committed by GitHub
parent 8424989dad
commit 56b27b2e21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
"saleor-app-taxes": patch
---
Fix invalid response format in `order-calculate-taxes`.

View file

@ -2,6 +2,11 @@ import { NextApiResponse } from "next";
import { Logger } from "pino"; import { Logger } from "pino";
import { createLogger } from "../../lib/logger"; import { createLogger } from "../../lib/logger";
/*
* idea: distinguish between async and sync webhooks
* when sync webhooks, require passing the event and enforce the required response format using ctx.buildResponse
* when async webhooks, dont require anything
*/
export class WebhookResponse { export class WebhookResponse {
private logger: Logger; private logger: Logger;
constructor(private res: NextApiResponse) { constructor(private res: NextApiResponse) {
@ -20,9 +25,6 @@ export class WebhookResponse {
success(data?: any) { success(data?: any) {
this.logger.debug({ data }, "success called with:"); this.logger.debug({ data }, "success called with:");
return this.res.status(200).json({ return this.res.send(data);
status: 200,
data,
});
} }
} }

View file

@ -37,7 +37,17 @@ export const CountrySelect = React.forwardRef((p: CountrySelectProps, ref) => {
}) ?? null }) ?? null
} }
getOptionLabel={(option) => option.label} getOptionLabel={(option) => option.label}
renderInput={(params) => <TextField {...params} inputRef={ref} placeholder={"Country"} />} renderInput={(params) => (
<TextField
{...params}
inputRef={ref}
placeholder={"Country"}
inputProps={{
...params.inputProps,
autoComplete: "new-password", // disable autocomplete and autofill
}}
/>
)}
/> />
); );
}); });

View file

@ -66,7 +66,7 @@ export default orderCalculateTaxesSyncWebhook.createHandler(async (req, res, ctx
const calculatedTaxes = await taxProvider.calculateTaxes(payload.taxBase); const calculatedTaxes = await taxProvider.calculateTaxes(payload.taxBase);
logger.info({ calculatedTaxes }, "Taxes calculated"); logger.info({ calculatedTaxes }, "Taxes calculated");
return webhookResponse.success(calculatedTaxes); return webhookResponse.success(ctx.buildResponse(calculatedTaxes));
} catch (error) { } catch (error) {
return webhookResponse.failureRetry("Error while calculating taxes"); return webhookResponse.failureRetry("Error while calculating taxes");
} }