import { useQuery } from '@tanstack/react-query'; import { useParams } from 'react-router-dom'; import * as Yup from 'yup'; import { Grid, FormLabel, Radio, RadioGroup, FormControlLabel, } from '@mui/material'; import { Formik, Form, Field } from 'formik'; import LoadingButton from '@mui/lab/LoadingButton'; import { Spinner } from '../../../components/spinner/Spinner'; import { ReportService } from '../../../features/reports/report-service'; import { Layout } from '../../../components/ui/layout/layout'; export const ReportEdit = () => { const { id } = useParams(); const breadcrumbs = [ { label: 'Reports', href: `?page=vendorfuel#!/reports`, }, { label: 'Schedule reports', href: `?page=vf-admin#/reports/schedule`, }, { label: `ID: ${id.toString()}`, href: `?page=vf-admin#/reports/schedule/${id}`, }, ]; const nav = [ { label: 'Edit reports', href: `?page=vendorfuel#!/reports`, }, { label: 'Downloadable reports', href: `?page=vf-admin#/reports/downloads`, }, ]; const radioOptions = [ { label: 'Daily', value: 'daily' }, { label: 'Weekly', value: 'weekly' }, { label: 'Monthly', value: 'monthly' }, { label: 'Quarterly', value: 'quarterly' }, { label: 'None', value: 'none' }, ]; const validationSchema = Yup.object().shape({ frequency: Yup.string().required( 'The report schedule frequency is required.' ), }); const { data, isFetching } = useQuery({ queryKey: [`report-${id}`], queryFn: () => ReportService.show(id), }); return ( {!data && } {data && ( { ReportService.schedule({ id, ...values }).then(() => { setSubmitting(false); }); }} > {({ isSubmitting }) => (
{data.name} Frequency {radioOptions.map((option) => ( } label={option.label} /> ))} Update
)}
)}
); };