forked from medusajs/medusa
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for price setting and updates for products (medusaj…
…s#7037) We still need to add a `batch` method for variants, but I'll do that in a separate PR
- Loading branch information
Showing
15 changed files
with
506 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/admin-next/dashboard/src/v2-routes/products/common/variant-pricing-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { UseFormReturn, useWatch } from "react-hook-form" | ||
import { CreateProductSchemaType } from "../product-create/schema" | ||
import { DataGrid } from "../../../components/grid/data-grid" | ||
import { useCurrencies } from "../../../hooks/api/currencies" | ||
import { useStore } from "../../../hooks/api/store" | ||
import { ColumnDef, createColumnHelper } from "@tanstack/react-table" | ||
import { CurrencyDTO, ProductVariantDTO } from "@medusajs/types" | ||
import { useTranslation } from "react-i18next" | ||
import { useMemo } from "react" | ||
import { ReadonlyCell } from "../../../components/grid/grid-cells/common/readonly-cell" | ||
import { CurrencyCell } from "../../../components/grid/grid-cells/common/currency-cell" | ||
import { DataGridMeta } from "../../../components/grid/types" | ||
|
||
type VariantPricingFormProps = { | ||
form: UseFormReturn<CreateProductSchemaType> | ||
} | ||
|
||
export const VariantPricingForm = ({ form }: VariantPricingFormProps) => { | ||
const { store, isLoading: isStoreLoading } = useStore() | ||
const { currencies, isLoading: isCurrenciesLoading } = useCurrencies( | ||
{ | ||
code: store?.supported_currency_codes, | ||
limit: store?.supported_currency_codes?.length, | ||
}, | ||
{ | ||
enabled: !!store, | ||
} | ||
) | ||
|
||
const columns = useVariantPriceGridColumns({ | ||
currencies, | ||
}) | ||
|
||
const variants = useWatch({ | ||
control: form.control, | ||
name: "variants", | ||
}) as any | ||
|
||
return ( | ||
<div className="flex size-full flex-col divide-y overflow-hidden"> | ||
<DataGrid | ||
columns={columns} | ||
data={variants} | ||
isLoading={isStoreLoading || isCurrenciesLoading} | ||
state={form} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
const columnHelper = createColumnHelper<ProductVariantDTO>() | ||
|
||
export const useVariantPriceGridColumns = ({ | ||
currencies = [], | ||
}: { | ||
currencies?: CurrencyDTO[] | ||
}) => { | ||
const { t } = useTranslation() | ||
|
||
const colDefs: ColumnDef<ProductVariantDTO>[] = useMemo(() => { | ||
return [ | ||
columnHelper.display({ | ||
id: t("fields.title"), | ||
header: t("fields.title"), | ||
cell: ({ row }) => { | ||
const entity = row.original | ||
|
||
return ( | ||
<ReadonlyCell> | ||
<div className="flex h-full w-full items-center gap-x-2 overflow-hidden"> | ||
<span className="truncate">{entity.title}</span> | ||
</div> | ||
</ReadonlyCell> | ||
) | ||
}, | ||
}), | ||
...currencies.map((currency) => { | ||
return columnHelper.display({ | ||
header: `Price ${currency.code.toUpperCase()}`, | ||
cell: ({ row, table }) => { | ||
return ( | ||
<CurrencyCell | ||
currency={currency} | ||
meta={table.options.meta as DataGridMeta} | ||
field={`variants.${row.index}.prices.${currency.code}`} | ||
/> | ||
) | ||
}, | ||
}) | ||
}), | ||
] | ||
}, [t, currencies]) | ||
|
||
return colDefs | ||
} |
124 changes: 0 additions & 124 deletions
124
.../v2-routes/products/product-create/components/create-product-form/create-product-form.tsx
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...t/dashboard/src/v2-routes/products/product-create/components/create-product-form/index.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.