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
package/CONTRIBUTING.md DELETED
@@ -1,3 +0,0 @@
1
- # Contributing
2
-
3
- Find our contribution agreement [here](https://github.com/ocadotechnology/codeforlife-workspace/blob/main/CONTRIBUTING.md).
package/eslint.config.js DELETED
@@ -1,17 +0,0 @@
1
- import workspaceConfig from "@codeforlife/workspace/eslint.config.js"
2
- import ts from "typescript-eslint"
3
-
4
- export default ts.config(
5
- ...workspaceConfig,
6
- {
7
- ignores: [
8
- "src/scripts/*",
9
- "src/server.js", // TODO: convert to src/server.ts and remove this ignore
10
- ],
11
- },
12
- {
13
- languageOptions: {
14
- parserOptions: { tsconfigRootDir: import.meta.dirname },
15
- },
16
- },
17
- )
@@ -1,91 +0,0 @@
1
- import {
2
- type FetchArgs,
3
- createApi as _createApi,
4
- fetchBaseQuery,
5
- } from "@reduxjs/toolkit/query/react"
6
-
7
- import { SERVICE_API_URL } from "../settings"
8
- import { buildLogoutEndpoint } from "./endpoints/session"
9
- import defaultTagTypes from "./tagTypes"
10
- import { getCsrfCookie } from "../utils/auth"
11
- import { isSafeHttpMethod } from "../utils/api"
12
-
13
- // TODO: decide if we want to keep any of this.
14
- // export function handleResponseError(error: FetchBaseQueryError): void {
15
- // if (
16
- // error.status === 400 &&
17
- // typeof error.data === "object" &&
18
- // error.data !== null
19
- // ) {
20
- // // Parse the error's data from snake_case to camelCase.
21
- // snakeCaseToCamelCase(error.data)
22
- // } else if (error.status === 401) {
23
- // // TODO: redirect to appropriate login page based on user type.
24
- // window.location.href = `${PORTAL_BASE_URL}/login/teacher`
25
- // } else {
26
- // // Catch-all error pages by status-code.
27
- // window.location.href = `${PORTAL_BASE_URL}/error/${
28
- // [403, 404].includes(error.status as number) ? error.status : 500
29
- // }`
30
- // }
31
- // }
32
-
33
- export default function createApi<TagTypes extends string = never>({
34
- tagTypes = [],
35
- }: {
36
- tagTypes?: readonly TagTypes[]
37
- } = {}) {
38
- const fetch = fetchBaseQuery({
39
- baseUrl: `${SERVICE_API_URL}/`,
40
- credentials: "include",
41
- prepareHeaders: (headers, endpoint) => {
42
- const { type, arg } = endpoint as typeof endpoint & {
43
- arg: string | FetchArgs
44
- }
45
- const method = typeof arg === "string" ? "GET" : arg.method || "GET"
46
-
47
- if (type === "mutation" || !isSafeHttpMethod(method)) {
48
- const csrfToken = getCsrfCookie()
49
- if (csrfToken) headers.set("x-csrftoken", csrfToken)
50
- }
51
-
52
- return headers
53
- },
54
- })
55
-
56
- const api = _createApi({
57
- // https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#implementing-a-custom-basequery
58
- baseQuery: async (args: string | FetchArgs, api, extraOptions) => {
59
- if (api.type === "mutation" && getCsrfCookie() === undefined) {
60
- // Get the CSRF token.
61
- const { error } = await fetch(
62
- { url: "/csrf/cookie/", method: "GET" },
63
- api,
64
- {},
65
- )
66
-
67
- // Validate we got the CSRF token.
68
- if (error !== undefined) {
69
- console.error(error)
70
- // TODO
71
- // window.location.href = `${PORTAL_BASE_URL}/error/500`
72
- }
73
- if (getCsrfCookie() === undefined) {
74
- // TODO
75
- // window.location.href = `${PORTAL_BASE_URL}/error/500`
76
- }
77
- }
78
-
79
- // Send the HTTP request and fetch the response.
80
- return await fetch(args, api, extraOptions)
81
- },
82
- tagTypes: [...defaultTagTypes, ...tagTypes],
83
- endpoints: () => ({}),
84
- })
85
-
86
- return api.injectEndpoints({
87
- endpoints: build => ({
88
- logout: buildLogoutEndpoint<null, null>(api, build),
89
- }),
90
- })
91
- }
@@ -1,31 +0,0 @@
1
- import { type EndpointBuilder } from "@reduxjs/toolkit/query/react"
2
-
3
- import {
4
- type ListArg as _ListArg,
5
- type ListResult as _ListResult,
6
- buildUrl,
7
- tagData,
8
- } from "../../utils/api"
9
- import type { AuthFactor } from "../models"
10
- import { type TagTypes } from "../tagTypes"
11
- import urls from "../urls"
12
-
13
- export const AUTH_FACTOR_TAG: TagTypes = "AuthFactor"
14
-
15
- export type ListAuthFactorsResult = _ListResult<AuthFactor, "type">
16
- export type ListAuthFactorsArg = _ListArg
17
-
18
- export default function getReadAuthFactorEndpoints<
19
- ListResult extends _ListResult<AuthFactor> = ListAuthFactorsResult,
20
- ListArg extends _ListArg<AuthFactor> = ListAuthFactorsArg,
21
- >(build: EndpointBuilder<any, any, any>) {
22
- return {
23
- listAuthFactors: build.query<ListResult, ListArg>({
24
- query: search => ({
25
- url: buildUrl(urls.authFactor.list, { search }),
26
- method: "GET",
27
- }),
28
- providesTags: tagData(AUTH_FACTOR_TAG, { includeListTag: true }),
29
- }),
30
- }
31
- }
@@ -1,9 +0,0 @@
1
- export * from "./authFactor"
2
- export { default as getReadAuthFactorEndpoints } from "./authFactor"
3
- export * from "./klass"
4
- export { default as getReadClassEndpoints } from "./klass"
5
- export * from "./school"
6
- export { default as getReadSchoolEndpoints } from "./school"
7
- export * from "./session"
8
- export * from "./user"
9
- export { default as getReadUserEndpoints } from "./user"
@@ -1,87 +0,0 @@
1
- import { type EndpointBuilder } from "@reduxjs/toolkit/query/react"
2
-
3
- import type {
4
- Class,
5
- SchoolTeacher,
6
- SchoolTeacherUser,
7
- Teacher,
8
- } from "../models"
9
- import {
10
- type ListArg as _ListArg,
11
- type ListResult as _ListResult,
12
- type RetrieveArg as _RetrieveArg,
13
- type RetrieveResult as _RetrieveResult,
14
- buildUrl,
15
- tagData,
16
- } from "../../utils/api"
17
- import { type TagTypes } from "../tagTypes"
18
- import urls from "../urls"
19
-
20
- export const CLASS_TAG: TagTypes = "Class"
21
-
22
- export type RetrieveClassResult = _RetrieveResult<
23
- Class,
24
- "name" | "read_classmates_data" | "receive_requests_until" | "school"
25
- > & {
26
- teacher: SchoolTeacher & {
27
- user: Pick<
28
- SchoolTeacherUser,
29
- | "id"
30
- | "first_name"
31
- | "last_name"
32
- | "email"
33
- | "is_active"
34
- | "date_joined"
35
- | "requesting_to_join_class"
36
- >
37
- }
38
- }
39
- export type RetrieveClassArg = _RetrieveArg<Class>
40
-
41
- export type ListClassesResult = _ListResult<
42
- Class,
43
- "name" | "read_classmates_data" | "receive_requests_until" | "school",
44
- {
45
- teacher: SchoolTeacher & {
46
- user: Pick<
47
- SchoolTeacherUser,
48
- | "id"
49
- | "first_name"
50
- | "last_name"
51
- | "email"
52
- | "is_active"
53
- | "date_joined"
54
- | "requesting_to_join_class"
55
- >
56
- }
57
- }
58
- >
59
- export type ListClassesArg = _ListArg<{
60
- teacher: Teacher["id"]
61
- _id: Class["id"] | Class["id"][]
62
- id_or_name: string
63
- }>
64
-
65
- export default function getReadClassEndpoints<
66
- RetrieveResult extends _RetrieveResult<Class> = RetrieveClassResult,
67
- RetrieveArg extends _RetrieveArg<Class> = RetrieveClassArg,
68
- ListResult extends _ListResult<Class> = ListClassesResult,
69
- ListArg extends _ListArg<Class> = ListClassesArg,
70
- >(build: EndpointBuilder<any, any, any>) {
71
- return {
72
- retrieveClass: build.query<RetrieveResult, RetrieveArg>({
73
- query: id => ({
74
- url: buildUrl(urls.class.detail, { url: { id } }),
75
- method: "GET",
76
- }),
77
- providesTags: tagData(CLASS_TAG),
78
- }),
79
- listClasses: build.query<ListResult, ListArg>({
80
- query: search => ({
81
- url: buildUrl(urls.class.list, { search }),
82
- method: "GET",
83
- }),
84
- providesTags: tagData(CLASS_TAG, { includeListTag: true }),
85
- }),
86
- }
87
- }
@@ -1,34 +0,0 @@
1
- import { type EndpointBuilder } from "@reduxjs/toolkit/query/react"
2
-
3
- import {
4
- type RetrieveArg as _RetrieveArg,
5
- type RetrieveResult as _RetrieveResult,
6
- buildUrl,
7
- tagData,
8
- } from "../../utils/api"
9
- import type { School } from "../models"
10
- import { type TagTypes } from "../tagTypes"
11
- import urls from "../urls"
12
-
13
- export const SCHOOL_TAG: TagTypes = "School"
14
-
15
- export type RetrieveSchoolResult = _RetrieveResult<
16
- School,
17
- "name" | "country" | "uk_county"
18
- >
19
- export type RetrieveSchoolArg = _RetrieveArg<School>
20
-
21
- export default function getReadSchoolEndpoints<
22
- RetrieveResult extends _RetrieveResult<School> = RetrieveSchoolResult,
23
- RetrieveArg extends _RetrieveArg<School> = RetrieveSchoolArg,
24
- >(build: EndpointBuilder<any, any, any>) {
25
- return {
26
- retrieveSchool: build.query<RetrieveResult, RetrieveArg>({
27
- query: id => ({
28
- url: buildUrl(urls.school.detail, { url: { id } }),
29
- method: "GET",
30
- }),
31
- providesTags: tagData(SCHOOL_TAG),
32
- }),
33
- }
34
- }
@@ -1,47 +0,0 @@
1
- import { type Api, type EndpointBuilder } from "@reduxjs/toolkit/query/react"
2
-
3
- import { login, logout } from "../../slices/session"
4
-
5
- export type ExchangeOAuth2CodeArg = {
6
- code: string
7
- code_verifier: string
8
- redirect_uri: string
9
- }
10
-
11
- export function buildLoginEndpoint<ResultType, QueryArg>(
12
- build: EndpointBuilder<any, any, any>,
13
- url: string = "session/login/",
14
- ) {
15
- return build.mutation<ResultType, QueryArg>({
16
- query: body => ({ url, method: "POST", body }),
17
- async onQueryStarted(_, { dispatch, queryFulfilled }) {
18
- try {
19
- await queryFulfilled
20
- dispatch(login())
21
- } catch (error) {
22
- console.error("Failed to call login endpoint...", error)
23
- }
24
- },
25
- })
26
- }
27
-
28
- export function buildLogoutEndpoint<ResultType, QueryArg>(
29
- api: Api<any, any, any, any, any>,
30
- build: EndpointBuilder<any, any, any>,
31
- url: string = "session/logout/",
32
- ) {
33
- return build.mutation<ResultType, QueryArg>({
34
- query: () => ({ url, method: "POST" }),
35
- async onQueryStarted(_, { dispatch, queryFulfilled }) {
36
- try {
37
- await queryFulfilled
38
- } catch (error) {
39
- console.error("Failed to call logout endpoint...", error)
40
- } finally {
41
- dispatch(logout())
42
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
43
- dispatch(api.util.resetApiState())
44
- }
45
- },
46
- })
47
- }
@@ -1,70 +0,0 @@
1
- import { type EndpointBuilder } from "@reduxjs/toolkit/query/react"
2
-
3
- import type { Class, User } from "../models"
4
- import {
5
- type ListArg as _ListArg,
6
- type ListResult as _ListResult,
7
- type RetrieveArg as _RetrieveArg,
8
- type RetrieveResult as _RetrieveResult,
9
- buildUrl,
10
- tagData,
11
- } from "../../utils/api"
12
- import { type TagTypes } from "../tagTypes"
13
- import urls from "../urls"
14
-
15
- export const USER_TAG: TagTypes = "User"
16
-
17
- export type RetrieveUserResult = _RetrieveResult<
18
- User,
19
- | "first_name"
20
- | "last_name"
21
- | "email"
22
- | "is_active"
23
- | "date_joined"
24
- | "requesting_to_join_class"
25
- | "student"
26
- | "teacher"
27
- >
28
- export type RetrieveUserArg = _RetrieveArg<User>
29
-
30
- export type ListUsersResult = _ListResult<
31
- User,
32
- | "first_name"
33
- | "last_name"
34
- | "email"
35
- | "is_active"
36
- | "date_joined"
37
- | "requesting_to_join_class"
38
- | "student"
39
- | "teacher"
40
- >
41
- export type ListUsersArg = _ListArg<{
42
- students_in_class: Class["id"]
43
- _id: User["id"] | User["id"][]
44
- name: string
45
- type: "teacher" | "student" | "independent" | "indy"
46
- }>
47
-
48
- export default function getReadUserEndpoints<
49
- RetrieveResult extends _RetrieveResult<User> = RetrieveUserResult,
50
- RetrieveArg extends _RetrieveArg<User> = RetrieveUserArg,
51
- ListResult extends _ListResult<User> = ListUsersResult,
52
- ListArg extends _ListArg<User> = ListUsersArg,
53
- >(build: EndpointBuilder<any, any, any>) {
54
- return {
55
- retrieveUser: build.query<RetrieveResult, RetrieveArg>({
56
- query: id => ({
57
- url: buildUrl(urls.user.detail, { url: { id } }),
58
- method: "GET",
59
- }),
60
- providesTags: tagData(USER_TAG),
61
- }),
62
- listUsers: build.query<ListResult, ListArg>({
63
- query: search => ({
64
- url: buildUrl(urls.user.list, { search }),
65
- method: "GET",
66
- }),
67
- providesTags: tagData(USER_TAG, { includeListTag: true }),
68
- }),
69
- }
70
- }
package/src/api/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export { default as createApi } from "./createApi"
2
- export * from "./models"
3
- export * as schemas from "./schemas"
4
- export { default as tagTypes } from "./tagTypes"
5
- export { default as urls } from "./urls"
package/src/api/models.ts DELETED
@@ -1,145 +0,0 @@
1
- import type { CountryIsoCodes, UkCounties } from "../utils/general"
2
- import type { Model } from "../utils/api"
3
-
4
- // -----------------------------------------------------------------------------
5
- // User Models
6
- // -----------------------------------------------------------------------------
7
-
8
- type _UserTeacher<T extends Teacher> = Omit<T, "user">
9
- type _UserStudent<S extends Student> = Omit<S, "user" | "auto_gen_password">
10
-
11
- export type User = Model<
12
- number,
13
- {
14
- password: string
15
- last_login?: Date
16
- first_name: string
17
- last_name?: string
18
- email?: string
19
- is_staff: boolean
20
- is_active: boolean
21
- date_joined: Date
22
- requesting_to_join_class?: Class["id"] | null
23
- teacher?: _UserTeacher<Teacher>
24
- student?: _UserStudent<Student>
25
- }
26
- >
27
-
28
- export type TeacherUser<Fields = User> = Fields & {
29
- email: string
30
- last_name: string
31
- teacher: _UserTeacher<Teacher>
32
- student?: undefined
33
- }
34
-
35
- export type SchoolTeacherUser<Fields = User> = TeacherUser<Fields> & {
36
- teacher: _UserTeacher<SchoolTeacher>
37
- }
38
-
39
- export type AdminSchoolTeacherUser<Fields = User> =
40
- SchoolTeacherUser<Fields> & {
41
- teacher: _UserTeacher<AdminSchoolTeacher>
42
- }
43
-
44
- export type NonAdminSchoolTeacherUser<Fields = User> =
45
- SchoolTeacherUser<Fields> & {
46
- teacher: _UserTeacher<NonAdminSchoolTeacher>
47
- }
48
-
49
- export type NonSchoolTeacherUser<Fields = User> = TeacherUser<Fields> & {
50
- teacher: _UserTeacher<NonSchoolTeacher>
51
- }
52
-
53
- export type StudentUser<Fields = User> = Fields & {
54
- email?: undefined
55
- last_name?: undefined
56
- teacher?: undefined
57
- student: _UserStudent<Student>
58
- }
59
-
60
- export type IndependentUser<Fields = User> = Fields & {
61
- email: string
62
- last_name: string
63
- teacher?: undefined
64
- student?: undefined
65
- }
66
-
67
- // -----------------------------------------------------------------------------
68
- // Teacher Models
69
- // -----------------------------------------------------------------------------
70
-
71
- export type Teacher = Model<
72
- number,
73
- {
74
- user: User["id"]
75
- school?: School["id"]
76
- is_admin: boolean
77
- }
78
- >
79
-
80
- export type SchoolTeacher<Fields = Teacher> = Fields & {
81
- school: School["id"]
82
- }
83
-
84
- export type AdminSchoolTeacher<Fields = Teacher> = SchoolTeacher<Fields> & {
85
- is_admin: true
86
- }
87
-
88
- export type NonAdminSchoolTeacher<Fields = Teacher> = SchoolTeacher<Fields> & {
89
- is_admin: false
90
- }
91
-
92
- export type NonSchoolTeacher<Fields = Teacher> = Fields & {
93
- school?: undefined
94
- is_admin: false
95
- }
96
-
97
- // -----------------------------------------------------------------------------
98
- // Other Models
99
- // -----------------------------------------------------------------------------
100
-
101
- export type Student = Model<
102
- number,
103
- {
104
- user: User["id"]
105
- school: School["id"]
106
- klass: Class["id"]
107
- auto_gen_password: string
108
- }
109
- >
110
-
111
- export type School = Model<
112
- number,
113
- {
114
- name: string
115
- country?: CountryIsoCodes
116
- uk_county?: UkCounties
117
- }
118
- >
119
-
120
- export type Class = Model<
121
- string,
122
- {
123
- name: string
124
- teacher: Teacher["id"]
125
- school: School["id"]
126
- read_classmates_data: boolean
127
- receive_requests_until?: Date
128
- }
129
- >
130
-
131
- export type AuthFactor = Model<
132
- number,
133
- {
134
- user: User["id"]
135
- type: "otp"
136
- }
137
- >
138
-
139
- export type OtpBypassToken = Model<
140
- number,
141
- {
142
- user: User["id"]
143
- token: string
144
- }
145
- >