|
1 | | -"use client" |
2 | | -import { Upload as UploadDSFR } from "@codegouvfr/react-dsfr/Upload" |
3 | | -import { useCallback, useState } from "react" |
4 | | -import { useRouter } from "next/navigation" |
5 | | -import LoadingButton from "../Button/LoadingButton" |
| 1 | +import { Tile } from "@codegouvfr/react-dsfr/Tile" |
| 2 | +import { CallOut } from "@codegouvfr/react-dsfr/CallOut" |
6 | 3 | import styles from "./Upload.module.css" |
7 | 4 | import Link from "next/link" |
8 | | -import { uploadFile } from "../../serverFunctions/upload" |
9 | | -import Alert from "@codegouvfr/react-dsfr/Alert" |
| 5 | +import UploadPanel from "./UploadPanel" |
10 | 6 |
|
11 | 7 | const Upload = () => { |
12 | | - const [file, setFile] = useState<File | null>(null) |
13 | | - const [success, setSuccess] = useState(false) |
14 | | - const [error, setError] = useState("") |
15 | | - const [uploading, setUploading] = useState(false) |
16 | | - |
17 | | - const router = useRouter() |
18 | | - const upload = useCallback(() => { |
19 | | - setError("") |
20 | | - setSuccess(false) |
21 | | - setUploading(true) |
22 | | - if (file) { |
23 | | - uploadFile(file).then((error) => { |
24 | | - setUploading(false) |
25 | | - setFile(null) |
26 | | - if (error) { |
27 | | - setError(error) |
28 | | - } else { |
29 | | - setSuccess(true) |
30 | | - } |
31 | | - router.refresh() |
32 | | - }) |
33 | | - } |
34 | | - }, [file, router]) |
35 | | - |
36 | | - const sizeError = file ? file.size > 1 * 1024 * 1024 : false |
37 | 8 | return ( |
38 | | - <div className={success || error ? "" : styles.container}> |
39 | | - <Alert |
40 | | - className={success || error ? "" : styles.help} |
41 | | - title='Aide' |
42 | | - severity='info' |
43 | | - description={ |
44 | | - <> |
45 | | - <span>Vous souhaitez un modèle ?</span> |
46 | | - <br /> |
47 | | - <span> |
48 | | - <span className='fr-icon-arrow-right-s-fill' aria-hidden='true' />{" "} |
49 | | - <Link href='/exemple/exemple.xlsx' className='fr-link' prefetch={false}> |
50 | | - Téléchargez notre template Excel |
51 | | - </Link> |
52 | | - </span> |
53 | | - <br /> |
54 | | - <span> |
55 | | - <span className='fr-icon-arrow-right-s-fill' aria-hidden='true' />{" "} |
56 | | - <Link href='/exemple/exemple.csv' className='fr-link' prefetch={false}> |
57 | | - Téléchargez notre template CSV |
58 | | - </Link> |
59 | | - </span> |
60 | | - <br /> |
61 | | - <br /> |
62 | | - <span> |
63 | | - Comment concevoir un fichier de déclaration pour le portail ?{" "} |
64 | | - <Link href='/documentation' className='fr-link' prefetch={false}> |
65 | | - Consultez l'aide en ligne |
66 | | - </Link> |
67 | | - . |
68 | | - </span> |
69 | | - <br /> |
70 | | - <br /> |
71 | | - <span> |
72 | | - Si vous voulez faire un test avant de vous lancer, rejoignez{" "} |
73 | | - <Link |
74 | | - href='https://test-affichage-environnemental.ecobalyse.beta.gouv.fr/' |
75 | | - className='fr-link' |
76 | | - target='_blank' |
77 | | - rel='noopener noreferrer'> |
78 | | - le serveur de test |
79 | | - </Link> |
80 | | - . |
81 | | - </span> |
82 | | - <br /> |
83 | | - <br /> |
84 | | - <span> |
85 | | - Si vous avez besoin d’aide,{" "} |
86 | | - <Link |
87 | | - className='fr-link' |
88 | | - href={`mailto:${process.env.NEXT_PUBLIC_SUPPORT_MAIL}`} |
89 | | - prefetch={false} |
90 | | - target='_blank' |
91 | | - rel='noopener noreferrer'> |
92 | | - vous pouvez contacter le service support. |
93 | | - </Link> |
94 | | - </span> |
95 | | - </> |
96 | | - } |
97 | | - /> |
98 | | - {success || error ? ( |
99 | | - <Alert |
100 | | - data-testid={`upload-${success ? "success" : "error"}`} |
101 | | - className='fr-mt-4w' |
102 | | - title={ |
103 | | - success |
104 | | - ? "Votre fichier a été correctement téléchargé" |
105 | | - : "Une erreur est survenue lors de l'analyse du fichier" |
| 9 | + <div className={styles.layout}> |
| 10 | + <div> |
| 11 | + <h2>Nouvelle déclaration</h2> |
| 12 | + <p> |
| 13 | + Si vous souhaitez faire un test avant de vous lancer, rejoignez{" "} |
| 14 | + <Link |
| 15 | + href='https://test-affichage-environnemental.ecobalyse.beta.gouv.fr/' |
| 16 | + className='fr-link' |
| 17 | + target='_blank' |
| 18 | + rel='noopener noreferrer'> |
| 19 | + le serveur de test |
| 20 | + </Link>{" "} |
| 21 | + ou consultez les aides ci-contre. |
| 22 | + </p> |
| 23 | + <CallOut className='fr-mt-2w'> |
| 24 | + <span> |
| 25 | + Dans l'hypothèse où vous ne déclarez pas le champ "score", le calcul sera effectué automatiquement |
| 26 | + conformément à vos déclarations. Le score calculé demeure sous votre responsabilité. |
| 27 | + </span> |
| 28 | + <Link href='/documentation' className='fr-link' prefetch={false}> |
| 29 | + Consultez la méthode de calcul |
| 30 | + </Link> |
| 31 | + . |
| 32 | + </CallOut> |
| 33 | + <UploadPanel /> |
| 34 | + </div> |
| 35 | + <aside className={styles.aside}> |
| 36 | + <Tile |
| 37 | + className={styles.tile} |
| 38 | + orientation='horizontal' |
| 39 | + title='Télécharger un modèle Excel' |
| 40 | + titleAs='h3' |
| 41 | + imageUrl='/images/document.svg' |
| 42 | + small |
| 43 | + desc={ |
| 44 | + <> |
| 45 | + Le fichier type pour déclarer vos produits |
| 46 | + <span className={styles.tileMeta}>.xlsx - 13 Ko</span> |
| 47 | + </> |
106 | 48 | } |
107 | | - severity={success ? "success" : "error"} |
108 | | - description={ |
109 | | - success ? ( |
110 | | - <> |
111 | | - Le système va maintenant l’analyser pour vérifier qu’il contient l’ensemble des informations |
112 | | - réglementaires au bon format. Cette étape peut prendre quelques minutes en fonction de la taille de |
113 | | - votre CSV. <b>Une fois l’analyse terminée, vous recevrez un mail vous indiquant le résultat</b>. Vous |
114 | | - pouvez fermer cet onglet. |
115 | | - </> |
116 | | - ) : ( |
117 | | - <> |
118 | | - {error}. Si l'erreur persiste n'hesitez pas à nous envoyer votre fichier par mail, à l'adresse suivante, |
119 | | - pour analyse plus approfondie. |
120 | | - <br /> |
121 | | - <Link |
122 | | - className='fr-link' |
123 | | - href={`mailto:${process.env.NEXT_PUBLIC_SUPPORT_MAIL}`} |
124 | | - prefetch={false} |
125 | | - target='_blank' |
126 | | - rel='noopener noreferrer'> |
127 | | - {process.env.NEXT_PUBLIC_SUPPORT_MAIL} |
128 | | - </Link> |
129 | | - </> |
130 | | - ) |
| 49 | + linkProps={{ href: "/exemple/exemple.xlsx", download: true }} |
| 50 | + /> |
| 51 | + <Tile |
| 52 | + className={styles.tile} |
| 53 | + orientation='horizontal' |
| 54 | + title='Télécharger un modèle CSV' |
| 55 | + titleAs='h3' |
| 56 | + imageUrl='/images/document.svg' |
| 57 | + small |
| 58 | + desc={ |
| 59 | + <> |
| 60 | + Le fichier type pour déclarer vos produits |
| 61 | + <span className={styles.tileMeta}>.csv - 2 Ko</span> |
| 62 | + </> |
131 | 63 | } |
| 64 | + linkProps={{ href: "/exemple/exemple.csv", download: true }} |
| 65 | + /> |
| 66 | + <Tile |
| 67 | + className={styles.tile} |
| 68 | + orientation='horizontal' |
| 69 | + title='Comment concevoir un fichier de déclaration pour le portail ?' |
| 70 | + titleAs='h3' |
| 71 | + small |
| 72 | + desc="Consultez l'aide en ligne" |
| 73 | + linkProps={{ href: "/notice-reglementaire.pdf", target: "_blank", rel: "noopener noreferrer" }} |
132 | 74 | /> |
133 | | - ) : ( |
134 | | - <div className={styles.upload}> |
135 | | - <UploadDSFR |
136 | | - label='Déposez votre fichier pour déclarer vos produits.' |
137 | | - disabled={uploading} |
138 | | - hint='Format CSV ou XLSX, 1mb max' |
139 | | - state={sizeError ? "error" : "default"} |
140 | | - stateRelatedMessage={sizeError ? "Le fichier doit faire moins de 1mb" : ""} |
141 | | - nativeInputProps={{ |
142 | | - accept: ".csv, .xlsx", |
143 | | - onChange: (event) => setFile(event.target.files?.[0] || null), |
144 | | - }} |
145 | | - /> |
146 | | - <LoadingButton disabled={!file || sizeError} onClick={upload} loading={uploading} className={styles.button}> |
147 | | - Envoyer mon fichier pour validation |
148 | | - </LoadingButton> |
149 | | - </div> |
150 | | - )} |
| 75 | + </aside> |
151 | 76 | </div> |
152 | 77 | ) |
153 | 78 | } |
|
0 commit comments