27 lines
658 B
TypeScript
27 lines
658 B
TypeScript
import {
|
|
emptyProviderContacts,
|
|
PROVIDER_EMAIL_ROLE_LABEL,
|
|
PROVIDER_EMAIL_ROLE_ORDER,
|
|
type ProviderContactEmails,
|
|
type ProviderEmailRole
|
|
} from '~/types/provider-contacts'
|
|
import { useLocalStorageRef } from '~/utils/useLocalStorageRef'
|
|
|
|
function storageKey(providerId: string) {
|
|
return `policy-ui-provider-contacts-v1-${providerId}`
|
|
}
|
|
|
|
export function useProviderContactEmails(providerId: string) {
|
|
const emails = useLocalStorageRef(storageKey(providerId), emptyProviderContacts)
|
|
|
|
function label(r: ProviderEmailRole) {
|
|
return PROVIDER_EMAIL_ROLE_LABEL[r]
|
|
}
|
|
|
|
return {
|
|
emails,
|
|
roles: PROVIDER_EMAIL_ROLE_ORDER,
|
|
label
|
|
}
|
|
}
|