saleor-apps-redis_apl/apps/invoices/src/modules/app-configuration/app-config-container.ts
Lukasz Ostrowski 0219561dd9
Remove firstName and lastName from billing address of the company and form (#143)
* [Invoices] Remove firstName and lastName from billing address of the company and form

* Fix fixtures
2023-02-10 16:29:54 +01:00

37 lines
1 KiB
TypeScript

import { AppConfig, SellerShopConfig } from "./app-config";
const getDefaultEmptyAddress = (): SellerShopConfig["address"] => ({
city: "",
cityArea: "",
companyName: "",
country: "",
countryArea: "",
postalCode: "",
streetAddress1: "",
streetAddress2: "",
});
const getChannelAddress = (appConfig: AppConfig | null | undefined) => (channelSlug: string) => {
try {
return appConfig?.shopConfigPerChannel[channelSlug].address ?? null;
} catch (e) {
return null;
}
};
const setChannelAddress =
(appConfig: AppConfig | null | undefined) =>
(channelSlug: string) =>
(address: SellerShopConfig["address"]) => {
const appConfigNormalized = structuredClone(appConfig) ?? { shopConfigPerChannel: {} };
appConfigNormalized.shopConfigPerChannel[channelSlug] ??= { address: getDefaultEmptyAddress() };
appConfigNormalized.shopConfigPerChannel[channelSlug].address = address;
return appConfigNormalized;
};
export const AppConfigContainer = {
getChannelAddress,
setChannelAddress,
};