Correction des types et amélioration de la gestion des erreurs dans les composants ThirdParty et ThirdPartyEdit

This commit is contained in:
Boris Waaub
2026-02-04 14:48:33 +01:00
parent 454aad7ed1
commit 23369197e7
4 changed files with 26 additions and 29 deletions

View File

@@ -308,7 +308,7 @@ export interface AccompanyingPeriodWorkEvaluation {
documents: AccompanyingPeriodWorkEvaluationDocument[];
endDate: DateTime | null;
evaluation: Evaluation | null;
id: number | null;
id: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
key: any;
maxDate: DateTime | null;
@@ -445,31 +445,31 @@ export type EntitiesOrMe = "me" | Entities;
export function isSuggestionForUserGroup(
s: Suggestion,
): s is Suggestion & { result: UserGroup } {
return (s as any)?.result?.type === "user_group";
return (s as Suggestion)?.result?.type === "user_group";
}
export function isSuggestionForUser(
s: Suggestion,
): s is Suggestion & { result: User } {
return (s as any)?.result?.type === "user";
return (s as Suggestion)?.result?.type === "user";
}
export function isSuggestionForPerson(
s: Suggestion,
): s is Suggestion & { result: Person } {
return (s as any)?.result?.type === "person";
return (s as Suggestion)?.result?.type === "person";
}
export function isSuggestionForThirdParty(
s: Suggestion,
): s is Suggestion & { result: Thirdparty } {
return (s as any)?.result?.type === "thirdparty";
return (s as Suggestion)?.result?.type === "thirdparty";
}
export function isSuggestionForHousehold(
s: Suggestion,
): s is Suggestion & { result: Household } {
return (s as any)?.result?.type === "household";
return (s as Suggestion)?.result?.type === "household";
}
export type AddPersonResult = Entities & {

View File

@@ -1,6 +1,5 @@
import {
Address,
Center,
Civility,
DateTime,
SetAddress,
@@ -8,6 +7,12 @@ import {
User,
} from "ChillMainAssets/types";
declare global {
interface Window {
addaddress: Record<string, unknown>;
}
}
export type ThirdPartyKind = "contact" | "child" | "company";
export interface BaseThirdParty {

View File

@@ -20,13 +20,7 @@
action === 'edit' || action === 'create' || action === 'addContact'
"
>
<ThirdPartyEdit
:id="id"
:type="type"
:action="action"
:query="query"
:parent="parent"
/>
<ThirdPartyEdit :id="id" :type="type" :action="action" :parent="parent" />
</div>
</template>

View File

@@ -41,7 +41,7 @@
</label>
</div>
</div>
<div v-else-if="resolvedParent">
<div v-if="resolvedParent">
<p>Contact de&nbsp;:</p>
<third-party-render-box
:thirdparty="resolvedParent"
@@ -152,6 +152,7 @@
<div
v-for="err in violations.violationTitles('name')"
class="invalid-feedback was-validated-force"
:key="err"
>
{{ err }}
</div>
@@ -191,6 +192,7 @@
<div
v-for="err in violations.violationTitles('name')"
class="invalid-feedback was-validated-force"
:key="err"
>
{{ err }}
</div>
@@ -238,6 +240,7 @@
<div
v-for="err in violations.violationTitles('email')"
class="invalid-feedback was-validated-force"
:key="err"
>
{{ err }}
</div>
@@ -266,6 +269,7 @@
<div
v-for="err in violations.violationTitles('telephone')"
class="invalid-feedback was-validated-force"
:key="err"
>
{{ err }}
</div>
@@ -294,6 +298,7 @@
<div
v-for="err in violations.violationTitles('telephone2')"
class="invalid-feedback was-validated-force"
:key="err"
>
{{ err }}
</div>
@@ -315,7 +320,7 @@
</template>
<script setup lang="ts">
import { ref, reactive, computed, onMounted, getCurrentInstance } from "vue";
import { ref, reactive, computed, onMounted } from "vue";
import ThirdPartyRenderBox from "../Entity/ThirdPartyRenderBox.vue";
import AddAddress from "ChillMainAssets/vuejs/Address/components/AddAddress.vue";
import {
@@ -339,22 +344,16 @@ import {
THIRDPARTY_MESSAGES_THIRDPARTY_PROFESSION,
THIRDPARTY_MESSAGES_THIRDPARTY_CIVILITY,
THIRDPARTY_MESSAGES_CHILD_OF,
PERSON_EDIT_ERROR_WHILE_SAVING,
} from "translator";
import {
createPerson,
getCivilities,
WritePersonViolationMap,
} from "ChillPersonAssets/vuejs/_api/OnTheFly";
import { getCivilities } from "ChillPersonAssets/vuejs/_api/OnTheFly";
import {
isThirdpartyChild,
isThirdpartyCompany,
Thirdparty,
ThirdpartyCompany,
ThirdPartyKind,
ThirdPartyWrite,
} from "../../../types";
import { Civility, SetCivility } from "ChillMainAssets/types";
import { Civility, TranslatableString } from "ChillMainAssets/types";
import { isValidationException } from "ChillMainAssets/lib/api/apiMethods";
import { useViolationList } from "ChillMainAssets/vuejs/_composables/violationList";
import { useToast } from "vue-toast-notification";
@@ -371,7 +370,7 @@ interface ThirdPartyAddContactProps {
id?: null;
type?: "thirdparty";
action: "addContact";
query?: "";
query?: string;
parent: ThirdpartyCompany;
}
@@ -433,7 +432,6 @@ const addAddress = reactive({
title: { create: "add_an_address_title", edit: "edit_address" },
},
});
const addAddressRef = ref<any>(null);
/**
* We need a specific computed for the kind
@@ -448,11 +446,11 @@ const kind = computed<ThirdPartyKind>({
});
const context = computed(() => {
const ctx: any = {
const ctx: Record<string, unknown> = {
target: { name: props.type, id: props.id },
edit: false,
addressId: null as number | null,
defaults: (window as any).addaddress,
defaults: window.addaddress,
};
if (thirdParty.value.address) {
ctx.addressId = thirdParty.value.address.id;
@@ -496,7 +494,7 @@ const queryItems = computed(() => {
.filter((word) => !lastNameWords.includes(word.toLowerCase()));
});
function localizeString(str: any) {
function localizeString(str: TranslatableString): string {
return _localizeString(str);
}