From 5065f1560a3e275ef04c44ae67c8e75aee5e09f7 Mon Sep 17 00:00:00 2001 From: mateusvrs Date: Mon, 12 Feb 2024 23:03:57 -0300 Subject: [PATCH] front(comps): decrease cog complexity of functions --- .../SchedulePreview/SchedulePreview.tsx | 79 +++++++++++-------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/web/app/components/SchedulePreview/SchedulePreview.tsx b/web/app/components/SchedulePreview/SchedulePreview.tsx index a969cb0..b805258 100644 --- a/web/app/components/SchedulePreview/SchedulePreview.tsx +++ b/web/app/components/SchedulePreview/SchedulePreview.tsx @@ -21,8 +21,7 @@ import deleteSchedule from '@/app/utils/api/deleteSchedule'; import { errorToast, successToast } from '@/app/utils/toast'; import jsPDF from 'jspdf'; -import toast from 'react-hot-toast'; -import { Axios, AxiosError } from 'axios'; +import { AxiosError } from 'axios'; const commonError = () => errorToast('Houve um erro na atualização das grades!'); @@ -94,34 +93,9 @@ function BottomPart(props: { } }) { const { user } = useUser(); - const { setCloudSchedules } = useSchedules(); const [changeDate, setChangeDate] = useState(''); - /** - * Tenta salvar a grade na nuvem, se der certo, atualiza as grades locais. - * Caso contrário, exibe errotToast com mensagem retornada pela API. - */ - async function handleUploadToCloud() { - try { - const saveResponse = await saveSchedule(props.schedules.localSchedule, user.access); - - if (saveResponse.status == 201) { - getSchedules(user.access).then(response => { - props.handleDelete(); - setCloudSchedules(response.data); - }).catch(() => commonError()); - successToast('Grade salva com sucesso!'); - } - } catch (error) { - const axiosError = error as AxiosError; - if (axiosError.response) { - const data = axiosError.response.data as { errors: string }; - errorToast(data.errors); - } - } - } - useEffect(() => { if (props.isCloud && props.schedules.cloudSchedule?.created_at) { setChangeDate(handleDate(props.schedules.cloudSchedule.created_at)); @@ -130,18 +104,12 @@ function BottomPart(props: { return (
-
+
Grade {props.position}
{props.isCloud && changeDate && {changeDate}}
- {!props.isCloud && !user.is_anonymous && - - } + {!props.isCloud && !user.is_anonymous && } + ); +} + function handleDownloadPDF(isCloud: boolean, index: number) { const doc = document.getElementById('download-content')!;