Files
payloadcms/test/plugin-ecommerce/app/components/CurrencySelector.tsx
Paul ef4874b9a0 feat: ecommerce plugin and template (#8297)
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.
2025-09-29 20:05:16 -04:00

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>
)
}