Skip to content

Commit

Permalink
Merge pull request #11 from SocialGouv/feat/ajout-demande
Browse files Browse the repository at this point in the history
feat(ajout): ajout demande
  • Loading branch information
alebret authored Feb 1, 2023
2 parents 9efa448 + 8f0e097 commit b075119
Show file tree
Hide file tree
Showing 22 changed files with 8,477 additions and 128 deletions.
4 changes: 4 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ fileignoreconfig:
checksum: 1fa040cef27d48607572966b9f06bf23656c95d03dd4cf5aba2508f0218f3a48
- filename: README.md
checksum: 8dc48ffdeb5f0ff5987ed48bee751b2551d37960e8dbbfc7c951ed2f48347b4c
- filename: pages/ajout-demande.tsx
checksum: 9f3910cf12b854fa65fc88503bae817f7655f9cfea2e4c85ee3396adbd0f3a95
- filename: pages/api/auth/[...nextauth].ts
checksum: 8c1d12d8b6179d284cce19aa33eaed6839861d85da22b368ba22e19b437e52fb
- filename: pages/index.tsx
checksum: abc2a89b85d95e759866b9a7b53ba934aff7b2f65e453e3ef65954320a926b38
- filename: pages/mui.tsx
checksum: 65dd6ab0469f43924ffc92d26055de14a77b1ef873e0efe69a014b582c38b694
- filename: src/components/SelectDepartment.tsx
checksum: d8074633be1f7eb9bf5fbeb4f387ea7ea087b04a5675bff25e9e252dda5f6913
scopeconfig:
- scope: node
version: "1.0"
24 changes: 24 additions & 0 deletions codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { CodegenConfig } from '@graphql-codegen/cli';

/**
* `yarn run compile` pour mettre à jours le schema.
* process.env.NEXT_PUBLIC_API_URL ne fonctionne pas avec la cmd, il faut utiliser l'url
*/
const API_URL = "https://backoffice-env-1000jours-develop-91uqrtdu.dev.fabrique.social.gouv.fr"//process.env.NEXT_PUBLIC_API_URL

const config: CodegenConfig = {
schema: `${API_URL}/graphql?nocache`,
documents: ['src/**/*.tsx'],
generates: {
'./src/__generated__/': {
preset: 'client',
plugins: [],
presetConfig: {
gqlTagName: 'gql',
}
}
},
ignoreNoDocuments: true,
};

export default config;
5 changes: 2 additions & 3 deletions csp.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const ContentSecurityPolicy = `
default-src 'self' *.fabrique.social.gouv.fr;
default-src 'self' *.gouv.fr;
img-src 'self' data: *.fabrique.social.gouv.fr https://dummyimage.com/;
script-src 'self' *.fabrique.social.gouv.fr ${
process.env.NODE_ENV !== "production" && "'unsafe-eval' 'unsafe-inline'"
script-src 'self' *.fabrique.social.gouv.fr ${process.env.NODE_ENV !== "production" && "'unsafe-eval' 'unsafe-inline'"
};
frame-src 'self' *.fabrique.social.gouv.fr;
style-src 'self' 'unsafe-inline';
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
"storybook:deploy:action": "npm run storybook:build && gh-pages -d .out -u \"github-actions-bot <[email protected]>\"",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"postinstall": "is-ci || husky install"
"postinstall": "is-ci || husky install",
"compile": "graphql-codegen",
"watch": "graphql-codegen -w"
},
"dependencies": {
"@codegouvfr/react-dsfr": "^0.21.2",
"@apollo/client": "^3.7.5",
"@codegouvfr/react-dsfr": "^0.28.0",
"@emotion/react": "^11.10.5",
"@emotion/server": "^11.10.0",
"@emotion/styled": "^11.10.5",
Expand All @@ -40,15 +43,20 @@
"@sentry/nextjs": "^6.17.9",
"@socialgouv/matomo-next": "^1.4.0",
"axios": "^1.2.4",
"graphql": "^16.6.0",
"next": "13.1.6",
"next-auth": "^4.18.10",
"next-seo": "^5.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"sass": "^1.57.1",
"ts-node": "^10.9.1",
"tss-react": "^4.5.2"
},
"devDependencies": {
"@babel/core": "^7.17.5",
"@graphql-codegen/cli": "^2.16.4",
"@graphql-codegen/client-preset": "^1.2.6",
"@storybook/addon-actions": "^6.4.19",
"@storybook/addon-docs": "^6.5.15",
"@storybook/addon-essentials": "^6.4.19",
Expand Down Expand Up @@ -77,6 +85,6 @@
"node-talisman": "^1.28.0",
"start-server-and-test": "^1.14.0",
"storybook-dark-mode": "^2.0.5",
"typescript": "4.9.4"
"typescript": "^4.9.4"
}
}
19 changes: 18 additions & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import '../styles/global.css';

import { useEffect } from "react";
import { useRouter } from "next/router";
import type { AppProps } from "next/app";
Expand All @@ -17,6 +19,7 @@ import { Footer } from "@codegouvfr/react-dsfr/Footer";
import { init } from "@socialgouv/matomo-next";
import Head from "next/head";
import { SessionProvider } from "next-auth/react";
import { ApolloClient, ApolloProvider, InMemoryCache } from '@apollo/client';

// Only in TypeScript projects
declare module "@codegouvfr/react-dsfr" {
Expand Down Expand Up @@ -79,6 +82,11 @@ const bottomLinks = [
},
];

const client = new ApolloClient({
uri: `${process.env.NEXT_PUBLIC_API_URL}/graphql?nocache`,
cache: new InMemoryCache()
});

function App({ Component, pageProps }: AppProps) {
const { css } = useStyles();

Expand Down Expand Up @@ -124,6 +132,13 @@ function App({ Component, pageProps }: AppProps) {
},
isActive: router.asPath === "/",
},
{
text: "Ajouter une demande",
linkProps: {
href: "/ajout-demande",
},
isActive: router.asPath === "/ajout-demande",
},
{
text: "DSFR playground",
linkProps: {
Expand Down Expand Up @@ -151,7 +166,9 @@ function App({ Component, pageProps }: AppProps) {
})}
>
<SessionProvider session={pageProps.session}>
<Component {...pageProps} />
<ApolloProvider client={client} >
<Component {...pageProps} />
</ApolloProvider>
</SessionProvider>
</div>
<Footer
Expand Down
220 changes: 220 additions & 0 deletions pages/ajout-demande.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
import React, { Fragment, useEffect, useState } from "react";
import { useSession } from "next-auth/react";
import { useQuery } from '@apollo/client';

import { useStyles } from "tss-react/dsfr";
import { LoggedState } from "../src/components/LoggedState";
import DatabaseApi from "../src/services/api/database";
import { Enum_Demandedecontact_Type_De_Contact, WidgetEpdsSources } from "../src/__generated__/graphql";
import { sortWidgetSourceByName } from "../src/utils/main.util";
import { Departement } from "../types/geogouv";

import { SelectDepartment } from "../src/components/SelectDepartment";
import { Input } from "@codegouvfr/react-dsfr/Input";
import Select from "@codegouvfr/react-dsfr/Select";
import Button from "@codegouvfr/react-dsfr/Button";
import Alert from "@codegouvfr/react-dsfr/Alert";


export default function AjoutDemande() {
const { css } = useStyles();
const widthFitContent = css({ width: "fit-content" })

const { data: session, status } = useSession()
const [isLogged, setLogged] = useState<Boolean>()

const [widgetSources, setWidgetSources] = useState<WidgetEpdsSources[]>([])
const [selectedDepartment, setSelectedDepartment] = useState<Departement>()
const [selectedContactOrigin, setSelectedContactOrigin] = useState<String>()
const [selectedContactMode, setSelectedContactMode] = useState<String>()
const [selectedContactSupport, setSelectedContactSupport] = useState<String>()

useEffect(() => {
console.log(isLogged)
}, [isLogged])

useEffect(() => {
setLogged(status === "authenticated")
}, [status])

const { loading, data, error } = useQuery(
DatabaseApi.GET_WIDGET_SOURCES
);

useEffect(() => {
if (data) {
setWidgetSources(sortWidgetSourceByName([...data.widgetEpdsSources]))
}
}, [data])

const createNewContact = async (event: any) => {
// Stop the form from submitting and refreshing the page.
event.preventDefault()
const target = event.target

// Get data from the form.
const data = {
name: target.name.value,
childNumber: target.childNumber.value,
childBirthDate: target.childBirthDate.value,
department: selectedDepartment,
contactDate: target.contactDate.value,
contactOrigin: selectedContactOrigin,
contactMode: selectedContactMode,
contactSupport: selectedContactSupport,
comment: target.comment.value
}

// TODO: branchement back
}

return <div>
<LoggedState showButton={false} />

<Alert
title="Page en cours de développement"
severity="info"
/>

{isLogged &&
<form onSubmit={createNewContact}>
<Input
label="Prénom"
nativeInputProps={{
id: "name"
}} />

<Input
label="Nombre d'enfants"
className={widthFitContent}
nativeInputProps={{
type: "number",
id: "childNumber"
}} />

<Input
label="Date de naissance du dernier enfant"
className={widthFitContent}
nativeInputProps={{
type: "date",
id: "childBirthDate"
}} />

<SelectDepartment setSelectedDepartment={setSelectedDepartment} />

<Input
label="Date de prise de contact"
className={widthFitContent}
nativeInputProps={{
type: "date",
id: "contactDate"
}} />

<Select
label="Provenance du contact"
nativeSelectProps={{
onChange: event => setSelectedContactOrigin(event.target.value),
}}
>
<Fragment key=".0">
<option
disabled
hidden
selected
value=""
>
Sélectionnez une option
</option>
{widgetSources.map((source, index) => (
<option key={index} value={source.nom}>{source.nom}</option>
))}
</Fragment>
</Select>

<ContactModeComponent
label="Mode de prise de contact"
setSelectedContactMode={setSelectedContactMode} />

<ContactSupportComponent
label="La personne contactée a-t'elle été accompagnée ?"
setSelectedContactSupport={setSelectedContactSupport}
/>

<Input
label="Commentaire"
textArea
nativeTextAreaProps={{
id: "comment"
}} />

<Button type="submit" onClick={() => { }}>Créer le contact</Button>
</form>
}
</div>
}

export type ContactModeComponentProps = {
label: string;
setSelectedContactMode: (arg: string) => void
};

export type ContactSupportComponentProps = {
label: string;
setSelectedContactSupport: (arg: string) => void
};


// A remplacer par le composant RadioButton de la lib @codegouvfr/react-dsfr lorsqu'il sera disponible
const ContactModeComponent = ({ label, setSelectedContactMode }: ContactModeComponentProps): JSX.Element => {
const typeContactList = Object.values(Enum_Demandedecontact_Type_De_Contact)

const handleContactMode = (event: any) => {
setSelectedContactMode(event.target.value)
}

return (
<div className="fr-form-group">
<fieldset className="fr-fieldset fr-fieldset--inline">
<legend className="fr-fieldset__legend fr-text--regular" id='radio-inline-legend'>
{label}
</legend>
<div className="fr-fieldset__content" onChange={handleContactMode}>
{typeContactList.map((type, index) => (
<div className="fr-radio-group" key={index}>
<input type="radio" id={`radio-mode-${index}`} name="radio-mode" value={type} />
<label className="fr-label" htmlFor={`radio-mode-${index}`}>{type}
</label>
</div>
))}
</div>
</fieldset >
</div >
)
}

const ContactSupportComponent = ({ label, setSelectedContactSupport }: ContactSupportComponentProps): JSX.Element => {
const supportList = ["Orientée", "Aidée", "Petit échange initial", "Non accompagnée"]

const handleContactSupport = (event: any) => {
setSelectedContactSupport(event.target.value)
}

return (
<div className="fr-form-group">
<fieldset className="fr-fieldset fr-fieldset--inline">
<legend className="fr-fieldset__legend fr-text--regular" id='radio-inline-legend'>
{label}
</legend>
<div className="fr-fieldset__content" onChange={handleContactSupport}>
{supportList.map((item, index) => (
<div className="fr-radio-group" key={index}>
<input type="radio" id={`radio-support-${index}`} name="radio-support" value={item} />
<label className="fr-label" htmlFor={`radio-support-${index}`}>{item}
</label>
</div>
))}
</div>
</fieldset >
</div >
)
}
2 changes: 1 addition & 1 deletion pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NextAuth, { User } from 'next-auth'
import NextAuth from 'next-auth'
import CredentialsProvider from 'next-auth/providers/credentials'
import axios from 'axios'
import { StrapiUser } from '../../../types/StrapiType';
Expand Down
Loading

0 comments on commit b075119

Please sign in to comment.