From 6e102964a18a4469e1e7c94ceb2c8506f574badf Mon Sep 17 00:00:00 2001 From: Jakub Majorek Date: Tue, 21 Sep 2021 15:30:41 +0200 Subject: [PATCH] Fetch shop data after user is authenticated (#1427) --- src/components/Shop/index.tsx | 44 ++++++++++++-------- src/components/Shop/query.ts | 2 +- src/components/Shop/types/ShopInfo.ts | 2 +- src/index.tsx | 8 ++-- src/siteSettings/mutations.ts | 4 +- src/siteSettings/types/ShopSettingsUpdate.ts | 1 + src/siteSettings/views/index.tsx | 4 +- 7 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/components/Shop/index.tsx b/src/components/Shop/index.tsx index a99c967d9..035598cd0 100644 --- a/src/components/Shop/index.tsx +++ b/src/components/Shop/index.tsx @@ -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,22 +13,31 @@ type ShopContext = ShopInfo_shop; export const ShopContext = React.createContext(undefined); -export const ShopProvider: React.FC = ({ children }) => ( - - {({ data }) => ( - <> - - - - - - - - {children} - - - )} - -); +export const ShopProvider: React.FC = ({ children }) => { + const { isAuthenticated } = useAuth(); + + return ( + + {({ data }) => ( + <> + + + + + + + + {children} + + + )} + + ); +}; + export const Shop = ShopContext.Consumer; export default Shop; diff --git a/src/components/Shop/query.ts b/src/components/Shop/query.ts index a2ec1a318..67555afc4 100644 --- a/src/components/Shop/query.ts +++ b/src/components/Shop/query.ts @@ -13,7 +13,6 @@ const shopInfo = gql` country code } - channelCurrencies defaultCountry { code country @@ -35,6 +34,7 @@ const shopInfo = gql` code name } + version } } `; diff --git a/src/components/Shop/types/ShopInfo.ts b/src/components/Shop/types/ShopInfo.ts index cb0274003..49dc6edd5 100644 --- a/src/components/Shop/types/ShopInfo.ts +++ b/src/components/Shop/types/ShopInfo.ts @@ -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 { diff --git a/src/index.tsx b/src/index.tsx index f304c7be4..d35e58b69 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -125,15 +125,15 @@ const App: React.FC = () => ( - - + + - - + + diff --git a/src/siteSettings/mutations.ts b/src/siteSettings/mutations.ts index eb6c46ca0..5b063532f 100644 --- a/src/siteSettings/mutations.ts +++ b/src/siteSettings/mutations.ts @@ -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 } diff --git a/src/siteSettings/types/ShopSettingsUpdate.ts b/src/siteSettings/types/ShopSettingsUpdate.ts index 9eb6834eb..7363e143a 100644 --- a/src/siteSettings/types/ShopSettingsUpdate.ts +++ b/src/siteSettings/types/ShopSettingsUpdate.ts @@ -138,4 +138,5 @@ export interface ShopSettingsUpdateVariables { shopDomainInput: SiteDomainInput; shopSettingsInput: ShopSettingsInput; addressInput?: AddressInput | null; + isCloudInstance: boolean; } diff --git a/src/siteSettings/views/index.tsx b/src/siteSettings/views/index.tsx index a09193829..a8fdc0bc3 100644 --- a/src/siteSettings/views/index.tsx +++ b/src/siteSettings/views/index.tsx @@ -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 = () => { }, shopSettingsInput: { description: data.description - } + }, + isCloudInstance: IS_CLOUD_INSTANCE } });