diff --git a/src/components/FeedbackForms/MissingRecord/UrlsField.tsx b/src/components/FeedbackForms/MissingRecord/UrlsField.tsx index 5d71b3eba..e7d473286 100644 --- a/src/components/FeedbackForms/MissingRecord/UrlsField.tsx +++ b/src/components/FeedbackForms/MissingRecord/UrlsField.tsx @@ -8,6 +8,7 @@ import { SelectInstance } from 'react-select'; import { FormValues } from './types'; import { IResourceUrl, ResourceUrlType, resourceUrlTypes } from '@/lib/useGetResourceLinks'; import { useIsClient } from '@/lib/useIsClient'; +import { EXTERNAL_URLS } from '@/config'; export const UrlsField = () => { return ( @@ -24,6 +25,8 @@ const typeOptions: SelectOption[] = resourceUrlTypes.map((t) => value: t as string, })); +const { DOI_ORIGIN, ARXIV_ORIGIN } = EXTERNAL_URLS; + export const UrlsTable = ({ editable }: { editable: boolean }) => { const isClient = useIsClient(); @@ -37,7 +40,7 @@ export const UrlsTable = ({ editable }: { editable: boolean }) => { }); // New row being added - const [newUrl, setNewUrl] = useState({ type: 'arXiv', url: '' }); + const [newUrl, setNewUrl] = useState({ type: 'arXiv', url: `${ARXIV_ORIGIN}/` }); // Existing row being edited const [editUrl, setEditUrl] = useState<{ index: number; url: IResourceUrl }>({ @@ -67,7 +70,9 @@ export const UrlsTable = ({ editable }: { editable: boolean }) => { try { const testUrl = new URL(url); - return VALID_PROTOCOLS.includes(testUrl.protocol); + return testUrl.origin === DOI_ORIGIN || testUrl.origin === ARXIV_ORIGIN + ? testUrl.pathname.length > 1 + : VALID_PROTOCOLS.includes(testUrl.protocol); } catch { return false; } @@ -80,7 +85,8 @@ export const UrlsTable = ({ editable }: { editable: boolean }) => { // Changes to fields for adding new url const handleNewTypeChange = (option: SelectOption) => { - setNewUrl((prev) => ({ ...prev, type: option.id })); + const origin = option.id === 'DOI' ? `${DOI_ORIGIN}/` : option.id === 'arXiv' ? `${ARXIV_ORIGIN}/` : ''; + setNewUrl({ url: origin, type: option.id }); }; const handleNewUrlChange = (e: ChangeEvent) => { @@ -90,7 +96,7 @@ export const UrlsTable = ({ editable }: { editable: boolean }) => { const handleAddUrl = () => { append(newUrl); // clear input fields - setNewUrl({ type: 'arXiv', url: '' }); + setNewUrl({ type: 'arXiv', url: `${ARXIV_ORIGIN}/` }); (newURLTypeInputRef.current as SelectInstance).focus(); }; diff --git a/src/config.ts b/src/config.ts index f645637ec..1ce49c397 100644 --- a/src/config.ts +++ b/src/config.ts @@ -79,6 +79,8 @@ export const EXTERNAL_URLS = { CFA_SAO_HOME_PAGE: 'https://www.cfa.harvard.edu/sao' as const, UAT: 'http://astrothesaurus.org', ORCID: 'https://orcid.org', + DOI_ORIGIN: 'https://doi.org', + ARXIV_ORIGIN: 'https://arxiv.org', }; export const TRACING_HEADERS = ['X-Original-Uri', 'X-Original-Forwarded-For', 'X-Forwarded-For', 'X-Amzn-Trace-Id'];