This PR adds an ecommerce plugin package with both a Payload plugin and React UI utilities for the frontend. It also adds a new ecommerce template and new ecommerce test suite. It also makes a change to the `cpa` package to accept a `--version` flag to install a specific version of Payload defaulting to the latest.
36 lines
959 B
TypeScript
36 lines
959 B
TypeScript
'use client'
|
|
import { useCurrency } from '@payloadcms/plugin-ecommerce/react'
|
|
import React from 'react'
|
|
import { CurrenciesConfig } from '@payloadcms/plugin-ecommerce/types'
|
|
|
|
type Props = {
|
|
currenciesConfig: CurrenciesConfig
|
|
}
|
|
|
|
export const CurrencySelector: React.FC<Props> = ({ currenciesConfig }) => {
|
|
const { currency, setCurrency } = useCurrency()
|
|
|
|
return (
|
|
<div>
|
|
selected: {currency.label} ({currency.code})<br />
|
|
<select
|
|
value={currency.code}
|
|
onChange={(e) => {
|
|
const selectedCurrency = currenciesConfig.supportedCurrencies.find(
|
|
(c) => c.code === e.target.value,
|
|
)
|
|
if (selectedCurrency) {
|
|
setCurrency(selectedCurrency.code)
|
|
}
|
|
}}
|
|
>
|
|
{currenciesConfig.supportedCurrencies.map((c) => (
|
|
<option key={c.code} value={c.code}>
|
|
{c.label} ({c.code})
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
)
|
|
}
|