Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set default type to "internal" if it's somehow missing #10

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/components/LinkTypeInput.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {ChevronDownIcon} from '@sanity/icons'

Check warning on line 1 in src/components/LinkTypeInput.tsx

View workflow job for this annotation

GitHub Actions / Lint & Build

Run autofix to sort these imports!
import {Button, Menu, MenuButton, MenuItem} from '@sanity/ui'
import {AtSignIcon, GlobeIcon, LinkIcon, PhoneIcon} from 'lucide-react'
import {set, type StringInputProps} from 'sanity'
import styled from 'styled-components'

import {CustomLinkType, LinkFieldPluginOptions, LinkType} from '../types'
import {useEffect} from 'react'

const defaultLinkTypes: LinkType[] = [
{title: 'Internal', value: 'internal', icon: LinkIcon},
Expand Down Expand Up @@ -52,6 +53,13 @@

const selectedType = linkTypes.find((type) => type.value === value) || linkTypes[0]

useEffect(() => {
// Make sure there's always a default value
if (!value) {
onChange(set('internal'))
}
}, [onChange, value])

return (
<MenuButton
button={
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/typeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export const isEmailLink = (link: LinkValue): link is EmailLink => link.type ===
export const isPhoneLink = (link: LinkValue): link is PhoneLink => link.type === 'phone'

export const isCustomLink = (link: LinkValue): link is CustomLink =>
!['internal', 'external', 'email', 'phone'].includes(link.type)
!!link.type && !['internal', 'external', 'email', 'phone'].includes(link.type)
Loading