Open ROXBOZ opened 1 year ago
I'm having the same problem. It looks like the same error has been raised as an issue in other plugins too.
Any update on this? Getting the same error @syedMSohaib
fixing this @tea-vitamin
I have the same problem :(
Cannot destructure property 'media' of 'n.sanity' as it is undefined.
Need to use this now so going to roll-my-own 👍 Hope you get it resolved.
If it helps anyone get by while the above is being fixed. I hacked this together and working well for my purposes:
import {SearchIcon} from '@sanity/icons'
import {Autocomplete, Box, Card, Flex, Text} from '@sanity/ui'
import {useCallback} from 'react'
import {StringInputProps, set, unset} from 'sanity'
import countries from 'world-countries'
export enum CountrySelectMode {
CCA2,
CCA3,
}
interface IProps extends StringInputProps {
mode?: CountrySelectMode
}
export const CountrySelectInput: React.FunctionComponent<IProps> = ({
mode = CountrySelectMode.CCA3,
...props
}) => {
const {onChange, value = '', ...fwdProps} = props
const handleChange = useCallback(
(value: string) => onChange(value ? set(value) : unset()),
[onChange]
)
return (
<Card>
<Autocomplete
{...fwdProps}
onChange={handleChange}
value={value}
filterOption={(query, option) =>
option.payload.name.common.toLowerCase().indexOf(query.toLowerCase()) > -1
}
fontSize={[2, 2, 3]}
icon={SearchIcon}
openButton
options={countries.map((country) => ({
value: mode === CountrySelectMode.CCA2 ? country.cca2 : country.cca3,
payload: country,
}))}
padding={[3, 3, 4]}
placeholder="Type to find a country"
renderOption={(option) => (
<Card as="button">
<Flex align="center">
<Box padding={1}>
<Text>{option.payload.flag}</Text>
</Box>
<Box flex={1} padding={2} paddingLeft={1}>
<Text size={[2, 2, 3]}>
{option.payload.name.common}
{mode === CountrySelectMode.CCA2
? ` (${option.payload.cca2})`
: ` (${option.payload.cca3})`}
</Text>
</Box>
</Flex>
</Card>
)}
renderValue={(value, option) => {
const country = option?.payload
return country
? `${country?.flag} ${country?.name.common} (${
mode === CountrySelectMode.CCA2 ? country.cca2 : country.cca3
})`
: ''
}}
/>
</Card>
)
}
If it helps anyone get by while the above is being fixed. I hacked this together and working well for my purposes:
import {SearchIcon} from '@sanity/icons' import {Autocomplete, Box, Card, Flex, Text} from '@sanity/ui' import {useCallback} from 'react' import {StringInputProps, set, unset} from 'sanity' import countries from 'world-countries' export enum CountrySelectMode { CCA2, CCA3, } interface IProps extends StringInputProps { mode?: CountrySelectMode } export const CountrySelectInput: React.FunctionComponent<IProps> = ({ mode = CountrySelectMode.CCA3, ...props }) => { const {onChange, value = '', ...fwdProps} = props const handleChange = useCallback( (value: string) => onChange(value ? set(value) : unset()), [onChange] ) return ( <Card> <Autocomplete {...fwdProps} onChange={handleChange} value={value} filterOption={(query, option) => option.payload.name.common.toLowerCase().indexOf(query.toLowerCase()) > -1 } fontSize={[2, 2, 3]} icon={SearchIcon} openButton options={countries.map((country) => ({ value: mode === CountrySelectMode.CCA2 ? country.cca2 : country.cca3, payload: country, }))} padding={[3, 3, 4]} placeholder="Type to find a country" renderOption={(option) => ( <Card as="button"> <Flex align="center"> <Box padding={1}> <Text>{option.payload.flag}</Text> </Box> <Box flex={1} padding={2} paddingLeft={1}> <Text size={[2, 2, 3]}> {option.payload.name.common} {mode === CountrySelectMode.CCA2 ? ` (${option.payload.cca2})` : ` (${option.payload.cca3})`} </Text> </Box> </Flex> </Card> )} renderValue={(value, option) => { const country = option?.payload return country ? `${country?.flag} ${country?.name.common} (${ mode === CountrySelectMode.CCA2 ? country.cca2 : country.cca3 })` : '' }} /> </Card> ) }
Thank you very much
When installing the plugin with npm, I get this line in my dependencies
"sanity-plugin-country-state-select": "^1.0.1",
The import you give is
import {countryStateListPlugin} from 'sanity-country-state-select'
(also sanity-country... instead of sanity-plugin-country...I can't use the plugin at all – whether I strictly follow the instructions or try adapting the
import
to the dependency name.Here is the error log.