import deleteEggVariable from '@/api/admin/eggs/deleteEggVariable'; import { NoItems } from '@/components/admin/AdminTable'; import ConfirmationModal from '@/components/elements/ConfirmationModal'; import { Form, Formik, FormikHelpers, useFormikContext } from 'formik'; import React, { useState } from 'react'; import tw from 'twin.macro'; import { array, boolean, object, string } from 'yup'; import { EggVariable, useEggFromRoute } from '@/api/admin/egg'; 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'; import { TrashIcon } from '@heroicons/react/outline'; export const validationSchema = object().shape({ name: string().required().min(1).max(191), description: string(), environmentVariable: string().required().min(1).max(191), defaultValue: string(), isUserViewable: boolean().required(), isUserEditable: boolean().required(), rules: string().required(), }); export function EggVariableForm ({ prefix }: { prefix: string }) { return ( <>
); } function EggVariableDeleteButton ({ onClick }: { onClick: (success: () => void) => void }) { const [ visible, setVisible ] = useState(false); const [ loading, setLoading ] = useState(false); const onDelete = () => { setLoading(true); onClick(() => { //setLoading(false); }); }; return ( <> setVisible(false)} > Are you sure you want to delete this variable? Deleting this variable will delete it from every server using this egg. ); } function EggVariableBox ({ onDeleteClick, variable, prefix }: { onDeleteClick: (success: () => void) => void, variable: EggVariable, prefix: string }) { const { isSubmitting } = useFormikContext(); return ( {variable.name}

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