Skip to content

Commit

Permalink
Met à jour l'app pour utiliser les ID des notes de suivi des fiches a…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
marc-rutkowski committed Dec 3, 2024
1 parent 734d832 commit 77885df
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useState } from 'react';
import {
Alert,
Button,
Expand All @@ -9,6 +8,7 @@ import {
Select,
Textarea,
} from '@tet/ui';
import { useState } from 'react';
import { EditedNote } from '../data/useUpsertNoteSuivi';

export const getYearsOptions = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ModaleEditionNote = ({
note.trim().length > 0 &&
(note !== editedNote.note || year !== initialYear)
) {
onEdit({ note, year });
onEdit({ id: editedNote.id, note, year });
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ModaleSuppressionNote = ({
btnCancelProps={{ onClick: close }}
btnOKProps={{
onClick: () => {
onDelete({ year });
onDelete({ id: editedNote.id });
close();
},
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useMutation, useQueryClient } from 'react-query';
import { FicheAction, FicheActionNote } from '@tet/api/plan-actions';
import { useApiClient } from 'core-logic/api/useApiClient';
import { useMutation, useQueryClient } from 'react-query';

export type EditedNote = Pick<FicheActionNote, 'note'> & { year: number };
export type DeletedNote = { year: number };
export type EditedNote = Pick<FicheActionNote, 'note'> & {
id?: number;
year: number;
};
export type DeletedNote = { id: number };

// renvoie une fonction de modification des notes de suivi
export const useUpsertNoteSuivi = ({
Expand All @@ -14,11 +17,13 @@ export const useUpsertNoteSuivi = ({
const queryClient = useQueryClient();

return useMutation(
async ({ note, year }: EditedNote) => {
async ({ id, note, year }: EditedNote) => {
return api.put({
route: `/collectivites/${collectiviteId}/fiches-action/${ficheId}/notes`,
params: {
notes: [{ note, dateNote: new Date(`${year}-01-01`).toISOString() }],
notes: [
{ id, note, dateNote: new Date(`${year}-01-01`).toISOString() },
],
},
});
},
Expand All @@ -45,10 +50,10 @@ export const useDeleteNoteSuivi = ({
const queryClient = useQueryClient();

return useMutation(
async ({ year }: DeletedNote) => {
async ({ id }: DeletedNote) => {
return api.delete({
route: `/collectivites/${collectiviteId}/fiches-action/${ficheId}/note`,
params: { dateNote: new Date(`${year}-01-01`).toISOString() },
params: { id },
});
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type JSONValue =
| number
| boolean
| null
| undefined
| { [x: string]: JSONValue }
| Array<JSONValue>;

Expand Down

0 comments on commit 77885df

Please sign in to comment.