fcdd6b4510
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { boolean, object, SchemaOf, string } from 'yup';
|
|
|
|
import { StackType } from '@/react/common/stacks/types';
|
|
import { buildGitValidationSchema } from '@/react/portainer/gitops/GitForm';
|
|
|
|
import { envVarValidation } from '@@/form-components/EnvironmentVariablesFieldset';
|
|
|
|
import { FormValues } from './types';
|
|
|
|
export function useValidationSchema(
|
|
stackType: StackType,
|
|
isSourceSelection: boolean
|
|
): SchemaOf<FormValues> {
|
|
const isKubernetes = stackType === StackType.Kubernetes;
|
|
|
|
return useMemo(
|
|
() =>
|
|
object({
|
|
kube: isKubernetes
|
|
? object({
|
|
name: string().default(''),
|
|
}).required()
|
|
: object({ name: string().default('') }).optional(),
|
|
git: buildGitValidationSchema(
|
|
false,
|
|
isKubernetes ? 'manifest' : 'compose',
|
|
true,
|
|
isSourceSelection
|
|
),
|
|
|
|
env: envVarValidation(),
|
|
prune: boolean().default(false),
|
|
redeployNow: boolean().default(false),
|
|
}),
|
|
[isKubernetes, isSourceSelection]
|
|
);
|
|
}
|