Skip to content

Commit

Permalink
feat(modeles): ajout des autres références
Browse files Browse the repository at this point in the history
  • Loading branch information
m-maillot committed Oct 9, 2023
1 parent 0217bde commit 6df1b22
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 307 deletions.
19 changes: 10 additions & 9 deletions targets/frontend/src/components/contributions/answers/Answer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ import React, { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
import { useUser } from "src/hooks/useUser";

import { FormEditionField, FormRadioGroup, FormTextField } from "../../forms";
import {
FormEditionField,
FormLegiReferences,
FormOtherReferences,
FormRadioGroup,
FormTextField,
} from "../../forms";
import { StatusContainer } from "../status";
import { Answer, Status } from "../type";
import { useContributionAnswerUpdateMutation } from "./answer.mutation";
import { useContributionAnswerQuery } from "./answer.query";
import { Comments } from "./Comments";
import {
CdtnReferenceInput,
KaliReferenceInput,
LegiReferenceInput,
OtherReferenceInput,
} from "./references";
import { CdtnReferenceInput, KaliReferenceInput } from "./references";
import { statusesMapping } from "../status/data";
import { getNextStatus, getPrimaryButtonLabel } from "../status/utils";
import { SnackBar } from "../../utils/SnackBar";
Expand Down Expand Up @@ -228,12 +229,12 @@ export const ContributionsAnswer = ({
disabled={isNotEditable(answer)}
/>
)}
<LegiReferenceInput
<FormLegiReferences
name="legiReferences"
control={control}
disabled={isNotEditable(answer)}
/>
<OtherReferenceInput
<FormOtherReferences
name="otherReferences"
control={control}
disabled={isNotEditable(answer)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OperationResult, useMutation } from "urql";
import { useMutation } from "urql";

import { Comments } from "../type";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getRouteBySource } from "@socialgouv/cdtn-sources";
import { Control } from "react-hook-form";
import { CdtnReference } from "../../type";
import { useContributionSearchCdtnReferencesQuery } from "./cdtnReferencesSearch.query";
import { ReferenceInput } from "./ReferenceInput";
import { FormAutocompleteChips } from "src/components/forms";

type Props = {
name: string;
Expand All @@ -15,7 +15,7 @@ export const CdtnReferenceInput = ({
control,
disabled = false,
}: Props): React.ReactElement => (
<ReferenceInput<CdtnReference>
<FormAutocompleteChips<CdtnReference>
isMultiple={true}
label={`Contenus liés`}
color="info"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getRouteBySource } from "@socialgouv/cdtn-sources";
import { Control } from "react-hook-form";
import { Document } from "../../type";
import { ReferenceInput } from "./ReferenceInput";
import { useFicheSpSearchCdtnReferencesQuery } from "./ficheSpReferenceSearch.query";
import { FormAutocompleteChips } from "src/components/forms";

type Props = {
name: string;
Expand All @@ -15,7 +15,7 @@ export const FicheSpDocumentInput = ({
control,
disabled = false,
}: Props): React.ReactElement => (
<ReferenceInput<Document>
<FormAutocompleteChips<Document>
label={`Fiche service-public`}
color="info"
name={name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ import {
Stack,
TextField,
} from "@mui/material";
import { FormTextField } from "../../../forms";
import { AutocompleteFetcherResult, FormTextField } from "../../../forms";
import DeleteIcon from "@mui/icons-material/Delete";
import { useContributionSearchKaliReferenceQuery } from "./kaliReferencesSearch.query";
import { Agreement, Answer, KaliArticle } from "../../type";
import { Result } from "./ReferenceInput";
import { SimpleLink } from "../../../utils/SimpleLink";

type KaliReferenceSearchProps = {
idcc: string;
disabled?: boolean;
onAdd: (item: KaliArticle | null) => void;
fetcher: (idcc: string) => (query: string | undefined) => Result<KaliArticle>;
fetcher: (
idcc: string
) => (query: string | undefined) => AutocompleteFetcherResult<KaliArticle>;
};

const KaliReferenceSearch = ({
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQuery } from "urql";

import { CdtnReference, Document } from "../../type";
import { Result } from "./ReferenceInput";
import { AutocompleteFetcherResult } from "src/components/forms";

export type SearchCdtnReferencesQueryResult = {
documents: Document[];
Expand Down Expand Up @@ -47,7 +47,7 @@ query SearchCdtnReferences($sources: [String!], $slug: String, $title: String) {

export const useContributionSearchCdtnReferencesQuery = (
query: string | undefined
): Result<Pick<CdtnReference, "document">> => {
): AutocompleteFetcherResult<Pick<CdtnReference, "document">> => {
const slug = getSlugFromUrl(query);
const title = getNormalizedTitle(slug);
const [{ data, fetching, error }] = useQuery<SearchCdtnReferencesQueryResult>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Document } from "../../type";
import { Result } from "./ReferenceInput";
import {
SearchCdtnReferencesQuery,
SearchCdtnReferencesQueryResult,
getNormalizedTitle,
getSlugFromUrl,
SearchCdtnReferencesQuery,
SearchCdtnReferencesQueryResult,
} from "./cdtnReferencesSearch.query";
import { useQuery } from "urql";
import { AutocompleteFetcherResult } from "src/components/forms";

export const useFicheSpSearchCdtnReferencesQuery = (
query: string | undefined
): Result<Document> => {
): AutocompleteFetcherResult<Document> => {
const slug = getSlugFromUrl(query);
const title = getNormalizedTitle(slug);
const [{ data, fetching, error }] = useQuery<SearchCdtnReferencesQueryResult>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export * from "./KaliReferenceInput";
export * from "./LegiReferenceInput";
export * from "./CdtnReferenceInput";
export * from "./OtherReferenceInput";
Loading

0 comments on commit 6df1b22

Please sign in to comment.