import { PropsWithChildren, ReactNode } from 'react'; import { SchemaOf, string } from 'yup'; import { useStateWrapper } from '@/react/hooks/useStateWrapper'; import { FormControl } from '@@/form-components/FormControl'; import { Input } from '@@/form-components/Input'; import { TextTip } from '@@/Tip/TextTip'; import { isBE } from '../../feature-flags/feature-flags.service'; import { RefSelector } from './RefSelector'; interface Props { value: string; onChange(value: string): void; sourceId?: number; error?: string; } export function RefField({ value, onChange, sourceId, error }: Props) { const [inputValue, updateInputValue] = useStateWrapper(value, onChange); const inputId = 'repository-reference-field'; return isBE ? ( Specify a reference of the repository using the following syntax: branches with refs/heads/branch_name or tags with{' '} refs/tags/tag_name. } > ) : ( Specify a reference of the repository using the following syntax: branches with refs/heads/branch_name or tags with{' '} refs/tags/tag_name. If not specified, will use the default HEAD reference normally the main{' '} branch. } > updateInputValue(e.target.value)} placeholder="refs/heads/main" /> ); } function Wrapper({ tip, children, errors, inputId, }: PropsWithChildren<{ tip: ReactNode; errors?: string; inputId: string }>) { return (
{tip}
{children}
); } export function refFieldValidation(): SchemaOf { return string() .when({ is: isBE, then: string().required('Repository reference name is required'), }) .default(''); }