Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

feat: Ajout d'une section "Temps passé" dans le formulaire d'édition d'un service #446

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 26 additions & 8 deletions src/lib/components/forms/fields/basic-input-field.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import FieldWrapper from "../field-wrapper.svelte";

export let id: string;
export let value: string | undefined = undefined;
export let value: string | number | undefined = undefined;

export let type: "email" | "tel" | "text" | "url" | "date" | "number" =
"text";
Expand All @@ -30,18 +30,34 @@
let phoneValue = value;
function handlePhoneChange() {
if (phoneValue) {
phoneValue = phoneValue.replace(/[^0-9]/g, "");
phoneValue = phoneValue.toString().replace(/[^0-9]/g, "");
}
value = phoneValue;
}
function handlePhoneBlur() {
if (phoneValue) {
phoneValue = formatPhoneNumber(phoneValue);
phoneValue = formatPhoneNumber(phoneValue.toString());
}
}
function handlePhoneFocus() {
if (phoneValue) {
phoneValue = phoneValue.replace(/[^0-9]/g, "");
phoneValue = phoneValue.toString().replace(/[^0-9]/g, "");
}
}

function handleNumberInput(event) {
if (event.target.value && event.target.value.length > 0) {
value = event.target.value.replace(/[^0-9]/g, "");
} else {
value = undefined
}
}
function handleNumberBlur() {
value = Number(value)
}
function handleNumberFocus() {
if (value) {
value = Number(value)
}
}

Expand Down Expand Up @@ -99,8 +115,10 @@
<input
type="number"
bind:value
on:blur={onBlur}
on:change={onChange}
Comment on lines -102 to -103
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: en plus des conversions, ne devrait-on pas également toujours appeler le onBlur() et le onChange() du FieldWrapper afin que la validation du schéma se fasse ?

inputmode="numeric"
on:input={handleNumberInput}
on:blur={handleNumberBlur}
on:focus={handleNumberFocus}
{...props}
/>
{:else if type === "email"}
Expand Down Expand Up @@ -136,9 +154,9 @@
{#if value && maxLength != null && !readonly && !disabled}
<div
class="mt-s4 self-end text-f12 text-gray-text-alt"
class:text-error={value.length > maxLength}
class:text-error={value.toString().length > maxLength}
>
{value.length}/{maxLength} caractères
{value.toString().length}/{maxLength} caractères
</div>
{/if}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script lang="ts">
import FieldSet from "$lib/components/display/fieldset.svelte";
import BasicInputField from "$lib/components/forms/fields/basic-input-field.svelte";
import type { Service } from "$lib/types";

export let service: Service;
</script>

<FieldSet title="Participation du bénéficiaire">
<BasicInputField
type="number"
id="spendingTimeTotalHours"
description="Nombre total d'heures investies par le bénéficiaire, ex : 18"
bind:value={service.spendingTimeTotalHours}
/>

<BasicInputField
type="text"
id="spendingTimePrecision"
description="Précision sur la répartition des heures passées, ex : « 6h par semaine, pendant 3 semaines »"
bind:value={service.spendingTimePrecision}
/>
</FieldSet>
2 changes: 2 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ export interface Service {
slug: string;
source?: string;
status: ServiceStatus;
spendingTimeTotalHours?: number;
spendingTimePrecision: string;
structure: string;
structureInfo: ServiceStructure;
subcategories: string[];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/validation/schema-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function isBool(msg = "") {

export function isInteger(msg = "") {
return (name, value, _data) => ({
valid: Number.isInteger(value),
valid: !value || value === "" || Number.isInteger(value),
msg: msg || `Ce champ doit être un nombre entier`,
});
}
Expand Down
16 changes: 16 additions & 0 deletions src/lib/validation/schemas/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ export const serviceSchema: v.Schema = {
default: false,
rules: [v.isBool()],
},
spendingTimeTotalHours: {
label: "Temps passé",
default: false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Je mettrais plutôt "" comme valeur par défaut sachant que le champ de saisie sous-jacent gère une chaîne de caractères.

rules: [v.isInteger()],
},
spendingTimePrecision: {
label: "Précision sur le temps passé",
default: "",
maxLength: 60,
post: [v.trim],
rules: [v.isString(), v.maxStrLength(60)],
},
};

export const inclusionNumeriqueSchema: v.Schema = {
Expand Down Expand Up @@ -442,6 +454,8 @@ export const draftSchema: v.Schema = {
recurrence: serviceSchema.recurrence,
suspensionDate: serviceSchema.suspensionDate,
useInclusionNumeriqueScheme: serviceSchema.useInclusionNumeriqueScheme,
spendingTimeTotalHours: serviceSchema.spendingTimeTotalHours,
spendingTimePrecision: serviceSchema.spendingTimePrecision,
};

export const contribSchema: v.Schema = {
Expand Down Expand Up @@ -500,4 +514,6 @@ export const modelSchema: v.Schema = {
onlineForm: serviceSchema.onlineForm,
recurrence: serviceSchema.recurrence,
suspensionDate: serviceSchema.suspensionDate,
spendingTimeTotalHours: serviceSchema.spendingTimeTotalHours,
spendingTimePrecision: serviceSchema.spendingTimePrecision,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import FieldsDocuments from "../_common/fields-documents.svelte";
import FieldsInclusionNumerique from "../_common/fields-inclusion-numerique.svelte";
import FieldsModalities from "../_common/fields-modalities.svelte";
import FieldsParticipation from "$lib/components/specialized/services/fields-participation.svelte";
import FieldsPerimeter from "../_common/fields-perimeter.svelte";
import FieldsPeriodicity from "../_common/fields-periodicity.svelte";
import FieldsPlace from "$lib/components/specialized/services/fields-place.svelte";
Expand Down Expand Up @@ -240,6 +241,8 @@

<FieldsPlace bind:service {structure} {servicesOptions} />

<FieldsParticipation bind:service />

<FieldsContact bind:service />
</div>
{:else}
Expand Down