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 { SelectField } from '@components/common/form/SelectField.js'; import { TelField } from '@components/common/form/TelField.js'; import { TextareaField } from '@components/common/form/TextareaField.js'; import { Card, CardContent, CardDescription, 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 React, { useEffect } from 'react'; import { useQuery } from 'urql'; const ProvincesQuery = ` query Province($countries: [String]) { provinces (countries: $countries) { code name countryCode } } `; const CountriesQuery = ` query Country($countries: [String]) { countries (countries: $countries) { code name } } `; const Province: React.FC<{ selectedCountry: string; selectedProvince: string; allowedCountries?: string[]; fieldName?: string; }> = ({ selectedCountry = 'US', selectedProvince, allowedCountries = [], fieldName = 'storeProvince' }) => { const { setValue } = useFormContext(); const [result] = useQuery({ query: ProvincesQuery, variables: { countries: allowedCountries } }); const { data, fetching, error } = result; useEffect(() => { if (fetching || !data) return; const provinces = data.provinces.filter( (p) => p.countryCode === selectedCountry ); if (provinces.every((p) => p.code !== selectedProvince)) { setValue(fieldName, ''); } }, [selectedCountry, fetching]); if (fetching) return (
); if (error) { return

{error.message}

; } const provinces = data.provinces.filter( (p) => p.countryCode === selectedCountry ); if (!provinces.length) { return null; } return (
({ value: p.code, label: p.name }))} />
); }; const Country: React.FC<{ selectedCountry: string; setSelectedCountry: (country: string) => void; allowedCountries?: string[]; fieldName?: string; }> = ({ selectedCountry, setSelectedCountry, allowedCountries = [], fieldName = 'storeCountry' }) => { const onChange = (value: string) => { setSelectedCountry(value); }; const [result] = useQuery({ query: CountriesQuery, variables: { countries: allowedCountries } }); const { data, fetching, error } = result; if (fetching) return ( ); if (error) { return

{error.message}

; } return (
({ value: c.code, label: c.name }))} />
); }; const StorePhoneNumber: React.FC<{ storePhoneNumber: string }> = ({ storePhoneNumber }) => { return (
); }; const StoreEmail: React.FC<{ storeEmail: string }> = ({ storeEmail }) => { return (
); }; interface StoreSettingProps { saveSettingApi: string; setting: { storeName: string; storeDescription: string; storePhoneNumber: string; storeEmail: string; storeCountry: string; storeAddress: string; storeCity: string; storeProvince: string; storePostalCode: string; }; } export default function StoreSetting({ saveSettingApi, setting: { storeName, storeDescription, storePhoneNumber, storeEmail, storeCountry, storeAddress, storeCity, storeProvince, storePostalCode } }: StoreSettingProps) { const [selectedCountry, setSelectedCountry] = React.useState(() => { const country = storeCountry; if (!country) { return 'US'; } else { return country; } }); return (
Store Settings Configure your store information ) }, sortOrder: 10 }, { component: { default: ( ) }, sortOrder: 20 } ]} /> Contact Information Address
); } export const layout = { areaId: 'content', sortOrder: 10 }; export const query = ` query Query { saveSettingApi: url(routeId: "saveSetting") setting { storeName storeDescription storeTimeZone storePhoneNumber storeEmail storeCountry storeAddress storeCity storeProvince storePostalCode } } `;