From 44cf9326c3b173083e1773db8286949a8c856a81 Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Fri, 9 Aug 2024 23:32:57 -0300 Subject: [PATCH] :sparkles: feat: Bug Module --- .../Action/Plain/MentoryAndVisit/index.tsx | 13 +++----- .../TabScreens/Action/index.tsx | 33 ++++++++++++++----- src/services/PlainService.ts | 5 ++- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/screens/SalesInspector/TabScreens/Action/Plain/MentoryAndVisit/index.tsx b/src/screens/SalesInspector/TabScreens/Action/Plain/MentoryAndVisit/index.tsx index c436e41..81594c2 100644 --- a/src/screens/SalesInspector/TabScreens/Action/Plain/MentoryAndVisit/index.tsx +++ b/src/screens/SalesInspector/TabScreens/Action/Plain/MentoryAndVisit/index.tsx @@ -16,7 +16,7 @@ interface PlainActionProps { seller: ISeller; modules: IModules[]; visits: IVisits[]; - addNewPlain: (newPlain: any) => void; + addNewPlain: () => void; } const PlainMentory: React.FC = ({ @@ -48,29 +48,26 @@ const PlainMentory: React.FC = ({ const handleCompletePlainAction = async () => { try { - // Formate a data no formato "dia/mês/ano" const formattedDate = date.toLocaleDateString('pt-BR', { day: '2-digit', month: '2-digit', year: 'numeric', }); - const newPlain = await PlainService.createPlain({ + await PlainService.createPlain({ title: titleAction, comments: comment, prize: formattedDate, // Envia a data formatada - sellerId: seller.id, + sellerId: seller?.id, supervisorId: seller.supervisorId, moduleId: seller.stage === 'Mentoria' ? selectedValue : selectedValue, }); - console.log(newPlain); - addNewPlain(newPlain); + addNewPlain(); setState(); showToast('Plano de ação efetivado com sucesso', 'success'); } catch (error) { - setState(); - showToast('Módulo já dispõe de um plano de ação', 'warning'); + showToast('Não foi possível criar plano para este módulo', 'warning'); } }; diff --git a/src/screens/SalesInspector/TabScreens/Action/index.tsx b/src/screens/SalesInspector/TabScreens/Action/index.tsx index 520f488..6bc4fec 100644 --- a/src/screens/SalesInspector/TabScreens/Action/index.tsx +++ b/src/screens/SalesInspector/TabScreens/Action/index.tsx @@ -18,7 +18,7 @@ const Action = ({ route }) => { const [isVisible, setIsVisible] = useState(false); const [plains, setPlains] = useState([]); const [completedPlains, setCompletedPlains] = useState([]); - const [seller, setSeller] = useState(null); + const [seller, setSeller] = useState(undefined); const [modules, setModules] = useState(null); const [visits, setVisits] = useState(null); @@ -31,11 +31,11 @@ const Action = ({ route }) => { idEmployee ); const visits = await VisitService.getVisitByIdSeller( - responseSeller.id + responseSeller?.id ?? '' ); const modulesData = await ModuleServices.getAllModules(); const plainsData = await PlainService.getByIdSellerPlain( - responseSeller.id + responseSeller?.id ?? '' ); setPlains(plainsData.filter((plain) => !plain.done)); setVisits(visits); @@ -53,8 +53,11 @@ const Action = ({ route }) => { fetchData(); }, [cargo, companyId, idEmployee]); - const addNewPlain = (newPlain: IPlains) => { - setPlains((prevPlains) => [...prevPlains, newPlain]); + const addNewPlain = async () => { + const updatedPlains = await PlainService.getByIdSellerPlain( + seller?.id ?? '' + ); + setPlains(updatedPlains); }; const handleToggleVisibility = (idPlain: string) => { @@ -126,15 +129,21 @@ const Action = ({ route }) => { setState={handleNavigator} seller={seller} modules={modules} - addNewPlain={addNewPlain} visits={visits} + addNewPlain={addNewPlain} /> )} ); }; -const PlanList = ({ +interface IPlanListProps { + title: string; + plains: IPlains[]; + handleToggleVisibility: (idPlain: string) => void; + handleMarkDone: (idPlain: string) => void; +} +const PlanList: React.FC = ({ title, plains, handleToggleVisibility, @@ -160,7 +169,15 @@ const PlanList = ({ ); }; -const CompletedPlanList = ({ +interface ICompletedPlanListProps { + title: string; + completedPlains: IPlains[]; + handleToggleVisibility: (idPlain: string) => void; + handleMarkDone: (idPlain: string) => void; + complete: boolean; +} + +const CompletedPlanList: React.FC = ({ title, completedPlains, handleToggleVisibility, diff --git a/src/services/PlainService.ts b/src/services/PlainService.ts index 5ebbb5b..4207a5d 100644 --- a/src/services/PlainService.ts +++ b/src/services/PlainService.ts @@ -43,7 +43,10 @@ export default class PlainService { } static async createPlain(newPlain: Partial): Promise { - const plainResponse = await api.post('/actionPlans/create', newPlain); + const plainResponse: AxiosResponse = await api.post( + '/actionPlans/create', + newPlain + ); return plainResponse.data; }