Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app,admin,api,lib): 3525 - Affichage des particularites access du PDR #4528

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions admin/src/scenes/pointDeRassemblement/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import React, { useState } from "react";
import { BsDownload } from "react-icons/bs";
import { useSelector } from "react-redux";
import { useHistory, useParams, useLocation } from "react-router-dom";
import { PointDeRassemblementType, ROLES, canCreateMeetingPoint, getDepartmentNumber } from "snu-lib";
import { PointDeRassemblementType, ROLES, canCreateMeetingPoint, getDepartmentNumber, getParticularitesAcces } from "snu-lib";
import BusSvg from "../../assets/icons/Bus";
import Calendar from "../../assets/icons/Calendar";
import ExternalLink from "../../assets/icons/ExternalLink";
import Menu from "../../assets/icons/Menu";
import Breadcrumbs from "../../components/Breadcrumbs";
Expand Down Expand Up @@ -336,7 +335,8 @@ const ListSessions = ({ user, defaultCohortName }) => {
Cohort: selectedCohort,
Nom: item.name,
Adresse: item.address,
"Complément d'adresse": item?.complementAddress.find((e) => e.cohort === selectedCohort)?.complement || "",
// TODO: à supprimer lorsque le PDR sera dissocié de la session
"Complément d'adresse": getParticularitesAcces(item, selectedCohort) || "",
Ville: item.city,
"Code postal": item.zip,
Département: item.department,
Expand Down
2 changes: 1 addition & 1 deletion admin/src/scenes/pointDeRassemblement/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
canViewMeetingPointId,
isPdrEditionOpen,
PointDeRassemblementType,
departmentToAcademy,
} from "snu-lib";
import { AddressForm } from "@snu/ds/common";
// @ts-ignore
Expand Down Expand Up @@ -479,6 +478,7 @@ export default function View(props) {
<Field
label="Complément d’adresse"
onChange={(e) => handleChangeComplement(e.target.value)}
// TODO: champ à supprimer une fois le PDR dissocié de la cohort
value={pdr.complementAddress.find((c) => c.cohort === currentCohort)?.complement || ""}
readOnly={!editSession}
/>
Expand Down
12 changes: 6 additions & 6 deletions api/src/young/youngCertificateService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CohesionCenterModel, SessionPhase1Model, CohortModel, LigneBusModel, LigneToPointModel, PointDeRassemblementModel, DepartmentServiceModel } from "../models";
import { YoungDto, PointDeRassemblementType, CohesionCenterType } from "snu-lib";
import { YoungDto, PointDeRassemblementType, CohesionCenterType, getParticularitesAcces } from "snu-lib";

export const getMeetingAddress = (young: YoungDto, meetingPoint: PointDeRassemblementType, center: CohesionCenterType) => {
if (young.deplacementPhase1Autonomous === "true" || !meetingPoint) return `${center.address} ${center.zip} ${center.city}`;
const complement = meetingPoint?.complementAddress.find((c) => c.cohort === young.cohort);
const complementText = complement?.complement ? ", " + complement.complement : "";
return meetingPoint.name + ", " + meetingPoint.address + " " + meetingPoint.zip + " " + meetingPoint.city + complementText;
export const getMeetingAddress = (young: YoungDto, pdr: PointDeRassemblementType, centre: CohesionCenterType) => {
if (young.deplacementPhase1Autonomous === "true" || !pdr) return `${centre.address} ${centre.zip} ${centre.city}`;
const complement = getParticularitesAcces(pdr, young.cohort);
const complementText = complement ? ", " + complement : "";
return `${pdr.name}, ${pdr.address} ${pdr.zip} ${pdr.city}${complementText}`;
};

export const getCertificateTemplate = (young: YoungDto) => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { YoungType } from "snu-lib";

import { authActions } from "./actions";

export type AuthState = {
// TODO: use API route response
Auth: {
young: YoungType;
};
};

const initState = {
young: null,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ import React from "react";
import { FiMail } from "react-icons/fi";
import { useSelector } from "react-redux";
import { Modal } from "reactstrap";
import Calendar from "../../../../assets/calendar";
import ChevronDown from "../../../../assets/icons/ChevronDown";
import Download from "../../../../assets/icons/Download";
import api from "../../../../services/api";
import downloadPDF from "../../../../utils/download-pdf";
import { toastr } from "react-redux-toastr";
import { getReturnDate, getReturnHour, translate } from "snu-lib";
import { capture } from "../../../../sentry";
import dayjs from "dayjs";
import { toastr } from "react-redux-toastr";

import { getParticularitesAcces, getReturnDate, getReturnHour, translate } from "snu-lib";

import api from "@/services/api";
import { capture } from "@/sentry";
import { AuthState } from "@/redux/auth/reducer";
import downloadPDF from "@/utils/download-pdf";

import Calendar from "@/assets/calendar";
import ChevronDown from "@/assets/icons/ChevronDown";
import Download from "@/assets/icons/Download";

export default function InfoConvocation({ isOpen, onCancel, title, meetingPoint, session, center, cohort }) {
const young = useSelector((state) => state.Auth.young) || {};
const young = useSelector((state: AuthState) => state.Auth.young) || {};

const [selectOpen, setSelectOpen] = React.useState(false);
const refSelect = React.useRef(null);
const refSelect = React.useRef<HTMLDivElement>(null);
const returnDate = getReturnDate(young, session, cohort, meetingPoint);
const returnHour = getReturnHour(meetingPoint);
const [loadingConvocation, setLoadingConvocation] = React.useState(false);
Expand Down Expand Up @@ -64,11 +69,11 @@ export default function InfoConvocation({ isOpen, onCancel, title, meetingPoint,
if (young.deplacementPhase1Autonomous === "true" || !meetingPoint?.address) {
return [center?.name, center?.address, center?.zip, center?.city, center?.department, center?.region].filter((e) => e).join(", ");
} else {
let address = [meetingPoint.address];
const address = [meetingPoint.address];

let complement = meetingPoint.complementAddress ? meetingPoint.complementAddress.find((c) => c.cohort === young.cohort) : null;
if (complement && complement.complement) {
complement = complement.complement.trim();
let complement = getParticularitesAcces(meetingPoint, young.cohort) || null;
if (complement) {
complement = complement.trim();
if (complement.length === 0) {
complement = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,32 @@ import dayjs from "dayjs";
import { supportURL } from "../../../../../config";
import api from "../../../../../services/api";
import { translate } from "../../../../../utils";
import { getMeetingHour, getReturnHour, transportDatesToString, htmlCleaner } from "snu-lib";
import { getMeetingHour, getReturnHour, transportDatesToString, htmlCleaner, getParticularitesAcces, DepartmentServiceType } from "snu-lib";
import useAuth from "@/services/useAuth";

import Loader from "../../../../../components/Loader";
import { Hero, Content } from "../../../../../components/Content";

export default function Convocation({ center, meetingPoint, departureDate, returnDate }) {
const { young, isCLE } = useAuth();
const history = useHistory();
const [service, setService] = useState();
const { young, isCLE } = useAuth();

const [service, setService] = useState<DepartmentServiceType>();

useEffect(() => {
if (young?.department && !service) getService();
}, [young]);

const getService = async () => {
const { data, code, ok } = await api.get(`/department-service/${young.department}`);
if (!ok) return toastr.error("error", translate(code));
setService(data);
};

useEffect(() => {
if (young?.department && !service) getService();
}, [young]);

const getMeetingAddress = () => {
if (young.deplacementPhase1Autonomous === "true" || !meetingPoint) return `${center.address} ${center.zip} ${center.city}`;
const complement = meetingPoint?.complementAddress.find((c) => c.cohort === young.cohort);
const complementText = complement?.complement ? ", " + complement.complement : "";
const complement = getParticularitesAcces(meetingPoint, young.cohort);
const complementText = complement ? ", " + complement : "";
return meetingPoint.name + ", " + meetingPoint.address + " " + meetingPoint.zip + " " + meetingPoint.city + complementText;
};

Expand Down Expand Up @@ -203,4 +204,3 @@ const Sign = styled.div`
font-weight: 500;
margin: 1rem;
`;

1 change: 1 addition & 0 deletions packages/lib/src/plandetransport/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./ligneService";
export * from "./pdrService";
8 changes: 8 additions & 0 deletions packages/lib/src/plandetransport/pdrService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { PointDeRassemblementType } from "../mongoSchema";

export const getParticularitesAcces = (pdr: PointDeRassemblementType, cohortName?: string) => {
if (!cohortName || !!pdr.matricule) {
return pdr.particularitesAcces;
}
return pdr.particularitesAcces || pdr?.complementAddress.find((c) => c.cohort === cohortName)?.complement;
};
Loading