codeforlife 2.8.2 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/dist/Countdown-DFI1RljW.js +28 -0
  2. package/dist/Countdown-DFI1RljW.js.map +1 -0
  3. package/dist/Countdown-zY3nMzmi.cjs +2 -0
  4. package/dist/Countdown-zY3nMzmi.cjs.map +1 -0
  5. package/dist/Image-D5jC9UoX.js +21 -0
  6. package/dist/Image-D5jC9UoX.js.map +1 -0
  7. package/dist/Image-mgT45r_B.cjs +2 -0
  8. package/dist/Image-mgT45r_B.cjs.map +1 -0
  9. package/dist/LinkButton-BYFkvL_O.cjs +2 -0
  10. package/dist/LinkButton-BYFkvL_O.cjs.map +1 -0
  11. package/dist/LinkButton-oK0RThqn.js +12 -0
  12. package/dist/LinkButton-oK0RThqn.js.map +1 -0
  13. package/dist/Navigate-Dq47aqC8.js +25 -0
  14. package/dist/Navigate-Dq47aqC8.js.map +1 -0
  15. package/dist/Navigate-dQocLhzN.cjs +2 -0
  16. package/dist/Navigate-dQocLhzN.cjs.map +1 -0
  17. package/dist/api/endpoints/index.cjs.js +2 -0
  18. package/dist/api/endpoints/index.cjs.js.map +1 -0
  19. package/dist/api/endpoints/index.d.ts +81 -0
  20. package/dist/api/endpoints/index.es.js +78 -0
  21. package/dist/api/endpoints/index.es.js.map +1 -0
  22. package/dist/api/index.cjs.js +4 -0
  23. package/dist/api/index.cjs.js.map +1 -0
  24. package/dist/api/index.d.ts +77 -0
  25. package/dist/api/index.es.js +541 -0
  26. package/dist/api/index.es.js.map +1 -0
  27. package/dist/api-Cbyt3rw0.js +92 -0
  28. package/dist/api-Cbyt3rw0.js.map +1 -0
  29. package/dist/api-CnMfjRk3.cjs +2 -0
  30. package/dist/api-CnMfjRk3.cjs.map +1 -0
  31. package/dist/api-Cs4Y-WeI.js +20 -0
  32. package/dist/api-Cs4Y-WeI.js.map +1 -0
  33. package/dist/api-DIgp_6Vr.cjs +2 -0
  34. package/dist/api-DIgp_6Vr.cjs.map +1 -0
  35. package/dist/api.d.ts +123 -0
  36. package/dist/auth-BPfUPjmM.js +237 -0
  37. package/dist/auth-BPfUPjmM.js.map +1 -0
  38. package/dist/auth-Vf1MgMci.cjs +2 -0
  39. package/dist/auth-Vf1MgMci.cjs.map +1 -0
  40. package/dist/auth.d.ts +40 -0
  41. package/dist/components/form/index.cjs.js +2 -0
  42. package/dist/components/form/index.cjs.js.map +1 -0
  43. package/dist/components/form/index.d.ts +86 -0
  44. package/dist/components/form/index.es.js +18 -0
  45. package/dist/components/form/index.es.js.map +1 -0
  46. package/dist/components/index.cjs.js +11 -0
  47. package/dist/components/index.cjs.js.map +1 -0
  48. package/dist/components/index.d.ts +90 -0
  49. package/dist/components/index.es.js +383 -0
  50. package/dist/components/index.es.js.map +1 -0
  51. package/dist/components/page/index.cjs.js +2 -0
  52. package/dist/components/page/index.cjs.js.map +1 -0
  53. package/dist/components/page/index.d.ts +77 -0
  54. package/dist/components/page/index.es.js +9 -0
  55. package/dist/components/page/index.es.js.map +1 -0
  56. package/dist/components/router/index.cjs.js +2 -0
  57. package/dist/components/router/index.cjs.js.map +1 -0
  58. package/dist/components/router/index.d.ts +78 -0
  59. package/dist/components/router/index.es.js +11 -0
  60. package/dist/components/router/index.es.js.map +1 -0
  61. package/dist/components/table/index.cjs.js +2 -0
  62. package/dist/components/table/index.cjs.js.map +1 -0
  63. package/dist/components/table/index.d.ts +75 -0
  64. package/dist/components/table/index.es.js +9 -0
  65. package/dist/components/table/index.es.js.map +1 -0
  66. package/dist/en-gb-B_rK7Jx1.js +20 -0
  67. package/dist/en-gb-B_rK7Jx1.js.map +1 -0
  68. package/dist/en-gb-CpyEkKq3.cjs +2 -0
  69. package/dist/en-gb-CpyEkKq3.cjs.map +1 -0
  70. package/dist/features/index.cjs.js +2 -0
  71. package/dist/features/index.cjs.js.map +1 -0
  72. package/dist/features/index.d.ts +76 -0
  73. package/dist/features/index.es.js +47 -0
  74. package/dist/features/index.es.js.map +1 -0
  75. package/dist/form.d.ts +40 -0
  76. package/dist/general-BPbbmkeX.cjs +2 -0
  77. package/dist/general-BPbbmkeX.cjs.map +1 -0
  78. package/dist/general-CtTJPCJn.js +58 -0
  79. package/dist/general-CtTJPCJn.js.map +1 -0
  80. package/dist/general.d.ts +53 -0
  81. package/dist/hooks/index.cjs.js +2 -0
  82. package/dist/hooks/index.cjs.js.map +1 -0
  83. package/dist/hooks/index.d.ts +77 -0
  84. package/dist/hooks/index.es.js +25 -0
  85. package/dist/hooks/index.es.js.map +1 -0
  86. package/dist/index-2W--_sNE.js +30 -0
  87. package/dist/index-2W--_sNE.js.map +1 -0
  88. package/dist/index-BUMdUVBH.cjs +5 -0
  89. package/dist/index-BUMdUVBH.cjs.map +1 -0
  90. package/dist/index-B_Zy_zwA.cjs +2 -0
  91. package/dist/index-B_Zy_zwA.cjs.map +1 -0
  92. package/dist/index-BgsynEGX.cjs +2 -0
  93. package/dist/index-BgsynEGX.cjs.map +1 -0
  94. package/dist/index-CA-ugBSa.cjs +2 -0
  95. package/dist/index-CA-ugBSa.cjs.map +1 -0
  96. package/dist/index-CNtOlJ49.js +572 -0
  97. package/dist/index-CNtOlJ49.js.map +1 -0
  98. package/dist/index-DkM_cG3a.js +237 -0
  99. package/dist/index-DkM_cG3a.js.map +1 -0
  100. package/dist/index-Dqp7dpn3.js +1111 -0
  101. package/dist/index-Dqp7dpn3.js.map +1 -0
  102. package/dist/index.cjs.js +2 -0
  103. package/dist/index.cjs.js.map +1 -0
  104. package/dist/index.d.ts +78 -0
  105. package/dist/index.es.js +7 -0
  106. package/dist/index.es.js.map +1 -0
  107. package/dist/jsx-runtime-CeSfJrVB.cjs +31 -0
  108. package/dist/jsx-runtime-CeSfJrVB.cjs.map +1 -0
  109. package/dist/jsx-runtime-Dpn_P65e.js +634 -0
  110. package/dist/jsx-runtime-Dpn_P65e.js.map +1 -0
  111. package/dist/middlewares/index.cjs.js +2 -0
  112. package/dist/middlewares/index.cjs.js.map +1 -0
  113. package/dist/middlewares/index.d.ts +73 -0
  114. package/dist/middlewares/index.es.js +10 -0
  115. package/dist/middlewares/index.es.js.map +1 -0
  116. package/dist/palette-CE2mKYse.cjs +2 -0
  117. package/dist/palette-CE2mKYse.cjs.map +1 -0
  118. package/dist/palette-C_L0akN_.js +43 -0
  119. package/dist/palette-C_L0akN_.js.map +1 -0
  120. package/dist/router.d.ts +48 -0
  121. package/dist/rtk-query.modern-CjetfYPg.js +3038 -0
  122. package/dist/rtk-query.modern-CjetfYPg.js.map +1 -0
  123. package/dist/rtk-query.modern-PBCErCqb.cjs +15 -0
  124. package/dist/rtk-query.modern-PBCErCqb.cjs.map +1 -0
  125. package/dist/schema.d.ts +89 -0
  126. package/dist/schemas-BZbJpkD5.cjs +2 -0
  127. package/dist/schemas-BZbJpkD5.cjs.map +1 -0
  128. package/dist/schemas-DlOtf2vf.js +162 -0
  129. package/dist/schemas-DlOtf2vf.js.map +1 -0
  130. package/dist/server.cjs.js +6 -0
  131. package/dist/server.cjs.js.map +1 -0
  132. package/dist/server.d.ts +129 -0
  133. package/dist/server.es.js +127 -0
  134. package/dist/server.es.js.map +1 -0
  135. package/dist/session-CE2U7oL1.cjs +2 -0
  136. package/dist/session-CE2U7oL1.cjs.map +1 -0
  137. package/dist/session-CacrgFSv.cjs +2 -0
  138. package/dist/session-CacrgFSv.cjs.map +1 -0
  139. package/dist/session-D312kYKk.js +32 -0
  140. package/dist/session-D312kYKk.js.map +1 -0
  141. package/dist/session-oI-Ht2C8.js +30 -0
  142. package/dist/session-oI-Ht2C8.js.map +1 -0
  143. package/dist/settings/index.cjs.js +2 -0
  144. package/dist/settings/index.cjs.js.map +1 -0
  145. package/dist/settings/index.d.ts +76 -0
  146. package/dist/settings/index.es.js +17 -0
  147. package/dist/settings/index.es.js.map +1 -0
  148. package/dist/slices/index.cjs.js +2 -0
  149. package/dist/slices/index.cjs.js.map +1 -0
  150. package/dist/slices/index.d.ts +74 -0
  151. package/dist/slices/index.es.js +6 -0
  152. package/dist/slices/index.es.js.map +1 -0
  153. package/dist/store.d.ts +17 -0
  154. package/dist/style.css +1 -0
  155. package/dist/test.d.ts +75 -0
  156. package/dist/theme/components/index.cjs.js +2 -0
  157. package/dist/theme/components/index.cjs.js.map +1 -0
  158. package/dist/theme/components/index.d.ts +75 -0
  159. package/dist/theme/components/index.es.js +6 -0
  160. package/dist/theme/components/index.es.js.map +1 -0
  161. package/dist/theme/index.cjs.js +2 -0
  162. package/dist/theme/index.cjs.js.map +1 -0
  163. package/dist/theme/index.d.ts +79 -0
  164. package/dist/theme/index.es.js +222 -0
  165. package/dist/theme/index.es.js.map +1 -0
  166. package/dist/theme.d.ts +19 -0
  167. package/dist/urls-DtHr1d3H.js +14 -0
  168. package/dist/urls-DtHr1d3H.js.map +1 -0
  169. package/dist/urls-MaVXL_C2.cjs +2 -0
  170. package/dist/urls-MaVXL_C2.cjs.map +1 -0
  171. package/dist/utils/api.cjs.js +2 -0
  172. package/dist/utils/api.cjs.js.map +1 -0
  173. package/dist/utils/api.d.ts +144 -0
  174. package/dist/utils/api.es.js +16 -0
  175. package/dist/utils/api.es.js.map +1 -0
  176. package/dist/utils/auth.cjs.js +2 -0
  177. package/dist/utils/auth.cjs.js.map +1 -0
  178. package/dist/utils/auth.d.ts +100 -0
  179. package/dist/utils/auth.es.js +117 -0
  180. package/dist/utils/auth.es.js.map +1 -0
  181. package/dist/utils/form.cjs.js +2 -0
  182. package/dist/utils/form.cjs.js.map +1 -0
  183. package/dist/utils/form.d.ts +97 -0
  184. package/dist/utils/form.es.js +76 -0
  185. package/dist/utils/form.es.js.map +1 -0
  186. package/dist/utils/general.cjs.js +2 -0
  187. package/dist/utils/general.cjs.js.map +1 -0
  188. package/dist/utils/general.d.ts +102 -0
  189. package/{src/utils/general.ts → dist/utils/general.es.js} +87 -165
  190. package/dist/utils/general.es.js.map +1 -0
  191. package/dist/utils/router.cjs.js +2 -0
  192. package/dist/utils/router.cjs.js.map +1 -0
  193. package/dist/utils/router.d.ts +91 -0
  194. package/dist/utils/router.es.js +33 -0
  195. package/dist/utils/router.es.js.map +1 -0
  196. package/dist/utils/schema.cjs.js +2 -0
  197. package/dist/utils/schema.cjs.js.map +1 -0
  198. package/dist/utils/schema.d.ts +115 -0
  199. package/dist/utils/schema.es.js +123 -0
  200. package/dist/utils/schema.es.js.map +1 -0
  201. package/dist/utils/store.cjs.js +2 -0
  202. package/dist/utils/store.cjs.js.map +1 -0
  203. package/dist/utils/store.d.ts +82 -0
  204. package/dist/utils/store.es.js +20 -0
  205. package/dist/utils/store.es.js.map +1 -0
  206. package/dist/utils/test.cjs.js +2 -0
  207. package/dist/utils/test.cjs.js.map +1 -0
  208. package/dist/utils/test.d.ts +125 -0
  209. package/dist/utils/test.es.js +60 -0
  210. package/dist/utils/test.es.js.map +1 -0
  211. package/dist/utils/theme.cjs.js +2 -0
  212. package/dist/utils/theme.cjs.js.map +1 -0
  213. package/dist/utils/theme.d.ts +83 -0
  214. package/dist/utils/theme.es.js +12 -0
  215. package/dist/utils/theme.es.js.map +1 -0
  216. package/dist/utils/window.cjs.js +2 -0
  217. package/dist/utils/window.cjs.js.map +1 -0
  218. package/dist/utils/window.d.ts +74 -0
  219. package/dist/utils/window.es.js +11 -0
  220. package/dist/utils/window.es.js.map +1 -0
  221. package/dist/window.d.ts +5 -0
  222. package/package.json +142 -37
  223. package/.github/workflows/main.yml +0 -55
  224. package/.prettierignore +0 -1
  225. package/CHANGELOG.md +0 -2020
  226. package/CONTRIBUTING.md +0 -3
  227. package/eslint.config.js +0 -17
  228. package/src/api/createApi.ts +0 -91
  229. package/src/api/endpoints/authFactor.ts +0 -31
  230. package/src/api/endpoints/index.ts +0 -9
  231. package/src/api/endpoints/klass.ts +0 -87
  232. package/src/api/endpoints/school.ts +0 -34
  233. package/src/api/endpoints/session.ts +0 -47
  234. package/src/api/endpoints/user.ts +0 -70
  235. package/src/api/index.ts +0 -5
  236. package/src/api/models.ts +0 -145
  237. package/src/api/schemas.ts +0 -243
  238. package/src/api/tagTypes.ts +0 -12
  239. package/src/api/urls.ts +0 -13
  240. package/src/components/App.css +0 -38
  241. package/src/components/App.tsx +0 -152
  242. package/src/components/ClickableTooltip.tsx +0 -43
  243. package/src/components/CopyIconButton.test.tsx +0 -16
  244. package/src/components/CopyIconButton.tsx +0 -27
  245. package/src/components/Countdown.tsx +0 -42
  246. package/src/components/DownloadFileButton.tsx +0 -55
  247. package/src/components/ElevatedAppBar.tsx +0 -41
  248. package/src/components/Image.tsx +0 -41
  249. package/src/components/InputFileButton.tsx +0 -27
  250. package/src/components/ItemizedList.tsx +0 -61
  251. package/src/components/OrderedGrid.tsx +0 -92
  252. package/src/components/ScrollIntoViewLink.tsx +0 -22
  253. package/src/components/SyncError.tsx +0 -14
  254. package/src/components/TablePagination.tsx +0 -142
  255. package/src/components/YouTubeVideo.tsx +0 -26
  256. package/src/components/form/ApiAutocompleteField.tsx +0 -187
  257. package/src/components/form/AutocompleteField.tsx +0 -135
  258. package/src/components/form/CheckboxField.tsx +0 -86
  259. package/src/components/form/CountryField.tsx +0 -75
  260. package/src/components/form/DatePickerField.tsx +0 -126
  261. package/src/components/form/EmailField.tsx +0 -38
  262. package/src/components/form/FirstNameField.tsx +0 -40
  263. package/src/components/form/Form.tsx +0 -165
  264. package/src/components/form/OtpField.tsx +0 -28
  265. package/src/components/form/PasswordField.tsx +0 -71
  266. package/src/components/form/RepeatField.tsx +0 -123
  267. package/src/components/form/SubmitButton.tsx +0 -57
  268. package/src/components/form/TextField.tsx +0 -150
  269. package/src/components/form/UkCountyField.tsx +0 -68
  270. package/src/components/form/index.tsx +0 -35
  271. package/src/components/index.ts +0 -28
  272. package/src/components/page/Banner.tsx +0 -95
  273. package/src/components/page/Notification.tsx +0 -71
  274. package/src/components/page/Page.tsx +0 -73
  275. package/src/components/page/Section.tsx +0 -21
  276. package/src/components/page/TabBar.tsx +0 -131
  277. package/src/components/page/index.ts +0 -10
  278. package/src/components/router/Link.tsx +0 -23
  279. package/src/components/router/LinkButton.tsx +0 -22
  280. package/src/components/router/LinkIconButton.tsx +0 -22
  281. package/src/components/router/LinkListItem.tsx +0 -22
  282. package/src/components/router/LinkTab.tsx +0 -22
  283. package/src/components/router/Navigate.tsx +0 -33
  284. package/src/components/router/index.tsx +0 -9
  285. package/src/components/table/CellStack.tsx +0 -19
  286. package/src/components/table/Table.tsx +0 -55
  287. package/src/components/table/index.tsx +0 -8
  288. package/src/features/InactiveDialog.tsx +0 -40
  289. package/src/features/ScreenTimeDialog.tsx +0 -30
  290. package/src/features/index.ts +0 -4
  291. package/src/fonts/ttf/Inter-VariableFont_slnt,wght.ttf +0 -0
  292. package/src/fonts/ttf/SpaceGrotesk-VariableFont_wght.ttf +0 -0
  293. package/src/hooks/api.tsx +0 -39
  294. package/src/hooks/auth.tsx +0 -397
  295. package/src/hooks/form.tsx +0 -11
  296. package/src/hooks/general.tsx +0 -110
  297. package/src/hooks/index.ts +0 -5
  298. package/src/hooks/router.tsx +0 -168
  299. package/src/images/svg/brain.svg +0 -1
  300. package/src/index.ts +0 -2
  301. package/src/middlewares/index.ts +0 -1
  302. package/src/middlewares/session.ts +0 -21
  303. package/src/scripts/freshDesk.js +0 -473
  304. package/src/scripts/index.ts +0 -1
  305. package/src/server.js +0 -187
  306. package/src/settings/custom.ts +0 -22
  307. package/src/settings/index.ts +0 -7
  308. package/src/settings/vite.ts +0 -26
  309. package/src/setupTests.ts +0 -2
  310. package/src/slices/createSlice.ts +0 -8
  311. package/src/slices/index.ts +0 -2
  312. package/src/slices/session.ts +0 -32
  313. package/src/theme/ThemedBox.tsx +0 -265
  314. package/src/theme/colors.ts +0 -57
  315. package/src/theme/components/MuiAccordion.tsx +0 -13
  316. package/src/theme/components/MuiAutocomplete.tsx +0 -11
  317. package/src/theme/components/MuiButton.ts +0 -70
  318. package/src/theme/components/MuiCardActions.tsx +0 -12
  319. package/src/theme/components/MuiCheckbox.ts +0 -12
  320. package/src/theme/components/MuiContainer.ts +0 -19
  321. package/src/theme/components/MuiDialog.tsx +0 -16
  322. package/src/theme/components/MuiFormControlLabel.ts +0 -18
  323. package/src/theme/components/MuiFormHelperText.ts +0 -12
  324. package/src/theme/components/MuiGrid2.ts +0 -16
  325. package/src/theme/components/MuiInputBase.ts +0 -14
  326. package/src/theme/components/MuiLink.ts +0 -41
  327. package/src/theme/components/MuiList.ts +0 -12
  328. package/src/theme/components/MuiListItemText.ts +0 -18
  329. package/src/theme/components/MuiMenu.ts +0 -14
  330. package/src/theme/components/MuiMenuItem.ts +0 -15
  331. package/src/theme/components/MuiSelect.ts +0 -16
  332. package/src/theme/components/MuiTab.ts +0 -29
  333. package/src/theme/components/MuiTable.ts +0 -29
  334. package/src/theme/components/MuiTableBody.ts +0 -15
  335. package/src/theme/components/MuiTableHead.ts +0 -26
  336. package/src/theme/components/MuiTabs.ts +0 -26
  337. package/src/theme/components/MuiTextField.ts +0 -86
  338. package/src/theme/components/MuiToolbar.ts +0 -11
  339. package/src/theme/components/MuiTypography.ts +0 -12
  340. package/src/theme/components/_components.ts +0 -95
  341. package/src/theme/components/index.ts +0 -57
  342. package/src/theme/index.ts +0 -25
  343. package/src/theme/palette.ts +0 -98
  344. package/src/theme/spacing.ts +0 -8
  345. package/src/theme/typography.ts +0 -101
  346. package/src/utils/api.test.ts +0 -19
  347. package/src/utils/api.tsx +0 -339
  348. package/src/utils/auth.ts +0 -78
  349. package/src/utils/form.test.ts +0 -50
  350. package/src/utils/form.ts +0 -193
  351. package/src/utils/general.test.ts +0 -55
  352. package/src/utils/router.test.ts +0 -156
  353. package/src/utils/router.ts +0 -67
  354. package/src/utils/schema.ts +0 -290
  355. package/src/utils/store.ts +0 -31
  356. package/src/utils/test.tsx +0 -82
  357. package/src/utils/theme.tsx +0 -83
  358. package/src/utils/window.ts +0 -11
  359. package/src/vite-env.d.ts +0 -1
  360. package/tsconfig.app.json +0 -4
  361. package/tsconfig.json +0 -7
  362. package/tsconfig.node.json +0 -4
  363. package/types/fixes.d.ts +0 -18
  364. package/vite.config.ts +0 -23
@@ -1,135 +0,0 @@
1
- import {
2
- Autocomplete,
3
- type AutocompleteProps,
4
- type ChipTypeMap,
5
- TextField,
6
- type TextFieldProps,
7
- } from "@mui/material"
8
- import { type ElementType, type JSX } from "react"
9
- import { Field, type FieldConfig, type FieldProps } from "formik"
10
- import {
11
- type ValidateOptions,
12
- number as YupNumber,
13
- string as YupString,
14
- } from "yup"
15
-
16
- import { type FormValues, schemaToFieldValidator } from "../../utils/form"
17
- import { getNestedProperty } from "../../utils/general"
18
-
19
- export interface AutocompleteFieldProps<
20
- Value extends string | number,
21
- Multiple extends boolean | undefined = false,
22
- DisableClearable extends boolean | undefined = false,
23
- FreeSolo extends boolean | undefined = false,
24
- ChipComponent extends ElementType = ChipTypeMap["defaultComponent"],
25
- > extends Omit<
26
- AutocompleteProps<
27
- Value,
28
- Multiple,
29
- DisableClearable,
30
- FreeSolo,
31
- ChipComponent
32
- >,
33
- "renderInput" | "defaultValue" | "onChange" | "onBlur" | "value"
34
- > {
35
- textFieldProps: Omit<
36
- TextFieldProps,
37
- | "name"
38
- | "value"
39
- | "onChange"
40
- | "onBlur"
41
- | "error"
42
- | "helperText"
43
- | "defaultValue"
44
- | "type"
45
- > & {
46
- name: string
47
- }
48
- validateOptions?: ValidateOptions
49
- }
50
-
51
- const AutocompleteField = <
52
- Value extends string | number,
53
- Multiple extends boolean | undefined = false,
54
- DisableClearable extends boolean | undefined = false,
55
- FreeSolo extends boolean | undefined = false,
56
- ChipComponent extends ElementType = ChipTypeMap["defaultComponent"],
57
- >({
58
- textFieldProps,
59
- options,
60
- validateOptions,
61
- ...otherAutocompleteProps
62
- }: AutocompleteFieldProps<
63
- Value,
64
- Multiple,
65
- DisableClearable,
66
- FreeSolo,
67
- ChipComponent
68
- >): JSX.Element => {
69
- const { id, name, required, ...otherTextFieldProps } = textFieldProps
70
-
71
- const dotPath = name.split(".")
72
-
73
- const message = "not a valid option"
74
- let schema =
75
- typeof options[0] === "string"
76
- ? YupString().oneOf(options as readonly string[], message)
77
- : YupNumber().oneOf(options as readonly number[], message)
78
- if (required) schema = schema.required()
79
-
80
- const fieldConfig: FieldConfig = {
81
- name,
82
- type: typeof options[0] === "string" ? "text" : "number",
83
- validate: schemaToFieldValidator(schema, validateOptions),
84
- }
85
-
86
- return (
87
- <Field {...fieldConfig}>
88
- {({ form, meta }: FieldProps) => {
89
- const value = getNestedProperty(
90
- form.values as FormValues,
91
- dotPath,
92
- ) as string
93
- const touched = getNestedProperty(form.touched, dotPath) as boolean
94
- const error = getNestedProperty(form.errors, dotPath) as
95
- | string
96
- | undefined
97
-
98
- return (
99
- <Autocomplete
100
- options={options}
101
- // @ts-expect-error value can be assigned
102
- defaultValue={
103
- meta.initialValue === ""
104
- ? undefined
105
- : (meta.initialValue as string)
106
- }
107
- renderInput={({
108
- id: _, // eslint-disable-line @typescript-eslint/no-unused-vars
109
- ...otherParams
110
- }) => (
111
- <TextField
112
- id={id ?? name}
113
- name={name}
114
- required={required}
115
- type="text" // Force to be string to avoid number incrementor/decrementor
116
- value={value}
117
- error={touched && Boolean(error)}
118
- helperText={touched && error}
119
- {...otherTextFieldProps}
120
- {...otherParams}
121
- />
122
- )}
123
- onChange={(_, value) => {
124
- void form.setFieldValue(name, value ?? undefined, true)
125
- }}
126
- onBlur={form.handleBlur}
127
- {...otherAutocompleteProps}
128
- />
129
- )
130
- }}
131
- </Field>
132
- )
133
- }
134
-
135
- export default AutocompleteField
@@ -1,86 +0,0 @@
1
- import {
2
- Checkbox,
3
- type CheckboxProps,
4
- FormControl,
5
- FormControlLabel,
6
- type FormControlLabelProps,
7
- FormHelperText,
8
- } from "@mui/material"
9
- import { Field, type FieldConfig, type FieldProps } from "formik"
10
- import { type ValidateOptions, bool as YupBool } from "yup"
11
- import { type FC } from "react"
12
-
13
- import { type FormValues, schemaToFieldValidator } from "../../utils/form"
14
- import { getNestedProperty } from "../../utils/general"
15
-
16
- export interface CheckboxFieldProps
17
- extends Omit<
18
- CheckboxProps,
19
- "defaultChecked" | "value" | "onChange" | "onBlur"
20
- > {
21
- name: string
22
- formControlLabelProps: Omit<FormControlLabelProps, "control">
23
- errorMessage?: string
24
- validateOptions?: ValidateOptions
25
- }
26
-
27
- const CheckboxField: FC<CheckboxFieldProps> = ({
28
- id,
29
- name,
30
- formControlLabelProps,
31
- required = false,
32
- errorMessage = "this is a required field",
33
- validateOptions,
34
- ...otherCheckboxProps
35
- }) => {
36
- const dotPath = name.split(".")
37
-
38
- let schema = YupBool()
39
- if (required) schema = schema.oneOf([true], errorMessage)
40
-
41
- const fieldConfig: FieldConfig = {
42
- name,
43
- type: "checkbox",
44
- validate: schemaToFieldValidator(schema, validateOptions),
45
- }
46
-
47
- return (
48
- <Field {...fieldConfig}>
49
- {({ form, meta }: FieldProps) => {
50
- const touched = getNestedProperty(form.touched, dotPath) as boolean
51
- const error = getNestedProperty(form.errors, dotPath) as
52
- | string
53
- | undefined
54
- const value = getNestedProperty(
55
- form.values as FormValues,
56
- dotPath,
57
- ) as boolean
58
-
59
- const hasError = touched && Boolean(error)
60
-
61
- // https://mui.com/material-ui/react-checkbox/#formgroup
62
- return (
63
- <FormControl error={hasError} required={required}>
64
- <FormControlLabel
65
- control={
66
- <Checkbox
67
- defaultChecked={meta.initialValue as boolean}
68
- id={id ?? name}
69
- name={name}
70
- value={value}
71
- onChange={form.handleChange}
72
- onBlur={form.handleBlur}
73
- {...otherCheckboxProps}
74
- />
75
- }
76
- {...formControlLabelProps}
77
- />
78
- {hasError && <FormHelperText>{error}</FormHelperText>}
79
- </FormControl>
80
- )
81
- }}
82
- </Field>
83
- )
84
- }
85
-
86
- export default CheckboxField
@@ -1,75 +0,0 @@
1
- import { type ElementType, type JSX } from "react"
2
- import { type ChipTypeMap } from "@mui/material"
3
-
4
- import AutocompleteField, {
5
- type AutocompleteFieldProps,
6
- } from "./AutocompleteField"
7
- import {
8
- COUNTRY_ISO_CODES,
9
- COUNTRY_ISO_CODE_MAPPING,
10
- type CountryIsoCodes,
11
- } from "../../utils/general"
12
-
13
- export interface CountryFieldProps<
14
- Multiple extends boolean | undefined = false,
15
- DisableClearable extends boolean | undefined = false,
16
- FreeSolo extends boolean | undefined = false,
17
- ChipComponent extends ElementType = ChipTypeMap["defaultComponent"],
18
- > extends Omit<
19
- AutocompleteFieldProps<
20
- string,
21
- Multiple,
22
- DisableClearable,
23
- FreeSolo,
24
- ChipComponent
25
- >,
26
- "options" | "textFieldProps" | "getOptionLabel"
27
- > {
28
- textFieldProps?: Omit<
29
- AutocompleteFieldProps<
30
- string,
31
- Multiple,
32
- DisableClearable,
33
- FreeSolo,
34
- ChipComponent
35
- >["textFieldProps"],
36
- "name"
37
- > & {
38
- name?: string
39
- }
40
- }
41
-
42
- const CountryField = <
43
- Multiple extends boolean | undefined = false,
44
- DisableClearable extends boolean | undefined = false,
45
- FreeSolo extends boolean | undefined = false,
46
- ChipComponent extends ElementType = ChipTypeMap["defaultComponent"],
47
- >({
48
- textFieldProps,
49
- ...otherAutocompleteFieldProps
50
- }: CountryFieldProps<
51
- Multiple,
52
- DisableClearable,
53
- FreeSolo,
54
- ChipComponent
55
- >): JSX.Element => {
56
- const {
57
- name = "country",
58
- label = "Country",
59
- placeholder = "Select your country",
60
- ...otherTextFieldProps
61
- } = textFieldProps || {}
62
-
63
- return (
64
- <AutocompleteField
65
- options={COUNTRY_ISO_CODES}
66
- getOptionLabel={isoCode =>
67
- COUNTRY_ISO_CODE_MAPPING[isoCode as CountryIsoCodes]
68
- }
69
- textFieldProps={{ name, label, placeholder, ...otherTextFieldProps }}
70
- {...otherAutocompleteFieldProps}
71
- />
72
- )
73
- }
74
-
75
- export default CountryField
@@ -1,126 +0,0 @@
1
- import "dayjs/locale/en-gb"
2
- import {
3
- DatePicker,
4
- type DatePickerProps,
5
- LocalizationProvider,
6
- type PickerValidDate,
7
- } from "@mui/x-date-pickers"
8
- import { Field, type FieldConfig, type FieldProps } from "formik"
9
- import { type ValidateOptions, date as YupDate } from "yup"
10
- import dayjs, { type Dayjs } from "dayjs"
11
- import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"
12
- import { type JSX } from "react"
13
-
14
- import { type FormValues, schemaToFieldValidator } from "../../utils/form"
15
- import { getNestedProperty } from "../../utils/general"
16
-
17
- export interface DatePickerFieldProps<
18
- TDate extends PickerValidDate,
19
- TEnableAccessibleFieldDOMStructure extends boolean = false,
20
- > extends Omit<
21
- DatePickerProps<TDate, TEnableAccessibleFieldDOMStructure>,
22
- "name" | "value" | "onChange" | "slotProps"
23
- > {
24
- name: string
25
- required?: boolean
26
- validateOptions?: ValidateOptions
27
- }
28
-
29
- const DatePickerField = <
30
- TDate extends PickerValidDate,
31
- TEnableAccessibleFieldDOMStructure extends boolean = false,
32
- >({
33
- name,
34
- required,
35
- minDate,
36
- maxDate,
37
- validateOptions,
38
- ...otherDatePickerProps
39
- }: DatePickerFieldProps<
40
- TDate,
41
- TEnableAccessibleFieldDOMStructure
42
- >): JSX.Element => {
43
- const dotPath = name.split(".")
44
-
45
- function dateToString(date: Dayjs) {
46
- return date.locale("en-gb").format("L")
47
- }
48
-
49
- let schema = YupDate()
50
- if (required) schema = schema.required()
51
- if (minDate) {
52
- schema = schema.min(
53
- minDate,
54
- `this field must be after or equal to ${dateToString(minDate)}`,
55
- )
56
- }
57
- if (maxDate) {
58
- schema = schema.max(
59
- maxDate,
60
- `this field must be before or equal to ${dateToString(maxDate)}`,
61
- )
62
- }
63
-
64
- const fieldConfig: FieldConfig = {
65
- name,
66
- type: "date",
67
- validate: schemaToFieldValidator(schema, validateOptions),
68
- }
69
-
70
- return (
71
- <Field {...fieldConfig}>
72
- {({ form }: FieldProps) => {
73
- const error = getNestedProperty(form.errors, dotPath) as
74
- | string
75
- | undefined
76
- const touched = getNestedProperty(form.touched, dotPath) as boolean
77
- let value: Dayjs | null | string = getNestedProperty(
78
- form.values as FormValues,
79
- dotPath,
80
- ) as string
81
-
82
- value = value ? dayjs(value) : null
83
-
84
- function handleChange(value: Dayjs | null) {
85
- void form.setFieldValue(
86
- name,
87
- value && value.isValid() ? value.format("YYYY-MM-DD") : null,
88
- true,
89
- )
90
- }
91
-
92
- return (
93
- <LocalizationProvider
94
- dateAdapter={AdapterDayjs}
95
- adapterLocale="en-gb"
96
- >
97
- {/* @ts-expect-error value is compatible */}
98
- <DatePicker
99
- name={name}
100
- value={value}
101
- minDate={minDate}
102
- maxDate={maxDate}
103
- onChange={handleChange}
104
- slotProps={{
105
- textField: {
106
- id: name,
107
- onChange: value => {
108
- // @ts-expect-error value is compatible
109
- handleChange(value as Dayjs | null)
110
- },
111
- onBlur: form.handleBlur,
112
- required,
113
- error: touched && Boolean(error),
114
- helperText: (touched && error) as false | string,
115
- },
116
- }}
117
- {...otherDatePickerProps}
118
- />
119
- </LocalizationProvider>
120
- )
121
- }}
122
- </Field>
123
- )
124
- }
125
-
126
- export default DatePickerField
@@ -1,38 +0,0 @@
1
- import { EmailOutlined as EmailOutlinedIcon } from "@mui/icons-material"
2
- import type { FC } from "react"
3
- import { InputAdornment } from "@mui/material"
4
- import { string as YupString } from "yup"
5
-
6
- import TextField, { type TextFieldProps } from "./TextField"
7
-
8
- export type EmailFieldProps = Omit<TextFieldProps, "type" | "name" | "schema"> &
9
- Partial<Pick<TextFieldProps, "name">>
10
-
11
- const EmailField: FC<EmailFieldProps> = ({
12
- name = "email",
13
- label = "Email address",
14
- placeholder = "Enter your email address",
15
- InputProps = {},
16
- ...otherTextFieldProps
17
- }) => {
18
- return (
19
- <TextField
20
- type="email"
21
- schema={YupString().email()}
22
- name={name}
23
- label={label}
24
- placeholder={placeholder}
25
- InputProps={{
26
- endAdornment: (
27
- <InputAdornment position="end">
28
- <EmailOutlinedIcon />
29
- </InputAdornment>
30
- ),
31
- ...InputProps,
32
- }}
33
- {...otherTextFieldProps}
34
- />
35
- )
36
- }
37
-
38
- export default EmailField
@@ -1,40 +0,0 @@
1
- import type { FC } from "react"
2
- import { InputAdornment } from "@mui/material"
3
- import { PersonOutlined as PersonOutlinedIcon } from "@mui/icons-material"
4
-
5
- import TextField, { type TextFieldProps } from "./TextField"
6
- import { schemas } from "../../api"
7
-
8
- export type FirstNameFieldProps = Omit<
9
- TextFieldProps,
10
- "type" | "name" | "schema"
11
- > &
12
- Partial<Pick<TextFieldProps, "name">>
13
-
14
- const FirstNameField: FC<FirstNameFieldProps> = ({
15
- name = "first_name",
16
- label = "First name",
17
- placeholder = "Enter your first name",
18
- InputProps = {},
19
- ...otherTextFieldProps
20
- }) => {
21
- return (
22
- <TextField
23
- schema={schemas.user.first_name}
24
- name={name}
25
- label={label}
26
- placeholder={placeholder}
27
- InputProps={{
28
- endAdornment: (
29
- <InputAdornment position="end">
30
- <PersonOutlinedIcon />
31
- </InputAdornment>
32
- ),
33
- ...InputProps,
34
- }}
35
- {...otherTextFieldProps}
36
- />
37
- )
38
- }
39
-
40
- export default FirstNameField
@@ -1,165 +0,0 @@
1
- import {
2
- type FC,
3
- type JSX,
4
- type ReactNode,
5
- type RefObject,
6
- useEffect,
7
- useRef,
8
- } from "react"
9
- import { FormHelperText, type FormHelperTextProps } from "@mui/material"
10
- import {
11
- Formik,
12
- type FormikConfig,
13
- type FormikErrors,
14
- Form as FormikForm,
15
- type FormikProps,
16
- } from "formik"
17
- import type { TypedUseMutation } from "@reduxjs/toolkit/query/react"
18
-
19
- import {
20
- type FormValues,
21
- type SubmitFormOptions,
22
- submitForm,
23
- } from "../../utils/form"
24
- import { getKeyPaths } from "../../utils/general"
25
-
26
- const SCROLL_INTO_VIEW_OPTIONS: ScrollIntoViewOptions = {
27
- behavior: "smooth",
28
- block: "start",
29
- }
30
-
31
- type NonFieldErrorsProps = Omit<FormHelperTextProps, "error" | "ref"> & {
32
- scrollIntoViewOptions?: ScrollIntoViewOptions
33
- }
34
-
35
- const NonFieldErrors: FC<NonFieldErrorsProps> = ({
36
- scrollIntoViewOptions = SCROLL_INTO_VIEW_OPTIONS,
37
- ...formHelperTextProps
38
- }) => {
39
- const pRef = useRef<HTMLParagraphElement>(null)
40
-
41
- useEffect(() => {
42
- if (pRef.current) pRef.current.scrollIntoView(scrollIntoViewOptions)
43
- }, [scrollIntoViewOptions])
44
-
45
- return <FormHelperText ref={pRef} error {...formHelperTextProps} />
46
- }
47
-
48
- export type FormErrors<Values> = FormikErrors<
49
- Omit<Values, "__all__"> & { __all__: string }
50
- >
51
-
52
- type _FormikProps<Values> = Omit<FormikProps<Values>, "errors"> & {
53
- errors: FormErrors<Values>
54
- }
55
-
56
- type BaseFormProps<Values> = Omit<FormikConfig<Values>, "children"> & {
57
- children: ReactNode | ((props: _FormikProps<Values>) => ReactNode)
58
- scrollIntoViewOptions?: ScrollIntoViewOptions
59
- nonFieldErrorsProps?: Omit<NonFieldErrorsProps, "children">
60
- fieldRefs?: Array<{
61
- name: string
62
- inputRef: RefObject<HTMLInputElement | null>
63
- }>
64
- }
65
-
66
- const BaseForm = <Values extends FormValues>({
67
- children,
68
- scrollIntoViewOptions = SCROLL_INTO_VIEW_OPTIONS,
69
- nonFieldErrorsProps,
70
- fieldRefs = [],
71
- ...otherFormikProps
72
- }: BaseFormProps<Values>) => (
73
- <Formik {...otherFormikProps}>
74
- {/* @ts-expect-error value is assignable */}
75
- {(formik: _FormikProps<Values>) => {
76
- const hasErrors = Boolean(Object.keys(formik.errors).length)
77
- const hasNonFieldErrors =
78
- hasErrors && typeof formik.errors.__all__ === "string"
79
-
80
- // If a submission was attempted and refs to the fields were provided.
81
- if (
82
- hasErrors &&
83
- !hasNonFieldErrors &&
84
- formik.isSubmitting &&
85
- fieldRefs.length
86
- ) {
87
- const errorNames = getKeyPaths(formik.errors)
88
-
89
- const input = fieldRefs.find(({ name }) => errorNames.includes(name))
90
- ?.inputRef.current
91
-
92
- if (input) input.scrollIntoView(scrollIntoViewOptions)
93
- }
94
-
95
- return (
96
- <>
97
- {hasNonFieldErrors && (
98
- <NonFieldErrors {...nonFieldErrorsProps}>
99
- {formik.errors.__all__ as string}
100
- </NonFieldErrors>
101
- )}
102
- <FormikForm>
103
- {typeof children === "function" ? children(formik) : children}
104
- </FormikForm>
105
- </>
106
- )
107
- }}
108
- </Formik>
109
- )
110
-
111
- type SubmitFormProps<
112
- Values extends FormValues,
113
- QueryArg extends FormValues,
114
- ResultType,
115
- > = Omit<BaseFormProps<Values>, "onSubmit"> & {
116
- useMutation: TypedUseMutation<ResultType, QueryArg, any>
117
- } & (Values extends QueryArg
118
- ? { submitOptions?: SubmitFormOptions<Values, QueryArg, ResultType> }
119
- : { submitOptions: SubmitFormOptions<Values, QueryArg, ResultType> })
120
-
121
- const SubmitForm = <
122
- Values extends FormValues,
123
- QueryArg extends FormValues,
124
- ResultType,
125
- >({
126
- useMutation,
127
- submitOptions,
128
- ...baseFormProps
129
- }: SubmitFormProps<Values, QueryArg, ResultType>): JSX.Element => {
130
- const [trigger] = useMutation()
131
-
132
- return (
133
- <BaseForm
134
- {...baseFormProps}
135
- onSubmit={submitForm<Values, QueryArg, ResultType>(
136
- trigger,
137
- baseFormProps.initialValues,
138
- submitOptions as SubmitFormOptions<Values, QueryArg, ResultType>,
139
- )}
140
- />
141
- )
142
- }
143
-
144
- export type FormProps<
145
- Values extends FormValues,
146
- QueryArg extends FormValues,
147
- ResultType,
148
- > = BaseFormProps<Values> | SubmitFormProps<Values, QueryArg, ResultType>
149
-
150
- const Form: {
151
- <Values extends FormValues>(props: BaseFormProps<Values>): JSX.Element
152
- <Values extends FormValues, QueryArg extends FormValues, ResultType>(
153
- props: SubmitFormProps<Values, QueryArg, ResultType>,
154
- ): JSX.Element
155
- } = <
156
- Values extends FormValues = FormValues,
157
- QueryArg extends FormValues = FormValues,
158
- ResultType = any,
159
- >(
160
- props: FormProps<Values, QueryArg, ResultType>,
161
- ): JSX.Element => {
162
- return "onSubmit" in props ? <BaseForm {...props} /> : SubmitForm(props)
163
- }
164
-
165
- export default Form
@@ -1,28 +0,0 @@
1
- import { type FC } from "react"
2
- import { string as YupString } from "yup"
3
-
4
- import TextField, { type TextFieldProps } from "./TextField"
5
-
6
- export type OtpFieldProps = Omit<
7
- TextFieldProps,
8
- "name" | "schema" | "required"
9
- > &
10
- Partial<Pick<TextFieldProps, "name">>
11
-
12
- const OtpField: FC<OtpFieldProps> = ({
13
- name = "otp",
14
- label = "OTP",
15
- placeholder = "Enter your OTP",
16
- ...otherTextFieldProps
17
- }) => (
18
- <TextField
19
- name={name}
20
- label={label}
21
- schema={YupString().matches(/^[0-9]{6}$/, "Must be exactly 6 digits.")}
22
- placeholder={placeholder}
23
- required
24
- {...otherTextFieldProps}
25
- />
26
- )
27
-
28
- export default OtpField