@@ -170290,36 +169546,6 @@ exports[`Storyshots Views / Products / Product edit when data is fully loaded 1`
-
- Channel:
-
-
-
- Channel1
-
-
-
@@ -173052,36 +172278,6 @@ exports[`Storyshots Views / Products / Product edit when product has no images 1
-
- Channel:
-
-
-
- Channel1
-
-
-
@@ -176720,36 +175916,6 @@ exports[`Storyshots Views / Products / Product edit with channels 1`] = `
-
- Channel:
-
-
-
- Channel1
-
-
-
@@ -195187,33 +194353,7 @@ exports[`Storyshots Views / Shipping / Shipping zones list default 1`] = `
>
+ />
+ />
+ />
+ />
= {
productListToolbar: null,
products: category.products.edges.map(edge => edge.node),
saveButtonBarState: "default",
+ selectedChannelId: "123",
subcategories: category.children.edges.map(edge => edge.node),
subcategoryListToolbar: null,
...listActionsProps
diff --git a/src/storybook/stories/collections/CollectionDetailsPage.tsx b/src/storybook/stories/collections/CollectionDetailsPage.tsx
index 8ff3b4240..e4da1623d 100644
--- a/src/storybook/stories/collections/CollectionDetailsPage.tsx
+++ b/src/storybook/stories/collections/CollectionDetailsPage.tsx
@@ -38,7 +38,7 @@ const props: Omit
= {
onSubmit: () => undefined,
openChannelsModal: () => undefined,
saveButtonBarState: "default",
- selectedChannel: "123"
+ selectedChannelId: "123"
};
storiesOf("Views / Collections / Collection details", module)
diff --git a/src/storybook/stories/collections/CollectionListPage.tsx b/src/storybook/stories/collections/CollectionListPage.tsx
index 0f4ed1bc0..13a798c1c 100644
--- a/src/storybook/stories/collections/CollectionListPage.tsx
+++ b/src/storybook/stories/collections/CollectionListPage.tsx
@@ -27,7 +27,7 @@ const props: CollectionListPageProps = {
},
...tabPageProps,
collections,
- selectedChannel: "123"
+ selectedChannelId: "123"
};
storiesOf("Views / Collections / Collection list", module)
diff --git a/src/storybook/stories/discounts/SaleDetailsPage.tsx b/src/storybook/stories/discounts/SaleDetailsPage.tsx
index 31ca59b46..58c2b3d6f 100644
--- a/src/storybook/stories/discounts/SaleDetailsPage.tsx
+++ b/src/storybook/stories/discounts/SaleDetailsPage.tsx
@@ -47,7 +47,7 @@ const props: SaleDetailsPageProps = {
productListToolbar: null,
sale,
saveButtonBarState: "default",
- selectedChannel: "123",
+ selectedChannelId: "123",
...listActionsProps
};
diff --git a/src/storybook/stories/discounts/SaleListPage.tsx b/src/storybook/stories/discounts/SaleListPage.tsx
index e37af1c92..27be6c9f9 100644
--- a/src/storybook/stories/discounts/SaleListPage.tsx
+++ b/src/storybook/stories/discounts/SaleListPage.tsx
@@ -42,9 +42,8 @@ const props: SaleListPageProps = {
value: [DiscountStatusEnum.ACTIVE]
}
},
- onSettingsOpen: () => undefined,
sales: saleList,
- selectedChannel: "123",
+ selectedChannelId: "123",
sort: {
...sortPageProps.sort,
sort: SaleListUrlSortField.name
@@ -60,7 +59,6 @@ storiesOf("Views / Discounts / Sale list", module)
({ ...sale, channelListings: [] }))}
- selectedChannel=""
- onSettingsOpen={undefined}
+ selectedChannelId=""
/>
));
diff --git a/src/storybook/stories/discounts/VoucherDetailsPage.tsx b/src/storybook/stories/discounts/VoucherDetailsPage.tsx
index 7f701bccd..03f8774cf 100644
--- a/src/storybook/stories/discounts/VoucherDetailsPage.tsx
+++ b/src/storybook/stories/discounts/VoucherDetailsPage.tsx
@@ -47,7 +47,7 @@ const props: VoucherDetailsPageProps = {
openChannelsModal: () => undefined,
productListToolbar: null,
saveButtonBarState: "default",
- selectedChannel: "123",
+ selectedChannelId: "123",
voucher: voucherDetails
};
diff --git a/src/storybook/stories/discounts/VoucherListPage.tsx b/src/storybook/stories/discounts/VoucherListPage.tsx
index 63b3b8849..49079996e 100644
--- a/src/storybook/stories/discounts/VoucherListPage.tsx
+++ b/src/storybook/stories/discounts/VoucherListPage.tsx
@@ -51,8 +51,7 @@ const props: VoucherListPageProps = {
}
}
},
- onSettingsOpen: () => undefined,
- selectedChannel: "123",
+ selectedChannelId: "123",
sort: {
...sortPageProps.sort,
sort: VoucherListUrlSortField.code
@@ -68,8 +67,7 @@ storiesOf("Views / Discounts / Voucher list", module)
.add("no channels", () => (
({
...voucher,
channelListings: []
diff --git a/src/storybook/stories/home/HomePage.tsx b/src/storybook/stories/home/HomePage.tsx
index d76a39546..44b528c0c 100644
--- a/src/storybook/stories/home/HomePage.tsx
+++ b/src/storybook/stories/home/HomePage.tsx
@@ -1,6 +1,5 @@
import placeholderImage from "@assets/images/placeholder60x60.png";
import { Omit } from "@material-ui/core";
-import { channelsList } from "@saleor/channels/fixtures";
import { adminUserPermissions } from "@saleor/fixtures";
import { PermissionEnum } from "@saleor/types/globalTypes";
import { storiesOf } from "@storybook/react";
@@ -11,16 +10,9 @@ import { shop as shopFixture } from "../../../home/fixtures";
import Decorator from "../../Decorator";
const shop = shopFixture(placeholderImage);
-const channelChoices = channelsList.map(channel => ({
- label: channel.name,
- value: channel.slug
-}));
const homePageProps: Omit = {
activities: shop.activities.edges.map(edge => edge.node),
- channelChoices,
- channelValue: channelChoices[0].value,
- onChannelChange: () => undefined,
onOrdersToCaptureClick: () => undefined,
onOrdersToFulfillClick: () => undefined,
onProductClick: () => undefined,
diff --git a/src/storybook/stories/orders/OrderDraftListPage.tsx b/src/storybook/stories/orders/OrderDraftListPage.tsx
index f44e463ca..ad5531ccc 100644
--- a/src/storybook/stories/orders/OrderDraftListPage.tsx
+++ b/src/storybook/stories/orders/OrderDraftListPage.tsx
@@ -37,7 +37,6 @@ const props: OrderDraftListPageProps = {
}
},
onAdd: () => undefined,
- onSettingsOpen: () => undefined,
orders,
sort: {
...sortPageProps.sort,
diff --git a/src/storybook/stories/orders/OrderProductAddDialog.tsx b/src/storybook/stories/orders/OrderProductAddDialog.tsx
index cf3565fc2..c2459c2be 100644
--- a/src/storybook/stories/orders/OrderProductAddDialog.tsx
+++ b/src/storybook/stories/orders/OrderProductAddDialog.tsx
@@ -21,7 +21,7 @@ const props: OrderProductAddDialogProps = {
onSubmit: () => undefined,
open: true,
products,
- selectedChannel: products[0].variants[0].channelListings[0].channel.id
+ selectedChannelId: products[0].variants[0].channelListings[0].channel.id
};
storiesOf("Orders / OrderProductAddDialog", module)
diff --git a/src/storybook/stories/products/ProductListPage.tsx b/src/storybook/stories/products/ProductListPage.tsx
index e4ccc3079..dc7112aee 100644
--- a/src/storybook/stories/products/ProductListPage.tsx
+++ b/src/storybook/stories/products/ProductListPage.tsx
@@ -42,9 +42,8 @@ const props: ProductListPageProps = {
filterOpts: productListFilterOpts,
gridAttributes: attributes,
onExport: () => undefined,
- onSettingsOpen: () => undefined,
products,
- selectedChannel: "123",
+ selectedChannelId: "123",
settings: {
...pageListProps.default.settings,
columns: ["availability", "productType", "price"]
@@ -69,8 +68,7 @@ storiesOf("Views / Products / Product list", module)
({ ...product, channelListings: [] }))}
/>
));
diff --git a/src/storybook/stories/products/ProductUpdatePage.tsx b/src/storybook/stories/products/ProductUpdatePage.tsx
index 27641ea19..6465ee047 100644
--- a/src/storybook/stories/products/ProductUpdatePage.tsx
+++ b/src/storybook/stories/products/ProductUpdatePage.tsx
@@ -58,6 +58,7 @@ const props: ProductUpdatePageProps = {
placeholderImage,
product,
saveButtonBarState: "default",
+ selectedChannelId: "123",
taxTypes,
variants: product.variants,
warehouses: warehouseList
diff --git a/src/storybook/stories/shipping/ShippingZoneDetailsPage.tsx b/src/storybook/stories/shipping/ShippingZoneDetailsPage.tsx
index a378b39ec..be27e6116 100644
--- a/src/storybook/stories/shipping/ShippingZoneDetailsPage.tsx
+++ b/src/storybook/stories/shipping/ShippingZoneDetailsPage.tsx
@@ -27,7 +27,7 @@ const props: ShippingZoneDetailsPageProps = {
onWeightRateAdd: () => undefined,
onWeightRateEdit: () => undefined,
saveButtonBarState: "default",
- selectedChannel: "12345",
+ selectedChannelId: "12345",
shippingZone,
warehouses: warehouseList
};
diff --git a/src/storybook/stories/shipping/ShippingZonesListPage.tsx b/src/storybook/stories/shipping/ShippingZonesListPage.tsx
index d44cfd478..308fbcc50 100644
--- a/src/storybook/stories/shipping/ShippingZonesListPage.tsx
+++ b/src/storybook/stories/shipping/ShippingZonesListPage.tsx
@@ -20,9 +20,7 @@ const props: ShippingZonesListPageProps = {
onAdd: () => undefined,
onBack: () => undefined,
onRemove: () => undefined,
- onSettingsOpen: () => undefined,
onSubmit: () => undefined,
- selectedChannel: "123",
shippingZones,
userPermissions: adminUserPermissions
};
diff --git a/src/types.ts b/src/types.ts
index b1cf4e3db..4aa53c18d 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -117,6 +117,10 @@ export interface TabPageProps {
onTabSave: () => void;
}
+export interface ChannelProps {
+ selectedChannelId: string;
+}
+
export interface PartialMutationProviderOutput<
TData extends {} = {},
TVariables extends {} = {}
diff --git a/src/utils/credentialsManagement.ts b/src/utils/credentialsManagement.ts
index 7f7998caa..a0c109852 100644
--- a/src/utils/credentialsManagement.ts
+++ b/src/utils/credentialsManagement.ts
@@ -1,21 +1,32 @@
import { User } from "@saleor/fragments/types/User";
-export const isSupported =
- navigator.credentials && navigator.credentials.preventSilentAccess;
+export const isSupported = !!(
+ navigator?.credentials?.preventSilentAccess && PasswordCredential
+);
-export function login(loginFn: (id: string, password: string) => T): T {
- if (isSupported) {
- navigator.credentials.get({ password: true }).then(credential => {
- if (credential instanceof PasswordCredential) {
- return loginFn(credential.id, credential.password);
- }
- });
+export async function login(
+ loginFn: (id: string, password: string) => T
+): Promise {
+ let result: T;
+
+ try {
+ const credential = await navigator.credentials.get({ password: true });
+ if (credential instanceof PasswordCredential) {
+ result = loginFn(credential.id, credential.password);
+ }
+ } catch {
+ result = null;
}
- return null;
+ return result;
}
-export function saveCredentials(user: User, password: string) {
+export function saveCredentials(
+ user: User,
+ password: string
+): Promise {
+ let result: Promise;
+
if (isSupported) {
const cred = new PasswordCredential({
iconURL: user.avatar ? user.avatar.url : undefined,
@@ -23,6 +34,14 @@ export function saveCredentials(user: User, password: string) {
name: user.firstName ? `${user.firstName} ${user.lastName}` : undefined,
password
});
- navigator.credentials.store(cred);
+ try {
+ result = navigator.credentials.store(cred);
+ } catch {
+ result = null;
+ }
+ } else {
+ result = null;
}
+
+ return result;
}