import { BrandAssetUploader } from '@components/admin/BrandAssetUploader.js'; import { StandaloneMetafieldCard } from '@components/admin/metafield/StandaloneMetafieldCard.js'; import { SettingMenu } from '@components/admin/SettingMenu.js'; import Spinner from '@components/admin/Spinner.js'; import Area from '@components/common/Area.js'; import { EmailField } from '@components/common/form/EmailField.js'; import { Form, useFormContext } from '@components/common/form/Form.js'; import { InputField } from '@components/common/form/InputField.js'; import { ReactSelectField } from '@components/common/form/ReactSelectField.js'; import { SelectField } from '@components/common/form/SelectField.js'; import { TelField } from '@components/common/form/TelField.js'; import { TextareaField } from '@components/common/form/TextareaField.js'; import { Button } from '@components/common/ui/Button.js'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@components/common/ui/Card.js'; import { Item } from '@components/common/ui/Item.js'; import { Skeleton } from '@components/common/ui/Skeleton.js'; import { toast } from '@components/common/ui/Sonner.js'; import { LANGUAGES } from '@evershop/evershop/lib/locale/languages'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import React, { useEffect } from 'react'; import { useQuery } from 'urql'; function ShopCustomFields({ setting }: { setting?: { metaData?: Record; shopMetafieldsApi?: string; } | null; }): React.ReactElement | null { // Store-wide custom fields. Rendered as a sibling card BELOW the store-settings // form (same `content` area, higher sortOrder) so its own form doesn't nest // inside the settings form. Values live in the `metafield_shop` singleton. if (!setting?.shopMetafieldsApi) return null; return ( ); } const RegionsQuery = ` query StoreRegions($country: String!) { regions(country: $country) { key name } addressConfigWarnings { kind source key keyName mergedInto { key name } } } `; const CountriesQuery = ` query StoreCountries { countries(scope: ALL) { code name } } `; // Pinned to the `Weight.unit` / `Dimension.unit` vocabularies (see oms/types/carrier.ts and // the createShipment normalizer). These are display labels only — stored weights/dimensions // are unit-less numbers, so changing the unit relabels existing data, it does not convert it. const WEIGHT_UNITS = [ { value: 'kg', label: 'Kilogram (kg)' }, { value: 'g', label: 'Gram (g)' }, { value: 'lb', label: 'Pound (lb)' }, { value: 'oz', label: 'Ounce (oz)' } ]; const DIMENSION_UNITS = [ { value: 'cm', label: 'Centimeter (cm)' }, { value: 'mm', label: 'Millimeter (mm)' }, { value: 'in', label: 'Inch (in)' } ]; interface RegionOption { key: string; name: string; } interface RetiredWarning { kind: string; source: string; key?: string | null; keyName?: string | null; mergedInto?: { key: string; name: string } | null; } /** * The store's administrative area, from `regions(country)` (Address Format * Registry). The stored key is kept even when a data refresh retired it: the * option stays, marked "(retired)", with the successor named in the helper * text (`addressConfigWarnings`, source `store_address`). Countries without * enumerated regions render nothing and keep whatever is stored. */ const StoreRegion: React.FC<{ selectedCountry: string; selectedRegion: string; fieldName?: string; }> = ({ selectedCountry = 'US', selectedRegion, fieldName = 'storeProvince' }) => { const { setValue } = useFormContext(); const [result] = useQuery({ query: RegionsQuery, variables: { country: selectedCountry }, pause: !selectedCountry }); const { data, fetching, error } = result; const regions: RegionOption[] = data?.regions ?? []; const retired: RetiredWarning | undefined = ( data?.addressConfigWarnings ?? [] ).find( (w: RetiredWarning) => w.kind === 'RETIRED_REGION' && w.source === 'store_address' && w.key === selectedRegion ); useEffect(() => { if (fetching || !data) return; if ( regions.length > 0 && !retired && regions.every((r) => r.key !== selectedRegion) ) { setValue(fieldName, ''); } }, [selectedCountry, fetching]); if (fetching) return (
); if (error) { return

{error.message}

; } if (!regions.length && !retired) { return null; } const options = regions.map((r) => ({ value: r.key, label: r.name })); if (retired) { options.unshift({ value: selectedRegion, label: `${retired.keyName ?? selectedRegion} (${_('retired')})` }); } return (
); }; const Country: React.FC<{ selectedCountry: string; setSelectedCountry: (country: string) => void; fieldName?: string; }> = ({ selectedCountry, setSelectedCountry, fieldName = 'storeCountry' }) => { const onChange = (value: string) => { setSelectedCountry(value); }; const [result] = useQuery({ query: CountriesQuery }); const { data, fetching, error } = result; if (fetching) return ( ); if (error) { return

{error.message}

; } return (
({ value: c.code, label: c.name }))} />
); }; /** Display name for a locale code in a target language; `undefined` if unresolved. */ function displayName(inLocale: string, code: string): string | undefined { try { const name = new Intl.DisplayNames([inLocale], { type: 'language' }).of( code ); // Intl echoes the input code back when it can't resolve a name — treat that // as "unknown" so callers can fall back to the curated English label. return name && name.toLowerCase() !== code.toLowerCase() ? name : undefined; } catch { return undefined; } } const LanguageSettings: React.FC<{ storeLanguage: string; storeLanguages: string[]; adminLanguage: string; }> = ({ storeLanguage, storeLanguages, adminLanguage }) => { // Offer every ISO 639-1 language, not just those that ship a translation // folder. A language without a folder simply falls back to English strings // until one is added (saveSetting warns, it does not block). const options = React.useMemo( () => LANGUAGES.map(({ value, text }) => { // Clean English name via Intl (e.g. "Greek" not "Greek, Modern (1453-)"), // with the curated ISO label as fallback; append the native autonym when // it differs, e.g. "Vietnamese (Tiếng Việt)". const english = displayName('en', value) ?? text; const native = displayName(value, value); const showNative = !!native && native.toLowerCase() !== english.toLowerCase(); return { value, label: showNative ? `${english} (${native})` : english }; }).sort((a, b) => a.label.localeCompare(b.label)), [] ); // "Additional languages" never lists the default — it's always included implicitly // (enabled set = default + additional), so offering it here would be confusing. const additionalOptions = options.filter((o) => o.value !== storeLanguage); return ( {_('Languages')}
{/* */}
); }; const StorePhoneNumber: React.FC<{ storePhoneNumber: string }> = ({ storePhoneNumber }) => { return (
); }; const StoreEmail: React.FC<{ storeEmail: string }> = ({ storeEmail }) => { return (
); }; interface CodeName { code: string; name: string; } interface StoreSettingProps { saveSettingApi: string; timezones: CodeName[]; currencies: CodeName[]; setting: { storeName: string; storeDescription: string; storeLanguage: string; storeLanguages: string[]; adminLanguage: string; storeTimeZone: string; storePhoneNumber: string; storeEmail: string; storeCountry: string; storeAddress: string; storeCity: string; storeProvince: string; storePostalCode: string; metaData?: Record; storeCurrency?: string; weightUnit?: string; dimensionUnit?: string; shopMetafieldsApi?: string; logo?: string; logoWidth?: string; logoHeight?: string; favicon?: string; socialSharingImage?: string; gaMeasurementId?: string; gaConsentDefault?: string; }; } export default function StoreSetting({ saveSettingApi, timezones, currencies, setting: { storeName, storeDescription, storeLanguage, storeLanguages, adminLanguage, storeTimeZone, storePhoneNumber, storeEmail, storeCountry, storeAddress, storeCity, storeProvince, storePostalCode, metaData, storeCurrency, weightUnit, dimensionUnit, shopMetafieldsApi, logo, logoWidth, logoHeight, favicon, socialSharingImage, gaMeasurementId, gaConsentDefault } }: StoreSettingProps) { const [selectedCountry, setSelectedCountry] = React.useState(() => { const country = storeCountry; if (!country) { return 'US'; } else { return country; } }); // The save succeeded; surface any non-blocking warnings (e.g. an enabled language with // no translations yet) alongside the success toast. Defining onSuccess overrides the // Form's default success toast, so we raise it here. const onSuccess = (result: { warnings?: string[] }) => { toast.success(_('Saved successfully!')); (result?.warnings ?? []).forEach((message) => toast.warning(message)); }; return (
{_('Store Settings')} {_('Configure your store information')} ) }, sortOrder: 10 }, { component: { default: ( ) }, sortOrder: 20 } ]} /> {_('Contact Information')} {_('Address')}
{_('Regional & Units')}
({ value: c.code, label: `${c.name} (${c.code})` }))} helperText={_( 'Default currency for new carts and price display. Existing orders keep their own currency.' )} /> ({ value: t.code, label: t.name }))} helperText={_( 'Timezone used to display dates in the store.' )} />
{_('Branding')} {_( 'Your logo, favicon, and the image shown when your store is shared on social media.' )}
{_('Logo')}

{_( 'Shown in the storefront header. Use a high-resolution PNG with a transparent background — it is scaled to fit your theme automatically and served as optimized WebP.' )}

{_('Favicon')}

{_( 'The small icon in browser tabs. Upload a square PNG of at least 512×512px — the 16/32px icons and the 180px Apple touch icon are generated automatically.' )}

{_('Social sharing image')}

{_( 'The preview shown when a page is shared on social media (Open Graph / Twitter). Recommended 1200×630px (1.91:1), PNG or JPG.' )}

{_('Analytics')}
); } export const layout = { areaId: 'content', sortOrder: 10 }; export const query = ` query Query { saveSettingApi: url(routeId: "saveSetting") timezones { code name } currencies { code name } setting { storeName storeDescription storeLanguage storeLanguages adminLanguage storeTimeZone storePhoneNumber storeEmail storeCountry storeAddress storeCity storeProvince storePostalCode metaData storeCurrency weightUnit dimensionUnit shopMetafieldsApi logo logoWidth logoHeight favicon socialSharingImage gaMeasurementId gaConsentDefault } } `;