|
1 | 1 | import React, { useState } from 'react'; |
2 | 2 |
|
| 3 | +import { isZodType } from '@douglasneuroinformatics/libjs'; |
3 | 4 | import { Button, FileDropzone, Heading, Spinner } from '@douglasneuroinformatics/libui/components'; |
4 | 5 | import { useDownload, useNotificationsStore, useTranslation } from '@douglasneuroinformatics/libui/hooks'; |
5 | 6 | import type { AnyUnilingualFormInstrument } from '@opendatacapture/runtime-core'; |
6 | | -import { BadgeHelpIcon, DownloadIcon } from 'lucide-react'; |
| 7 | +import { BadgeHelpIcon, CircleAlertIcon, DownloadIcon } from 'lucide-react'; |
7 | 8 | import { useParams } from 'react-router-dom'; |
8 | 9 |
|
9 | 10 | import { PageHeader } from '@/components/PageHeader'; |
@@ -107,44 +108,56 @@ export const UploadPage = () => { |
107 | 108 | </Heading> |
108 | 109 | </PageHeader> |
109 | 110 | {!isLoading ? ( |
110 | | - <div className="mx-auto flex w-full max-w-3xl grow flex-col justify-center"> |
111 | | - <FileDropzone |
112 | | - acceptedFileTypes={{ |
113 | | - 'text/csv': ['.csv'] |
114 | | - }} |
115 | | - className="flex h-80 w-full flex-col" |
116 | | - file={file} |
117 | | - setFile={setFile} |
118 | | - /> |
119 | | - <div className="mt-4 flex justify-between space-x-2"> |
120 | | - <Button disabled={!(file && instrument)} variant={'primary'} onClick={() => void handleInstrumentCSV()}> |
121 | | - {t('core.submit')} |
122 | | - </Button> |
123 | | - <div className="flex justify-between space-x-1"> |
124 | | - <Button className="gap-1" disabled={!instrument} variant={'primary'} onClick={handleTemplateDownload}> |
125 | | - <DownloadIcon /> |
126 | | - {t({ |
127 | | - en: 'Download Template', |
128 | | - fr: 'Télécharger le modèle' |
129 | | - })} |
130 | | - </Button> |
131 | | - <Button |
132 | | - className="gap-1" |
133 | | - disabled={!instrument} |
134 | | - variant={'primary'} |
135 | | - onClick={() => { |
136 | | - window.open('https://opendatacapture.org/en/docs/guides/how-to-upload-data/'); |
137 | | - }} |
138 | | - > |
139 | | - <BadgeHelpIcon /> |
140 | | - {t({ |
141 | | - en: 'Help', |
142 | | - fr: 'Aide' |
143 | | - })} |
| 111 | + isZodType(instrument.validationSchema, { version: 4 }) ? ( |
| 112 | + <div className="mb-2 flex items-center gap-2 rounded-md bg-red-300 p-4 dark:bg-red-800"> |
| 113 | + <CircleAlertIcon style={{ height: '20px', strokeWidth: '2px', width: '20px' }} /> |
| 114 | + <h5 className="font-medium tracking-tight"> |
| 115 | + {t({ |
| 116 | + en: 'Upload is Not Supported for Zod v4 Instruments', |
| 117 | + fr: "Le téléchargement n'est pas pris en charge pour les instruments utilisant Zod v4" |
| 118 | + })} |
| 119 | + </h5> |
| 120 | + </div> |
| 121 | + ) : ( |
| 122 | + <div className="mx-auto flex w-full max-w-3xl grow flex-col justify-center"> |
| 123 | + <FileDropzone |
| 124 | + acceptedFileTypes={{ |
| 125 | + 'text/csv': ['.csv'] |
| 126 | + }} |
| 127 | + className="flex h-80 w-full flex-col" |
| 128 | + file={file} |
| 129 | + setFile={setFile} |
| 130 | + /> |
| 131 | + <div className="mt-4 flex justify-between space-x-2"> |
| 132 | + <Button disabled={!(file && instrument)} variant={'primary'} onClick={() => void handleInstrumentCSV()}> |
| 133 | + {t('core.submit')} |
144 | 134 | </Button> |
| 135 | + <div className="flex justify-between space-x-1"> |
| 136 | + <Button className="gap-1" disabled={!instrument} variant={'primary'} onClick={handleTemplateDownload}> |
| 137 | + <DownloadIcon /> |
| 138 | + {t({ |
| 139 | + en: 'Download Template', |
| 140 | + fr: 'Télécharger le modèle' |
| 141 | + })} |
| 142 | + </Button> |
| 143 | + <Button |
| 144 | + className="gap-1" |
| 145 | + disabled={!instrument} |
| 146 | + variant={'primary'} |
| 147 | + onClick={() => { |
| 148 | + window.open('https://opendatacapture.org/en/docs/guides/how-to-upload-data/'); |
| 149 | + }} |
| 150 | + > |
| 151 | + <BadgeHelpIcon /> |
| 152 | + {t({ |
| 153 | + en: 'Help', |
| 154 | + fr: 'Aide' |
| 155 | + })} |
| 156 | + </Button> |
| 157 | + </div> |
145 | 158 | </div> |
146 | 159 | </div> |
147 | | - </div> |
| 160 | + ) |
148 | 161 | ) : ( |
149 | 162 | <> |
150 | 163 | <div className="mx-auto flex w-full max-w-3xl grow flex-col justify-center"> |
|
0 commit comments