Fetch shop data after user is authenticated (#1427)
This commit is contained in:
parent
ebe56da583
commit
6e102964a1
7 changed files with 39 additions and 26 deletions
|
@ -2,6 +2,7 @@ import appleTouchIcon from "@assets/favicons/apple-touch-icon.png";
|
|||
import favicon16 from "@assets/favicons/favicon-16x16.png";
|
||||
import favicon32 from "@assets/favicons/favicon-32x32.png";
|
||||
import safariPinnedTab from "@assets/favicons/safari-pinned-tab.svg";
|
||||
import { useAuth } from "@saleor/auth/AuthProvider";
|
||||
import React from "react";
|
||||
import Helmet from "react-helmet";
|
||||
|
||||
|
@ -12,12 +13,19 @@ type ShopContext = ShopInfo_shop;
|
|||
|
||||
export const ShopContext = React.createContext<ShopContext>(undefined);
|
||||
|
||||
export const ShopProvider: React.FC = ({ children }) => (
|
||||
<TypedShopInfoQuery>
|
||||
export const ShopProvider: React.FC = ({ children }) => {
|
||||
const { isAuthenticated } = useAuth();
|
||||
|
||||
return (
|
||||
<TypedShopInfoQuery skip={!isAuthenticated}>
|
||||
{({ data }) => (
|
||||
<>
|
||||
<Helmet>
|
||||
<link rel="apple-touch-icon" sizes="180x180" href={appleTouchIcon} />
|
||||
<link
|
||||
rel="apple-touch-icon"
|
||||
sizes="180x180"
|
||||
href={appleTouchIcon}
|
||||
/>
|
||||
<link rel="icon" type="image/png" sizes="32x32" href={favicon32} />
|
||||
<link rel="icon" type="image/png" sizes="16x16" href={favicon16} />
|
||||
<link rel="mask-icon" href={safariPinnedTab} />
|
||||
|
@ -28,6 +36,8 @@ export const ShopProvider: React.FC = ({ children }) => (
|
|||
</>
|
||||
)}
|
||||
</TypedShopInfoQuery>
|
||||
);
|
||||
);
|
||||
};
|
||||
|
||||
export const Shop = ShopContext.Consumer;
|
||||
export default Shop;
|
||||
|
|
|
@ -13,7 +13,6 @@ const shopInfo = gql`
|
|||
country
|
||||
code
|
||||
}
|
||||
channelCurrencies
|
||||
defaultCountry {
|
||||
code
|
||||
country
|
||||
|
@ -35,6 +34,7 @@ const shopInfo = gql`
|
|||
code
|
||||
name
|
||||
}
|
||||
version
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
|
|
@ -42,7 +42,6 @@ export interface ShopInfo_shop_permissions {
|
|||
export interface ShopInfo_shop {
|
||||
__typename: "Shop";
|
||||
countries: ShopInfo_shop_countries[];
|
||||
channelCurrencies: string[];
|
||||
defaultCountry: ShopInfo_shop_defaultCountry | null;
|
||||
defaultWeightUnit: WeightUnitsEnum | null;
|
||||
displayGrossPrices: boolean;
|
||||
|
@ -52,6 +51,7 @@ export interface ShopInfo_shop {
|
|||
name: string;
|
||||
trackInventoryByDefault: boolean | null;
|
||||
permissions: (ShopInfo_shop_permissions | null)[];
|
||||
version: string;
|
||||
}
|
||||
|
||||
export interface ShopInfo {
|
||||
|
|
|
@ -125,15 +125,15 @@ const App: React.FC = () => (
|
|||
<ServiceWorker />
|
||||
<BackgroundTasksProvider>
|
||||
<AppStateProvider>
|
||||
<ShopProvider>
|
||||
<AuthProvider>
|
||||
<ShopProvider>
|
||||
<AppChannelProvider>
|
||||
<ExternalAppProvider>
|
||||
<Routes />
|
||||
</ExternalAppProvider>
|
||||
</AppChannelProvider>
|
||||
</AuthProvider>
|
||||
</ShopProvider>
|
||||
</AuthProvider>
|
||||
</AppStateProvider>
|
||||
</BackgroundTasksProvider>
|
||||
</MessageManagerProvider>
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { IS_CLOUD_INSTANCE } from "@saleor/config";
|
||||
import { fragmentAddress } from "@saleor/fragments/address";
|
||||
import { shopErrorFragment } from "@saleor/fragments/errors";
|
||||
import { shopFragment } from "@saleor/fragments/shop";
|
||||
|
@ -18,6 +17,7 @@ const shopSettingsUpdate = gql`
|
|||
$shopDomainInput: SiteDomainInput!
|
||||
$shopSettingsInput: ShopSettingsInput!
|
||||
$addressInput: AddressInput
|
||||
$isCloudInstance: Boolean!
|
||||
) {
|
||||
shopSettingsUpdate(input: $shopSettingsInput) {
|
||||
errors {
|
||||
|
@ -27,7 +27,7 @@ const shopSettingsUpdate = gql`
|
|||
...ShopFragment
|
||||
}
|
||||
}
|
||||
shopDomainUpdate(input: $shopDomainInput) @skip(if: ${IS_CLOUD_INSTANCE}) {
|
||||
shopDomainUpdate(input: $shopDomainInput) @skip(if: $isCloudInstance) {
|
||||
errors {
|
||||
...ShopErrorFragment
|
||||
}
|
||||
|
|
|
@ -138,4 +138,5 @@ export interface ShopSettingsUpdateVariables {
|
|||
shopDomainInput: SiteDomainInput;
|
||||
shopSettingsInput: ShopSettingsInput;
|
||||
addressInput?: AddressInput | null;
|
||||
isCloudInstance: boolean;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { WindowTitle } from "@saleor/components/WindowTitle";
|
||||
import { IS_CLOUD_INSTANCE } from "@saleor/config";
|
||||
import useNavigator from "@saleor/hooks/useNavigator";
|
||||
import useNotifier from "@saleor/hooks/useNotifier";
|
||||
import { commonMessages, sectionNames } from "@saleor/intl";
|
||||
|
@ -80,7 +81,8 @@ export const SiteSettings: React.FC<SiteSettingsProps> = () => {
|
|||
},
|
||||
shopSettingsInput: {
|
||||
description: data.description
|
||||
}
|
||||
},
|
||||
isCloudInstance: IS_CLOUD_INSTANCE
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue