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(
|
appBridge?.dispatch(
|
||||||
actions.Notification({
|
actions.Notification({
|
||||||
title: "Success",
|
title: "Success",
|
||||||
text: "Remove TaxJar instance",
|
text: "Removed Avatax instance",
|
||||||
status: "success",
|
status: "success",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,7 +4,8 @@ import { z } from "zod";
|
||||||
import { createLogger } from "../../lib/logger";
|
import { createLogger } from "../../lib/logger";
|
||||||
import { createId } from "../../lib/utils";
|
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 {
|
export class CrudSettingsConfigurator {
|
||||||
private logger: pino.Logger;
|
private logger: pino.Logger;
|
||||||
|
@ -59,8 +60,8 @@ export class CrudSettingsConfigurator {
|
||||||
async create(data: any) {
|
async create(data: any) {
|
||||||
this.logger.debug(data, ".create called with:");
|
this.logger.debug(data, ".create called with:");
|
||||||
|
|
||||||
const getResponse = await this.readAll();
|
const settings = await this.readAll();
|
||||||
const prevData = getResponse.data;
|
const prevData = settings.data;
|
||||||
|
|
||||||
const id = createId();
|
const id = createId();
|
||||||
const newData = [...prevData, { ...data, id }];
|
const newData = [...prevData, { ...data, id }];
|
||||||
|
@ -78,8 +79,8 @@ export class CrudSettingsConfigurator {
|
||||||
async delete(id: string) {
|
async delete(id: string) {
|
||||||
this.logger.debug(`.delete called with: ${id}`);
|
this.logger.debug(`.delete called with: ${id}`);
|
||||||
|
|
||||||
const getResponse = await this.readAll();
|
const settings = await this.readAll();
|
||||||
const prevData = getResponse.data;
|
const prevData = settings.data;
|
||||||
const nextData = prevData.filter((item) => item.id !== id);
|
const nextData = prevData.filter((item) => item.id !== id);
|
||||||
|
|
||||||
await this.metadataManager.set({
|
await this.metadataManager.set({
|
||||||
|
@ -91,11 +92,10 @@ export class CrudSettingsConfigurator {
|
||||||
|
|
||||||
async update(id: string, data: any) {
|
async update(id: string, data: any) {
|
||||||
this.logger.debug(data, `.update called with: ${id}`);
|
this.logger.debug(data, `.update called with: ${id}`);
|
||||||
const getResponse = await this.readAll();
|
const { data: settings } = await this.readAll();
|
||||||
const prevData = getResponse.data;
|
const nextData = settings.map((item) => {
|
||||||
const nextData = prevData.map((item) => {
|
|
||||||
if (item.id === id) {
|
if (item.id === id) {
|
||||||
return { id, data };
|
return { id, ...data };
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
|
|
|
@ -46,7 +46,7 @@ export class TaxJarConfigurationService {
|
||||||
|
|
||||||
async get(id: string): Promise<TaxJarInstanceConfig> {
|
async get(id: string): Promise<TaxJarInstanceConfig> {
|
||||||
this.logger.debug(`.get called with id: ${id}`);
|
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`);
|
this.logger.debug({ setting: data }, `Fetched setting from crudSettingsConfigurator`);
|
||||||
|
|
||||||
const validation = getSchema.safeParse(data);
|
const validation = getSchema.safeParse(data);
|
||||||
|
|
|
@ -63,7 +63,7 @@ export const TaxJarConfigurationForm = () => {
|
||||||
|
|
||||||
const { refetch: refetchProvidersConfigurationData } =
|
const { refetch: refetchProvidersConfigurationData } =
|
||||||
trpcClient.providersConfiguration.getAll.useQuery();
|
trpcClient.providersConfiguration.getAll.useQuery();
|
||||||
const { data: instance } = trpcClient.avataxConfiguration.get.useQuery(
|
const { data: instance } = trpcClient.taxJarConfiguration.get.useQuery(
|
||||||
{ id: instanceId ?? "" },
|
{ id: instanceId ?? "" },
|
||||||
{
|
{
|
||||||
enabled: !!instanceId,
|
enabled: !!instanceId,
|
||||||
|
@ -137,7 +137,7 @@ export const TaxJarConfigurationForm = () => {
|
||||||
appBridge?.dispatch(
|
appBridge?.dispatch(
|
||||||
actions.Notification({
|
actions.Notification({
|
||||||
title: "Success",
|
title: "Success",
|
||||||
text: "Remove TaxJar instance",
|
text: "Removed TaxJar instance",
|
||||||
status: "success",
|
status: "success",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue