Fix strict null check in SiteSettings module (#2851)
* Fix strict null check in SiteSettings * Improve urls
This commit is contained in:
parent
769268a9a7
commit
ef35e5149b
5 changed files with 18 additions and 16 deletions
|
@ -45,7 +45,7 @@ export interface SiteSettingsPageFormData
|
||||||
export interface SiteSettingsPageProps {
|
export interface SiteSettingsPageProps {
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
errors: ShopErrorFragment[];
|
errors: ShopErrorFragment[];
|
||||||
shop: SiteSettingsQuery["shop"];
|
shop?: SiteSettingsQuery["shop"];
|
||||||
saveButtonBarState: ConfirmButtonTransitionState;
|
saveButtonBarState: ConfirmButtonTransitionState;
|
||||||
onSubmit: (data: SiteSettingsPageFormData) => SubmitPromise;
|
onSubmit: (data: SiteSettingsPageFormData) => SubmitPromise;
|
||||||
}
|
}
|
||||||
|
@ -107,10 +107,11 @@ const SiteSettingsPage: React.FC<SiteSettingsPageProps> = props => {
|
||||||
const initialForm: SiteSettingsPageFormData = {
|
const initialForm: SiteSettingsPageFormData = {
|
||||||
...initialFormAddress,
|
...initialFormAddress,
|
||||||
description: shop?.description || "",
|
description: shop?.description || "",
|
||||||
reserveStockDurationAnonymousUser: shop?.reserveStockDurationAnonymousUser,
|
reserveStockDurationAnonymousUser:
|
||||||
|
shop?.reserveStockDurationAnonymousUser ?? 0,
|
||||||
reserveStockDurationAuthenticatedUser:
|
reserveStockDurationAuthenticatedUser:
|
||||||
shop?.reserveStockDurationAuthenticatedUser,
|
shop?.reserveStockDurationAuthenticatedUser ?? 0,
|
||||||
limitQuantityPerCheckout: shop?.limitQuantityPerCheckout,
|
limitQuantityPerCheckout: shop?.limitQuantityPerCheckout ?? 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -179,7 +180,7 @@ const SiteSettingsPage: React.FC<SiteSettingsPageProps> = props => {
|
||||||
</Grid>
|
</Grid>
|
||||||
<Savebar
|
<Savebar
|
||||||
state={saveButtonBarState}
|
state={saveButtonBarState}
|
||||||
disabled={isSaveDisabled}
|
disabled={!!isSaveDisabled}
|
||||||
onCancel={() => navigate(configurationMenuUrl)}
|
onCancel={() => navigate(configurationMenuUrl)}
|
||||||
onSubmit={submit}
|
onSubmit={submit}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -12,14 +12,14 @@ export const shop: SiteSettingsQuery["shop"] = {
|
||||||
code: "UA",
|
code: "UA",
|
||||||
country: "United Arab Emirates",
|
country: "United Arab Emirates",
|
||||||
},
|
},
|
||||||
countryArea: null,
|
countryArea: "",
|
||||||
firstName: null,
|
firstName: "",
|
||||||
id: "1",
|
id: "1",
|
||||||
lastName: null,
|
lastName: "",
|
||||||
phone: "+41 876-373-9137",
|
phone: "+41 876-373-9137",
|
||||||
postalCode: "89880-6342",
|
postalCode: "89880-6342",
|
||||||
streetAddress1: "01419 Bernhard Plain",
|
streetAddress1: "01419 Bernhard Plain",
|
||||||
streetAddress2: null,
|
streetAddress2: "s",
|
||||||
},
|
},
|
||||||
countries: [
|
countries: [
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,8 +6,7 @@ import { siteSettingsPath, SiteSettingsUrlQueryParams } from "./urls";
|
||||||
import SiteSettingsComponent from "./views/";
|
import SiteSettingsComponent from "./views/";
|
||||||
|
|
||||||
const SiteSettings: React.FC<RouteComponentProps<{}>> = ({ location }) => {
|
const SiteSettings: React.FC<RouteComponentProps<{}>> = ({ location }) => {
|
||||||
const qs = parseQs(location.search.substr(1));
|
const params: SiteSettingsUrlQueryParams = parseQs(location.search.slice(1));
|
||||||
const params: SiteSettingsUrlQueryParams = qs;
|
|
||||||
|
|
||||||
return <SiteSettingsComponent params={params} />;
|
return <SiteSettingsComponent params={params} />;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,4 +8,4 @@ export const siteSettingsPath = siteSettingsSection;
|
||||||
export type SiteSettingsUrlDialog = "add-key";
|
export type SiteSettingsUrlDialog = "add-key";
|
||||||
export type SiteSettingsUrlQueryParams = Dialog<SiteSettingsUrlDialog>;
|
export type SiteSettingsUrlQueryParams = Dialog<SiteSettingsUrlDialog>;
|
||||||
export const siteSettingsUrl = (params?: SiteSettingsUrlQueryParams) =>
|
export const siteSettingsUrl = (params?: SiteSettingsUrlQueryParams) =>
|
||||||
siteSettingsPath + "?" + stringifyQs(params);
|
`${siteSettingsPath}?${stringifyQs(params)}`;
|
||||||
|
|
|
@ -34,8 +34,10 @@ export const SiteSettings: React.FC<SiteSettingsProps> = () => {
|
||||||
] = useShopSettingsUpdateMutation({
|
] = useShopSettingsUpdateMutation({
|
||||||
onCompleted: data => {
|
onCompleted: data => {
|
||||||
if (
|
if (
|
||||||
[...data.shopAddressUpdate.errors, ...data.shopSettingsUpdate.errors]
|
[
|
||||||
.length === 0
|
...(data?.shopAddressUpdate?.errors || []),
|
||||||
|
...(data?.shopSettingsUpdate?.errors || []),
|
||||||
|
].length === 0
|
||||||
) {
|
) {
|
||||||
notify({
|
notify({
|
||||||
status: "success",
|
status: "success",
|
||||||
|
@ -46,8 +48,8 @@ export const SiteSettings: React.FC<SiteSettingsProps> = () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const errors = [
|
const errors = [
|
||||||
...(updateShopSettingsOpts.data?.shopSettingsUpdate.errors || []),
|
...(updateShopSettingsOpts.data?.shopSettingsUpdate?.errors || []),
|
||||||
...(updateShopSettingsOpts.data?.shopAddressUpdate.errors || []),
|
...(updateShopSettingsOpts.data?.shopAddressUpdate?.errors || []),
|
||||||
];
|
];
|
||||||
const loading = siteSettings.loading || updateShopSettingsOpts.loading;
|
const loading = siteSettings.loading || updateShopSettingsOpts.loading;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue