import deleteEggVariable from '@/api/admin/eggs/deleteEggVariable'; import { Form, Formik, FormikHelpers, useFormikContext } from 'formik'; import React from 'react'; import tw from 'twin.macro'; import { array, boolean, object, string } from 'yup'; import getEgg, { Egg, EggVariable } from '@/api/admin/eggs/getEgg'; import updateEggVariables from '@/api/admin/eggs/updateEggVariables'; import NewVariableButton from '@/components/admin/nests/eggs/NewVariableButton'; import AdminBox from '@/components/admin/AdminBox'; import Button from '@/components/elements/Button'; import Checkbox from '@/components/elements/Checkbox'; import Field, { FieldRow, TextareaField } from '@/components/elements/Field'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import useFlash from '@/plugins/useFlash'; export const validationSchema = object().shape({ name: string().required().min(1).max(191), description: string(), envVariable: string().required().min(1).max(191), defaultValue: string(), userViewable: boolean().required(), userEditable: boolean().required(), rules: string().required(), }); export function EggVariableForm ({ prefix }: { prefix: string }) { return ( <>
); } function EggVariableBox ({ onDeleteClick, variable, prefix }: { onDeleteClick: () => void, variable: EggVariable, prefix: string }) { const { isSubmitting } = useFormikContext(); return ( {variable.name}

} button={ } >
); } export default function EggVariablesContainer ({ egg }: { egg: Egg }) { const { clearAndAddHttpError } = useFlash(); const { mutate } = getEgg(egg.id); const submit = (values: EggVariable[], { setSubmitting }: FormikHelpers) => { updateEggVariables(egg.id, values) .then(async (variables) => await mutate(egg => ({ ...egg!, relations: { variables: variables } }))) .catch(error => clearAndAddHttpError({ key: 'egg', error })) .then(() => setSubmitting(false)); }; return ( {({ isSubmitting, isValid }) => (
{egg.relations?.variables?.map((v, i) => ( { deleteEggVariable(egg.id, v.id) .then(async () => await mutate(egg => ({ ...egg!, relations: { variables: egg!.relations.variables!.filter(v2 => v.id === v2.id), }, }))) .catch(error => clearAndAddHttpError({ key: 'egg', error })); }} /> ))}
)}
); }