import React from "react"; import { ReportFieldDefinition, reportFieldTypes } from "@/data/report"; import { identityTransformer, Transformer } from "@/serialization"; import { useTranslation } from "react-i18next"; import { useSpacing } from "@/styles"; import { Field, FieldArray, FieldProps, useFormikContext } from "formik"; import { TextField as TextFieldFormik, Select } from "formik-material-ui"; import { FormControl, InputLabel, Typography, MenuItem, Card, Box, Button, CardContent, CardHeader, IconButton } from "@material-ui/core"; import { CKEditorField } from "@/forms/ckeditor"; import { Multilingual } from "@/data"; import { Actions } from "@/components"; import { Add } from "@material-ui/icons"; import { TrashCan } from "mdi-material-ui"; import { FieldPreview } from "@/management/report/fields/list"; import { createStyles, makeStyles, Theme } from "@material-ui/core/styles"; export type FieldDefinitionFormValues = ReportFieldDefinition | { type: string }; export const initialFieldFormValues: FieldDefinitionFormValues = { type: "short-text", description: { pl: "", en: "", }, label: { pl: "", en: "", }, choices: [], } export const fieldFormValuesTransformer: Transformer = identityTransformer; export type ChoiceFieldProps = { name: string }; const ChoiceField = ({ field, form, meta }: FieldProps) => { const { name } = field; const { t } = useTranslation("management"); const spacing = useSpacing(2); return
} const useStyles = makeStyles((theme: Theme) => createStyles({ preview: { padding: theme.spacing(2), backgroundColor: "#e9f0f5", }, })) export function FieldDefinitionForm() { const { t } = useTranslation("management"); const spacing = useSpacing(2); const { values } = useFormikContext(); const classes = useStyles(); return
{ t("report-field.field.type") } { reportFieldTypes.map(type => { t(`report-field.type.${type}`) })} { t("report-field.field.label") } { t("report-field.field.description") } { ["radio", "select", "checkbox"].includes(values.type) && <> { t("report-field.field.choices") } <> { values.choices.map((value: Multilingual, index: number) => helper.remove(index) }> }/> ) } } /> }
{ t("report-field.preview") }
}