Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fetch currencies from API
dominik-zeglen87adbd04e81d
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx b/saleor/static/dashboard-next/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsxindex 5ec6212224..5bc622ab40 100644--- a/saleor/static/dashboard-next/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx+++ b/saleor/static/dashboard-next/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx@@ -28,6 +28,7 @@ interface FormData {sku?: string;}interface ProductVariantCreatePageProps {+ currencySymbol: string;errors: UserError[];header: string;loading: boolean;@@ -53,6 +54,7 @@ const decorate = withStyles(theme => ({const ProductVariantCreatePage = decorate<ProductVariantCreatePageProps>(({classes,+ currencySymbol,errors: formErrors,loading,header,@@ -114,8 +116,7 @@ const ProductVariantCreatePage = decorate<ProductVariantCreatePageProps>(<ProductVariantPriceerrors={errors}priceOverride={data.priceOverride}- // FIXME: currency symbol should be fetched from API- currencySymbol="USD"+ currencySymbol={currencySymbol}costPrice={data.costPrice}loading={loading}onChange={change}diff --git a/saleor/static/dashboard-next/products/components/ProductVariantPage/ProductVariantPage.tsx b/saleor/static/dashboard-next/products/components/ProductVariantPage/ProductVariantPage.tsxindex 8178676b3b..2fe3ab308a 100644--- a/saleor/static/dashboard-next/products/components/ProductVariantPage/ProductVariantPage.tsx+++ b/saleor/static/dashboard-next/products/components/ProductVariantPage/ProductVariantPage.tsx@@ -192,6 +192,8 @@ const ProductVariantPage = decorate<ProductVariantPageProps>(currencySymbol={variant && variant.priceOverride? variant.priceOverride.currency+ : variant && variant.costPrice+ ? variant.costPrice.currency: ""}costPrice={data.costPrice}diff --git a/saleor/static/dashboard-next/products/views/ProductCreate.tsx b/saleor/static/dashboard-next/products/views/ProductCreate.tsxindex 0bfe93e3e5..d0eea3ec68 100644--- a/saleor/static/dashboard-next/products/views/ProductCreate.tsx+++ b/saleor/static/dashboard-next/products/views/ProductCreate.tsx@@ -5,7 +5,7 @@ import Messages from "../../components/messages";import Navigator from "../../components/Navigator";import { WindowTitle } from "../../components/WindowTitle";import i18n from "../../i18n";-import { decimal } from "../../misc";+import { decimal, maybe } from "../../misc";import ProductCreatePage from "../components/ProductCreatePage";import { productListUrl, productUrl } from "../index";import { TypedProductCreateMutation } from "../mutations";@@ -19,116 +19,122 @@ interface ProductUpdateProps {export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = () => (- <Messages>- {pushMessage => {- return (- <Navigator>- {navigate => {- const handleAttributesEdit = undefined;- const handleBack = () => navigate(productListUrl);+ <Shop>+ {shop => (+ <Messages>+ {pushMessage => {+ return (+ <Navigator>+ {navigate => {+ const handleAttributesEdit = undefined;+ const handleBack = () => navigate(productListUrl);- return (- <TypedProductCreateQuery query={productCreateQuery}>- {({ data, error, loading }) => {- const handleSuccess = (data: ProductCreate) => {- if (data.productCreate.errors.length === 0) {- pushMessage({ text: i18n.t("Product created") });- navigate(- productUrl(- encodeURIComponent(data.productCreate.product.id)- )- );- }- };-- if (error) {- return (- <ErrorMessageCard- message={i18n.t("Something went wrong")}- />- );- }-- return (- <TypedProductCreateMutation onCompleted={handleSuccess}>- {(- productCreate,- {- data: productCreateData,- loading: productCreateDataLoading+ return (+ <TypedProductCreateQuery query={productCreateQuery}>+ {({ data, error, loading }) => {+ const handleSuccess = (data: ProductCreate) => {+ if (data.productCreate.errors.length === 0) {+ pushMessage({ text: i18n.t("Product created") });+ navigate(+ productUrl(+ encodeURIComponent(data.productCreate.product.id)+ )+ );}- ) => {- const handleSubmit = formData => {- productCreate({- variables: {- attributes: formData.attributes,- availableOn:- formData.availableOn !== ""- ? formData.availableOn- : null,- category: formData.category,- chargeTaxes: formData.chargeTaxes,- collections: formData.collections,- description: formData.description,- isPublished: formData.available,- name: formData.name,- price: decimal(formData.price),- productType: formData.productType.value.id- }- });- };+ };- const disabled = loading || productCreateDataLoading;+ if (error) {return (- <>- <WindowTitle title={i18n.t("Create product")} />- <ProductCreatePage- // FIXME: this should be fetched from API- currency="USD"- categories={- data && data.categories- ? data.categories.edges.map(edge => edge.node)- : undefined- }- collections={- data && data.collections- ? data.collections.edges.map(- edge => edge.node- )- : undefined- }- disabled={disabled}- errors={- productCreateData &&- productCreateData.productCreate &&- productCreateData.productCreate.errors- ? productCreateData.productCreate.errors- : []- }- header={i18n.t("New Product")}- productTypes={- data && data.productTypes- ? data.productTypes.edges.map(- edge => edge.node- )- : undefined- }- onAttributesEdit={handleAttributesEdit}- onBack={handleBack}- onSubmit={handleSubmit}- />- </>+ <ErrorMessageCard+ message={i18n.t("Something went wrong")}+ />);- }}- </TypedProductCreateMutation>- );- }}- </TypedProductCreateQuery>- );- }}- </Navigator>- );- }}- </Messages>+ }++ return (+ <TypedProductCreateMutation onCompleted={handleSuccess}>+ {(+ productCreate,+ {+ data: productCreateData,+ loading: productCreateDataLoading+ }+ ) => {+ const handleSubmit = formData => {+ productCreate({+ variables: {+ attributes: formData.attributes,+ availableOn:+ formData.availableOn !== ""+ ? formData.availableOn+ : null,+ category: formData.category,+ chargeTaxes: formData.chargeTaxes,+ collections: formData.collections,+ description: formData.description,+ isPublished: formData.available,+ name: formData.name,+ price: decimal(formData.price),+ productType: formData.productType.value.id+ }+ });+ };++ const disabled =+ loading || productCreateDataLoading;+ return (+ <>+ <WindowTitle title={i18n.t("Create product")} />+ <ProductCreatePage+ currency={maybe(() => shop.defaultCurrency)}+ categories={+ data && data.categories+ ? data.categories.edges.map(+ edge => edge.node+ )+ : undefined+ }+ collections={+ data && data.collections+ ? data.collections.edges.map(+ edge => edge.node+ )+ : undefined+ }+ disabled={disabled}+ errors={+ productCreateData &&+ productCreateData.productCreate &&+ productCreateData.productCreate.errors+ ? productCreateData.productCreate.errors+ : []+ }+ header={i18n.t("New Product")}+ productTypes={+ data && data.productTypes+ ? data.productTypes.edges.map(+ edge => edge.node+ )+ : undefined+ }+ onAttributesEdit={handleAttributesEdit}+ onBack={handleBack}+ onSubmit={handleSubmit}+ />+ </>+ );+ }}+ </TypedProductCreateMutation>+ );+ }}+ </TypedProductCreateQuery>+ );+ }}+ </Navigator>+ );+ }}+ </Messages>+ )}+ </Shop>);export default ProductUpdate;diff --git a/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx b/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsxindex a6b4c595cb..7726bfc653 100644--- a/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx+++ b/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx@@ -4,6 +4,7 @@ import { productUrl, productVariantEditUrl } from "..";import ErrorMessageCard from "../../components/ErrorMessageCard";import Messages from "../../components/messages";import Navigator from "../../components/Navigator";+import Shop from "../../components/Shop";import { WindowTitle } from "../../components/WindowTitle";import i18n from "../../i18n";import { decimal, maybe } from "../../misc";@@ -33,100 +34,109 @@ interface FormData {export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({productId}) => (- <Navigator>- {navigate => (- <Messages>- {pushMessage => (- <TypedProductVariantCreateQuery- query={productVariantCreateQuery}- variables={{ id: productId }}- >- {({ data, error, loading: productLoading }) => {- if (error) {- return (- <ErrorMessageCard message={i18n.t("Something went wrong")} />- );- }-- const handleCreateSuccess = (data: VariantCreate) => {- if (- data.productVariantCreate.errors &&- data.productVariantCreate.errors.length === 0- ) {- pushMessage({ text: i18n.t("Product created") });- navigate(- productVariantEditUrl(- encodeURIComponent(productId),- encodeURIComponent(- data.productVariantCreate.productVariant.id- )- )- );- }- };-- return (- <TypedVariantCreateMutation onCompleted={handleCreateSuccess}>- {(variantCreate, variantCreateResult) => {- if (variantCreateResult.error) {- return (- <ErrorMessageCard- message={i18n.t("Something went wrong")}- />- );- }+ <Shop>+ {shop => (+ <Navigator>+ {navigate => (+ <Messages>+ {pushMessage => (+ <TypedProductVariantCreateQuery+ query={productVariantCreateQuery}+ variables={{ id: productId }}+ >+ {({ data, error, loading: productLoading }) => {+ if (error) {+ return (+ <ErrorMessageCard+ message={i18n.t("Something went wrong")}+ />+ );+ }- const handleBack = () =>- navigate(productUrl(encodeURIComponent(productId)));- const handleSubmit = (formData: FormData) =>- variantCreate({- variables: {- attributes: formData.attributes,- costPrice: decimal(formData.costPrice),- priceOverride: decimal(formData.priceOverride),- product: productId,- quantity: formData.quantity || null,- sku: formData.sku,- trackInventory: true- }- });- const handleVariantClick = (id: string) =>+ const handleCreateSuccess = (data: VariantCreate) => {+ if (+ data.productVariantCreate.errors &&+ data.productVariantCreate.errors.length === 0+ ) {+ pushMessage({ text: i18n.t("Product created") });navigate(productVariantEditUrl(encodeURIComponent(productId),- encodeURIComponent(id)+ encodeURIComponent(+ data.productVariantCreate.productVariant.id+ )));+ }+ };- const loading =- productLoading || variantCreateResult.loading;- return (- <>- <WindowTitle title={i18n.t("Create variant")} />- <ProductVariantCreatePage- errors={maybe(- () =>- variantCreateResult.data.productVariantCreate- .errors,- []- )}- header={i18n.t("Add Variant")}- loading={loading}- product={maybe(() => data.product)}- onBack={handleBack}- onSubmit={handleSubmit}- onVariantClick={handleVariantClick}- />- </>- );- }}- </TypedVariantCreateMutation>- );- }}- </TypedProductVariantCreateQuery>+ return (+ <TypedVariantCreateMutation+ onCompleted={handleCreateSuccess}+ >+ {(variantCreate, variantCreateResult) => {+ if (variantCreateResult.error) {+ return (+ <ErrorMessageCard+ message={i18n.t("Something went wrong")}+ />+ );+ }++ const handleBack = () =>+ navigate(productUrl(encodeURIComponent(productId)));+ const handleSubmit = (formData: FormData) =>+ variantCreate({+ variables: {+ attributes: formData.attributes,+ costPrice: decimal(formData.costPrice),+ priceOverride: decimal(formData.priceOverride),+ product: productId,+ quantity: formData.quantity || null,+ sku: formData.sku,+ trackInventory: true+ }+ });+ const handleVariantClick = (id: string) =>+ navigate(+ productVariantEditUrl(+ encodeURIComponent(productId),+ encodeURIComponent(id)+ )+ );++ const loading =+ productLoading || variantCreateResult.loading;+ return (+ <>+ <WindowTitle title={i18n.t("Create variant")} />+ <ProductVariantCreatePage+ currencySymbol={maybe(() => shop.defaultCurrency)}+ errors={maybe(+ () =>+ variantCreateResult.data.productVariantCreate+ .errors,+ []+ )}+ header={i18n.t("Add Variant")}+ loading={loading}+ product={maybe(() => data.product)}+ onBack={handleBack}+ onSubmit={handleSubmit}+ onVariantClick={handleVariantClick}+ />+ </>+ );+ }}+ </TypedVariantCreateMutation>+ );+ }}+ </TypedProductVariantCreateQuery>+ )}+ </Messages>)}- </Messages>+ </Navigator>)}- </Navigator>+ </Shop>);export default ProductVariant;