Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
name="libelle"
label="Titre"
:label-visible="true"
:model-value="libelle"
:model-value="libelle as string"
:readonly="!props.modifiable"
:is-valid="libelleMeta.valid"
:error-message="libelleErrorMessage"
Expand Down Expand Up @@ -40,7 +40,7 @@
type="date"
label="Date de début"
:label-visible="true"
:model-value="dateDebut"
:model-value="dateDebut as string"
:readonly="!props.modifiable"
:is-valid="dateDebutMeta.valid"
:error-message="dateDebutErrorMessage"
Expand All @@ -54,7 +54,7 @@
type="date"
label="Date de fin"
:label-visible="true"
:model-value="dateFin"
:model-value="dateFin as string"
:readonly="!props.modifiable"
:is-valid="dateFinMeta.valid"
:error-message="dateFinErrorMessage"
Expand All @@ -77,7 +77,7 @@
<div class="fr-fieldset">
<div class="fr-fieldset__element fr-col-12">
<DsfrInputGroup
v-if="duree > 0"
v-if="Number(duree) > 0"
name="duree"
label="Durée du séjour (en jours)"
:label-visible="true"
Expand All @@ -102,12 +102,10 @@
@update:personne="onResponsableSejourChange"
></Personne>
</div>
<div
v-if="organismeStore.organismeCourant.typeOrganisme === 'personne_morale'"
>
<div v-if="props.initOrganisme.typeOrganisme === 'personne_morale'">
<h3>Organisme</h3>
<OrganismePersonneMorale
:init-data="organismeStore.organismeCourant.personneMorale"
:init-data="props.initOrganisme?.personneMorale"
:show-responsable-sejour="false"
:show-buttons="false"
:modifiable="false"
Expand All @@ -116,6 +114,7 @@
v-if="organismeStore.isSiegeSocial"
:modifiable="false"
:show-buttons="false"
:init-organisme="props.initOrganisme"
/>
</div>

Expand All @@ -135,18 +134,21 @@
</div>
</template>

<script setup>
<script setup lang="ts">
import { useField, useForm } from "vee-validate";
import * as yup from "yup";
import dayjs from "dayjs";
import { IsDownloading } from "@vao/shared-ui";
import { DsfrAlert } from "@gouvminint/vue-dsfr";

const props = defineProps({
initData: {
type: Object,
required: true,
},
initOrganisme: {
type: Object,
required: true,
},
modifiable: { type: Boolean, default: true },
validateOnMount: { type: Boolean, default: false },
showButtons: { type: Boolean, default: true },
Expand All @@ -170,12 +172,12 @@ const statutsAfficheRappel = [
];

const duree = computed(() => {
const nbjours = dayjs(dateFin.value).diff(dateDebut.value, "day") + 1;
const nbjours = dayjs(dateFin.value as string).diff(dayjs(dateDebut.value as string), "day") + 1;
return nbjours.toString();
});

const periode = computed(() => {
const moisDebut = dayjs(dateDebut.value).month();
const moisDebut = dayjs(dateDebut.value as string).month();
if (moisDebut < 3) return "hiver";
if (moisDebut < 6) return "printemps";
if (moisDebut < 9) return "été";
Expand All @@ -186,19 +188,7 @@ const periode = computed(() => {
const validationSchema = yup.object(DeclarationSejour.baseSchema);

const initialValues = (() => {
const responsableSejour =
props.initData.responsableSejour ??
(organismeStore.organismeCourant.typeOrganisme === "personne_morale"
? organismeStore.organismeCourant.personneMorale.responsableSejour
: {
nom: organismeStore.organismeCourant.personnePhysique.nomNaissance,
prenom: organismeStore.organismeCourant.personnePhysique.prenom,
fonction: "organisateur de séjour",
email: userStore.user.email,
telephone: organismeStore.organismeCourant.personnePhysique.telephone,
adresse:
organismeStore.organismeCourant.personnePhysique.adresseSiege,
});
const initResponsableSejour = initDataByOrganisme();
return {
libelle: props.initData.libelle,
dateDebut: props.initData.dateDebut
Expand All @@ -207,7 +197,7 @@ const initialValues = (() => {
dateFin: props.initData.dateFin
? dayjs(props.initData.dateFin).format("YYYY-MM-DD")
: dayjs().add(2, "month").add(7, "day").format("YYYY-MM-DD"),
responsableSejour,
responsableSejour: initResponsableSejour,
};
})();

Expand Down Expand Up @@ -235,13 +225,35 @@ const {
handleChange: onDateFinChange,
meta: dateFinMeta,
} = useField("dateFin");
interface ResponsableSejour {
nom?: string;
prenom?: string;
fonction?: string;
email?: string;
telephone?: string;
adresse?: string;
}

const { value: responsableSejour, handleChange: onResponsableSejourChange } =
useField("responsableSejour");
useField<ResponsableSejour>("responsableSejour");

defineExpose({
meta,
});

function initDataByOrganisme() {
return props.initOrganisme.typeOrganisme === "personne_morale"
? props.initOrganisme.personneMorale?.responsableSejour
: {
nom: props.initOrganisme?.personnePhysique?.nomNaissance,
prenom: props.initOrganisme?.personnePhysique?.prenom,
fonction: "organisateur de séjour",
email: userStore?.user?.email,
telephone: props.initOrganisme?.personnePhysique?.telephone,
adresse: props.initOrganisme?.personnePhysique?.adresseSiege,
};
}

function next() {
if (!props.modifiable) {
return emit("next");
Expand Down
61 changes: 34 additions & 27 deletions packages/frontend-usagers/src/components/DS/synthese.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<DsfrAccordionsGroup v-model="expandedIndex">
<ul role="list">
<li v-if="stepToDisplay('info-generales')" role="listitem">
<DsfrAccordion :id="1" title="Informations générales">
<DsfrAccordion :id="'1'" title="Informations générales">
<template #title>
<span>Informations générales&nbsp;</span>
<DsfrBadge
Expand All @@ -16,14 +16,15 @@
<DSInformationsGenerales
ref="sectionInformationsGenerales"
:init-data="props.declarationCourante"
:init-organisme="props.initOrganisme"
:validate-on-mount="true"
:modifiable="false"
:show-buttons="false"
></DSInformationsGenerales>
</DsfrAccordion>
</li>
<li v-if="stepToDisplay('info-vacanciers')" role="listitem">
<DsfrAccordion :id="2" title="Informations sur les vacanciers">
<DsfrAccordion :id="'2'" title="Informations sur les vacanciers">
<template #title>
<span>Informations sur les vacanciers&nbsp;</span>
<DsfrBadge
Expand All @@ -44,7 +45,7 @@
</DsfrAccordion>
</li>
<li v-if="stepToDisplay('info-personnel')" role="listitem">
<DsfrAccordion :id="3" title="Informations sur le personnel">
<DsfrAccordion :id="'3'" title="Informations sur le personnel">
<template #title>
<span>Informations sur le personnel&nbsp;</span>
<DsfrBadge
Expand All @@ -65,7 +66,7 @@
</DsfrAccordion>
</li>
<li v-if="stepToDisplay('projet-sejour')" role="listitem">
<DsfrAccordion :id="4" title="Projet de séjour">
<DsfrAccordion :id="'4'" title="Projet de séjour">
<template #title>
<span>Projet de séjour &nbsp;</span>
<DsfrBadge
Expand All @@ -83,7 +84,7 @@
</DsfrAccordion>
</li>
<li v-if="stepToDisplay('info-transport')" role="listitem">
<DsfrAccordion :id="5" title="Informations sur le transport">
<DsfrAccordion :id="'5'" title="Informations sur le transport">
<template #title>
<span>Informations sur le transport &nbsp;</span>
<DsfrBadge
Expand All @@ -103,7 +104,7 @@
</DsfrAccordion>
</li>
<li v-if="stepToDisplay('info-sanitaires')" role="listitem">
<DsfrAccordion :id="6" title="Informations sanitaires">
<DsfrAccordion :id="'6'" title="Informations sanitaires">
<template #title>
<span>Informations sanitaires &nbsp;</span>
<DsfrBadge
Expand Down Expand Up @@ -144,10 +145,10 @@
>
<DsfrAccordion
:id="'synthese-hebergement-' + index"
:title="`Fiche annexe n°${index + 1}`"
:title="`Fiche annexe n°${Number(index) + 1}`"
>
<template #title>
<span>Fiche annexe n°{{ index + 1 }} &nbsp;</span>
<span>Fiche annexe n°{{ Number(index) + 1 }} &nbsp;</span>
<DsfrBadge
:label="validateHebergement(index).label"
:small="true"
Expand Down Expand Up @@ -186,6 +187,7 @@
label="Je certifie sur l'honneur que les renseignements portés sur cette déclaration sont exacts."
:small="true"
:disabled="!props.modifiable"
:value="true"
@update:model-value="onACertifieChange"
/>
</div>
Expand All @@ -197,7 +199,7 @@
readonly
:label-visible="true"
placeholder=""
:model-value="nom"
:model-value="nom as string"
/>
</div>

Expand All @@ -208,7 +210,7 @@
readonly
:label-visible="true"
placeholder=""
:model-value="prenom"
:model-value="prenom as string"
/>
</div>

Expand All @@ -219,8 +221,8 @@
:readonly="!props.modifiable"
:label-visible="true"
placeholder=""
:model-value="qualite"
:error-message="qualiteErrorMessage && qualiteMeta.touched"
:model-value="qualite as string"
:error-message="qualiteMeta.touched ? qualiteErrorMessage : undefined"
:is-valid="qualiteMeta"
@update:model-value="onQualiteChange"
/>
Expand All @@ -234,7 +236,7 @@
readonly
:label-visible="true"
placeholder=""
:model-value="at"
:model-value="at ? String(at) : ''"
/>
</div>
</div>
Expand Down Expand Up @@ -270,22 +272,23 @@
</div>
</template>

<script setup>
<script setup lang="ts">
import * as yup from "yup";
import { useField, useForm } from "vee-validate";
import dayjs from "dayjs";
import { IsDownloading } from "@vao/shared-ui";

const props = defineProps({
declarationCourante: { type: Object, default: null, required: true },
declarationCourante: { type: Object, default: null },
initOrganisme: { type: Object, default: null },
modifiable: { type: Boolean, default: true },
isDownloading: { type: Boolean, required: false, default: false },
message: { type: String, required: false, default: null },
});

const emit = defineEmits(["previous", "finalize"]);
const expandedIndex = ref(-1);
const subExpandedIndex = ref(-1);
const expandedIndex = ref(Number(-1));
const subExpandedIndex = ref<number>(-1);

const userStore = useUserStore();
const demandeSejourStore = useDemandeSejourStore();
Expand All @@ -298,8 +301,8 @@ const initialValues = {
attestation: {
...(props.declarationCourante.attestation ?? {}),
...(props.modifiable && {
nom: userStore.user.nom,
prenom: userStore.user.prenom,
nom: userStore?.user?.nom,
prenom: userStore?.user?.prenom,
aCertifie: false,
at: dayjs(new Date()).format("YYYY-MM-DD"),
}),
Expand Down Expand Up @@ -333,17 +336,17 @@ const {
} = useField("attestation.qualite");
const { value: at } = useField("attestation.at");

const success = {
const success: { label: string; type: "success" } = {
label: "complet",
type: "success",
};

const failure = {
const failure: { label: string; type: "warning" } = {
label: "incomplet",
type: "warning",
};

const sectionInformationsGenerales = ref(null);
const sectionInformationsGenerales = ref<any>(null);

const informationsGenerales = computed(() =>
sectionInformationsGenerales.value?.meta.valid ? success : failure,
Expand Down Expand Up @@ -403,21 +406,25 @@ const libelleBoutonTransmission = computed(() => {
return "";
});

function validateHebergement(index) {
interface ValidationResult {
label: string;
type: "success" | "warning";
}

function validateHebergement(index: number): ValidationResult {
return !Object.keys(errors.value).find((k) =>
k.startsWith("hebergement.hebergements[" + index + "]"),
)
? success
: failure;
}

function stepToDisplay(step) {
function stepToDisplay(step: string): boolean {
const statutsMasques = demandeSejourMenus.find(
(menu) => menu.id === step,
(menu: any) => menu.id === step,
)?.statutsMasques;
return !(statutsMasques && statutsMasques.includes(declarationStatut.value));
return !(statutsMasques && statutsMasques.includes(declarationStatut.value as string));
}

function finalizeDeclaration() {
emit("finalize", values.attestation);
}
Expand Down
Loading
Loading