fix/331 no provider available (#337)
* fix: 🐛 error while reading updated provider * build: 👷 add changeset
This commit is contained in:
parent
d0af8bd420
commit
aa8a96a0ba
5 changed files with 18 additions and 13 deletions
5
.changeset/five-hounds-play.md
Normal file
5
.changeset/five-hounds-play.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"saleor-app-taxes": patch
|
||||
---
|
||||
|
||||
Fix "no provider available" error while reading an updated provider.
|
|
@ -145,7 +145,7 @@ export const AvataxConfigurationForm = () => {
|
|||
appBridge?.dispatch(
|
||||
actions.Notification({
|
||||
title: "Success",
|
||||
text: "Remove TaxJar instance",
|
||||
text: "Removed Avatax instance",
|
||||
status: "success",
|
||||
})
|
||||
);
|
||||
|
|
|
@ -4,7 +4,8 @@ import { z } from "zod";
|
|||
import { createLogger } from "../../lib/logger";
|
||||
import { createId } from "../../lib/utils";
|
||||
|
||||
const settingsSchema = z.array(z.record(z.any()));
|
||||
const settingSchema = z.record(z.any()).and(z.object({ id: z.string() }));
|
||||
const settingsSchema = z.array(settingSchema);
|
||||
|
||||
export class CrudSettingsConfigurator {
|
||||
private logger: pino.Logger;
|
||||
|
@ -59,8 +60,8 @@ export class CrudSettingsConfigurator {
|
|||
async create(data: any) {
|
||||
this.logger.debug(data, ".create called with:");
|
||||
|
||||
const getResponse = await this.readAll();
|
||||
const prevData = getResponse.data;
|
||||
const settings = await this.readAll();
|
||||
const prevData = settings.data;
|
||||
|
||||
const id = createId();
|
||||
const newData = [...prevData, { ...data, id }];
|
||||
|
@ -78,8 +79,8 @@ export class CrudSettingsConfigurator {
|
|||
async delete(id: string) {
|
||||
this.logger.debug(`.delete called with: ${id}`);
|
||||
|
||||
const getResponse = await this.readAll();
|
||||
const prevData = getResponse.data;
|
||||
const settings = await this.readAll();
|
||||
const prevData = settings.data;
|
||||
const nextData = prevData.filter((item) => item.id !== id);
|
||||
|
||||
await this.metadataManager.set({
|
||||
|
@ -91,11 +92,10 @@ export class CrudSettingsConfigurator {
|
|||
|
||||
async update(id: string, data: any) {
|
||||
this.logger.debug(data, `.update called with: ${id}`);
|
||||
const getResponse = await this.readAll();
|
||||
const prevData = getResponse.data;
|
||||
const nextData = prevData.map((item) => {
|
||||
const { data: settings } = await this.readAll();
|
||||
const nextData = settings.map((item) => {
|
||||
if (item.id === id) {
|
||||
return { id, data };
|
||||
return { id, ...data };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
|
|
|
@ -46,7 +46,7 @@ export class TaxJarConfigurationService {
|
|||
|
||||
async get(id: string): Promise<TaxJarInstanceConfig> {
|
||||
this.logger.debug(`.get called with id: ${id}`);
|
||||
const data = await this.crudSettingsConfigurator.read(id);
|
||||
const { data } = await this.crudSettingsConfigurator.read(id);
|
||||
this.logger.debug({ setting: data }, `Fetched setting from crudSettingsConfigurator`);
|
||||
|
||||
const validation = getSchema.safeParse(data);
|
||||
|
|
|
@ -63,7 +63,7 @@ export const TaxJarConfigurationForm = () => {
|
|||
|
||||
const { refetch: refetchProvidersConfigurationData } =
|
||||
trpcClient.providersConfiguration.getAll.useQuery();
|
||||
const { data: instance } = trpcClient.avataxConfiguration.get.useQuery(
|
||||
const { data: instance } = trpcClient.taxJarConfiguration.get.useQuery(
|
||||
{ id: instanceId ?? "" },
|
||||
{
|
||||
enabled: !!instanceId,
|
||||
|
@ -137,7 +137,7 @@ export const TaxJarConfigurationForm = () => {
|
|||
appBridge?.dispatch(
|
||||
actions.Notification({
|
||||
title: "Success",
|
||||
text: "Remove TaxJar instance",
|
||||
text: "Removed TaxJar instance",
|
||||
status: "success",
|
||||
})
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue