Skip to content

Commit

Permalink
✨ feat: Bug Module
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrogomes18 committed Aug 10, 2024
1 parent 6b63676 commit 44cf932
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface PlainActionProps {
seller: ISeller;
modules: IModules[];
visits: IVisits[];
addNewPlain: (newPlain: any) => void;
addNewPlain: () => void;
}

const PlainMentory: React.FC<PlainActionProps> = ({
Expand Down Expand Up @@ -48,29 +48,26 @@ const PlainMentory: React.FC<PlainActionProps> = ({

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');
}
};

Expand Down
33 changes: 25 additions & 8 deletions src/screens/SalesInspector/TabScreens/Action/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Action = ({ route }) => {
const [isVisible, setIsVisible] = useState(false);
const [plains, setPlains] = useState<IPlains[]>([]);
const [completedPlains, setCompletedPlains] = useState<IPlains[]>([]);
const [seller, setSeller] = useState<ISeller | null>(null);
const [seller, setSeller] = useState<ISeller | undefined>(undefined);
const [modules, setModules] = useState<IModules[] | null>(null);
const [visits, setVisits] = useState<IVisits[] | null>(null);

Expand All @@ -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);
Expand All @@ -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) => {
Expand Down Expand Up @@ -126,15 +129,21 @@ const Action = ({ route }) => {
setState={handleNavigator}
seller={seller}
modules={modules}
addNewPlain={addNewPlain}
visits={visits}
addNewPlain={addNewPlain}
/>
)}
</S.ViewWrapper>
);
};

const PlanList = ({
interface IPlanListProps {
title: string;
plains: IPlains[];
handleToggleVisibility: (idPlain: string) => void;
handleMarkDone: (idPlain: string) => void;
}
const PlanList: React.FC<IPlanListProps> = ({
title,
plains,
handleToggleVisibility,
Expand All @@ -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<ICompletedPlanListProps> = ({
title,
completedPlains,
handleToggleVisibility,
Expand Down
5 changes: 4 additions & 1 deletion src/services/PlainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export default class PlainService {
}

static async createPlain(newPlain: Partial<IPlain>): Promise<IPlain> {
const plainResponse = await api.post('/actionPlans/create', newPlain);
const plainResponse: AxiosResponse<IPlain> = await api.post(
'/actionPlans/create',
newPlain
);
return plainResponse.data;
}

Expand Down

0 comments on commit 44cf932

Please sign in to comment.