@wger-project/react-components 25.10.16

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 (531) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +58 -0
  3. package/build/OpenSans-Bold.woff +0 -0
  4. package/build/OpenSans-Light.woff +0 -0
  5. package/build/assets/index.css +1 -0
  6. package/build/chunks/browser-ponyfill-DL_vVusK.js +3 -0
  7. package/build/chunks/browser-ponyfill-DL_vVusK.js.map +1 -0
  8. package/build/favicon.ico +0 -0
  9. package/build/index.html +60 -0
  10. package/build/locales/README.md +10 -0
  11. package/build/locales/ar/translation.json +240 -0
  12. package/build/locales/ca/translation.json +35 -0
  13. package/build/locales/cs/translation.json +257 -0
  14. package/build/locales/de/translation.json +338 -0
  15. package/build/locales/el/translation.json +97 -0
  16. package/build/locales/en/translation.json +332 -0
  17. package/build/locales/es/translation.json +335 -0
  18. package/build/locales/fa/translation.json +127 -0
  19. package/build/locales/fr/translation.json +341 -0
  20. package/build/locales/he/translation.json +146 -0
  21. package/build/locales/hr/translation.json +249 -0
  22. package/build/locales/it/translation.json +338 -0
  23. package/build/locales/ko/translation.json +331 -0
  24. package/build/locales/nb_NO/translation.json +50 -0
  25. package/build/locales/nl/translation.json +242 -0
  26. package/build/locales/pl/translation.json +261 -0
  27. package/build/locales/pt/translation.json +342 -0
  28. package/build/locales/pt_BR/translation.json +259 -0
  29. package/build/locales/pt_PT/translation.json +334 -0
  30. package/build/locales/ru/translation.json +116 -0
  31. package/build/locales/sk/translation.json +10 -0
  32. package/build/locales/sl/translation.json +326 -0
  33. package/build/locales/sr/translation.json +240 -0
  34. package/build/locales/sv/translation.json +165 -0
  35. package/build/locales/ta/translation.json +331 -0
  36. package/build/locales/th/translation.json +27 -0
  37. package/build/locales/tr/translation.json +238 -0
  38. package/build/locales/uk/translation.json +339 -0
  39. package/build/locales/uz/translation.json +56 -0
  40. package/build/locales/vi/translation.json +70 -0
  41. package/build/locales/zh_Hans/translation.json +336 -0
  42. package/build/locales/zh_Hant/translation.json +246 -0
  43. package/build/logo192.png +0 -0
  44. package/build/logo512.png +0 -0
  45. package/build/main.js +542 -0
  46. package/build/main.js.map +1 -0
  47. package/build/manifest.json +25 -0
  48. package/build/muscles/SOURCES +2 -0
  49. package/build/muscles/main/muscle-1.svg +72 -0
  50. package/build/muscles/main/muscle-10.svg +73 -0
  51. package/build/muscles/main/muscle-11.svg +72 -0
  52. package/build/muscles/main/muscle-12.svg +72 -0
  53. package/build/muscles/main/muscle-13.svg +92 -0
  54. package/build/muscles/main/muscle-14.svg +73 -0
  55. package/build/muscles/main/muscle-15.svg +72 -0
  56. package/build/muscles/main/muscle-16.svg +73 -0
  57. package/build/muscles/main/muscle-2.svg +72 -0
  58. package/build/muscles/main/muscle-3.svg +72 -0
  59. package/build/muscles/main/muscle-4.svg +72 -0
  60. package/build/muscles/main/muscle-5.svg +72 -0
  61. package/build/muscles/main/muscle-6.svg +73 -0
  62. package/build/muscles/main/muscle-7.svg +72 -0
  63. package/build/muscles/main/muscle-8.svg +72 -0
  64. package/build/muscles/main/muscle-9.svg +72 -0
  65. package/build/muscles/muscular_system_back.svg +118 -0
  66. package/build/muscles/muscular_system_front.svg +99 -0
  67. package/build/muscles/secondary/muscle-1.svg +72 -0
  68. package/build/muscles/secondary/muscle-10.svg +73 -0
  69. package/build/muscles/secondary/muscle-11.svg +72 -0
  70. package/build/muscles/secondary/muscle-12.svg +72 -0
  71. package/build/muscles/secondary/muscle-13.svg +92 -0
  72. package/build/muscles/secondary/muscle-14.svg +73 -0
  73. package/build/muscles/secondary/muscle-15.svg +72 -0
  74. package/build/muscles/secondary/muscle-16.svg +73 -0
  75. package/build/muscles/secondary/muscle-2.svg +72 -0
  76. package/build/muscles/secondary/muscle-3.svg +72 -0
  77. package/build/muscles/secondary/muscle-4.svg +72 -0
  78. package/build/muscles/secondary/muscle-5.svg +72 -0
  79. package/build/muscles/secondary/muscle-6.svg +73 -0
  80. package/build/muscles/secondary/muscle-7.svg +72 -0
  81. package/build/muscles/secondary/muscle-8.svg +72 -0
  82. package/build/muscles/secondary/muscle-9.svg +72 -0
  83. package/build/robots.txt +3 -0
  84. package/index.html +59 -0
  85. package/package.json +125 -0
  86. package/src/.sass-cache/166f82406a0edab65b7f8fd8256819ee2f34bebf/App.module.scssc +0 -0
  87. package/src/@types/i18next.d.ts +13 -0
  88. package/src/App.tsx +25 -0
  89. package/src/assets/images/discord-logo.svg +1 -0
  90. package/src/assets/images/get-it-on-google-play.svg +1 -0
  91. package/src/assets/images/logo.png +0 -0
  92. package/src/assets/images/twitter-logo-50.png +0 -0
  93. package/src/assets/images/twitter.svg +5 -0
  94. package/src/components/BodyWeight/Form/WeightForm.test.tsx +100 -0
  95. package/src/components/BodyWeight/Form/WeightForm.tsx +102 -0
  96. package/src/components/BodyWeight/Table/ActionButton/ActionButton.test.tsx +65 -0
  97. package/src/components/BodyWeight/Table/ActionButton/ActionButton.tsx +67 -0
  98. package/src/components/BodyWeight/Table/Fab/Fab.tsx +35 -0
  99. package/src/components/BodyWeight/Table/index.test.tsx +33 -0
  100. package/src/components/BodyWeight/Table/index.tsx +98 -0
  101. package/src/components/BodyWeight/Table/table.module.css +5 -0
  102. package/src/components/BodyWeight/Table/table.module.css.map +1 -0
  103. package/src/components/BodyWeight/Table/table.module.scss +0 -0
  104. package/src/components/BodyWeight/Table/table.mosule.css +2 -0
  105. package/src/components/BodyWeight/Table/table.mosule.css.map +1 -0
  106. package/src/components/BodyWeight/TableDashboard/TableDashboard.test.tsx +24 -0
  107. package/src/components/BodyWeight/TableDashboard/TableDashboard.tsx +62 -0
  108. package/src/components/BodyWeight/WeightChart/index.test.tsx +66 -0
  109. package/src/components/BodyWeight/WeightChart/index.tsx +105 -0
  110. package/src/components/BodyWeight/body_weight.module.css +8 -0
  111. package/src/components/BodyWeight/body_weight.module.css.map +1 -0
  112. package/src/components/BodyWeight/body_weight.module.scss +8 -0
  113. package/src/components/BodyWeight/index.test.tsx +92 -0
  114. package/src/components/BodyWeight/index.tsx +40 -0
  115. package/src/components/BodyWeight/model.ts +40 -0
  116. package/src/components/BodyWeight/queries/index.ts +49 -0
  117. package/src/components/BodyWeight/utils.test.ts +44 -0
  118. package/src/components/BodyWeight/utils.ts +22 -0
  119. package/src/components/BodyWeight/widgets/FilterButtons.test.tsx +57 -0
  120. package/src/components/BodyWeight/widgets/FilterButtons.tsx +69 -0
  121. package/src/components/BodyWeight/widgets/fab.tsx +33 -0
  122. package/src/components/Calendar/Components/CalendarComponent.test.tsx +141 -0
  123. package/src/components/Calendar/Components/CalendarComponent.tsx +250 -0
  124. package/src/components/Calendar/Components/CalendarDay.tsx +105 -0
  125. package/src/components/Calendar/Components/CalendarDayGrid.tsx +53 -0
  126. package/src/components/Calendar/Components/CalendarHeader.tsx +39 -0
  127. package/src/components/Calendar/Components/Entries.test.tsx +81 -0
  128. package/src/components/Calendar/Components/Entries.tsx +163 -0
  129. package/src/components/Calendar/Helpers/CalendarMeasurement.tsx +10 -0
  130. package/src/components/Carousel/carousel.module.css +43 -0
  131. package/src/components/Carousel/carousel.module.css.map +1 -0
  132. package/src/components/Carousel/carousel.module.scss +46 -0
  133. package/src/components/Carousel/index.tsx +66 -0
  134. package/src/components/Common/forms/LicenseAuthor.tsx +19 -0
  135. package/src/components/Common/forms/LicenseAuthorUrl.tsx +20 -0
  136. package/src/components/Common/forms/LicenseDerivativeSourceUrl.tsx +20 -0
  137. package/src/components/Common/forms/LicenseObjectUrl.tsx +20 -0
  138. package/src/components/Common/forms/LicenseTitle.tsx +19 -0
  139. package/src/components/Common/forms/WgerTextField.tsx +27 -0
  140. package/src/components/Core/LoadingWidget/LoadingWidget.tsx +22 -0
  141. package/src/components/Core/Modals/DeleteConfirmationModal.test.tsx +57 -0
  142. package/src/components/Core/Modals/DeleteConfirmationModal.tsx +74 -0
  143. package/src/components/Core/Modals/WgerModal.test.tsx +45 -0
  144. package/src/components/Core/Modals/WgerModal.tsx +46 -0
  145. package/src/components/Core/Notifications/index.tsx +57 -0
  146. package/src/components/Core/Notifications/notifications.module.css +8 -0
  147. package/src/components/Core/Notifications/notifications.module.css.map +1 -0
  148. package/src/components/Core/Notifications/notifications.module.scss +6 -0
  149. package/src/components/Core/Tooltips/LightToolTip.tsx +14 -0
  150. package/src/components/Core/Widgets/Container.tsx +98 -0
  151. package/src/components/Core/Widgets/FormError.tsx +64 -0
  152. package/src/components/Core/Widgets/OverviewEmpty.tsx +26 -0
  153. package/src/components/Core/Widgets/RenderLoadingQuery.tsx +28 -0
  154. package/src/components/Core/queries/index.ts +2 -0
  155. package/src/components/Core/queries/languageCheck.ts +31 -0
  156. package/src/components/Dashboard/Dashboard.tsx +22 -0
  157. package/src/components/Dashboard/EmptyCard.tsx +56 -0
  158. package/src/components/Dashboard/NutritionCard.test.tsx +89 -0
  159. package/src/components/Dashboard/NutritionCard.tsx +178 -0
  160. package/src/components/Dashboard/RoutineCard.test.tsx +66 -0
  161. package/src/components/Dashboard/RoutineCard.tsx +107 -0
  162. package/src/components/Dashboard/WeightCard.test.tsx +81 -0
  163. package/src/components/Dashboard/WeightCard.tsx +72 -0
  164. package/src/components/Exercises/Add/AddExerciseStepper.test.tsx +26 -0
  165. package/src/components/Exercises/Add/AddExerciseStepper.tsx +97 -0
  166. package/src/components/Exercises/Add/NotEnoughRights.tsx +37 -0
  167. package/src/components/Exercises/Add/Step1Basics.test.tsx +133 -0
  168. package/src/components/Exercises/Add/Step1Basics.tsx +179 -0
  169. package/src/components/Exercises/Add/Step2Variations.test.tsx +149 -0
  170. package/src/components/Exercises/Add/Step2Variations.tsx +237 -0
  171. package/src/components/Exercises/Add/Step3Description.test.tsx +66 -0
  172. package/src/components/Exercises/Add/Step3Description.tsx +96 -0
  173. package/src/components/Exercises/Add/Step4Translation.test.tsx +119 -0
  174. package/src/components/Exercises/Add/Step4Translations.tsx +183 -0
  175. package/src/components/Exercises/Add/Step5Images.test.tsx +28 -0
  176. package/src/components/Exercises/Add/Step5Images.tsx +269 -0
  177. package/src/components/Exercises/Add/Step6Overview.test.tsx +128 -0
  178. package/src/components/Exercises/Add/Step6Overview.tsx +262 -0
  179. package/src/components/Exercises/Detail/ExerciseDetailEdit.test.tsx +248 -0
  180. package/src/components/Exercises/Detail/ExerciseDetailEdit.tsx +340 -0
  181. package/src/components/Exercises/Detail/ExerciseDetailView.test.tsx +96 -0
  182. package/src/components/Exercises/Detail/ExerciseDetailView.tsx +242 -0
  183. package/src/components/Exercises/Detail/ExerciseDetails.test.tsx +88 -0
  184. package/src/components/Exercises/Detail/ExerciseDetails.tsx +119 -0
  185. package/src/components/Exercises/Detail/ExerciseImageAvatar.tsx +20 -0
  186. package/src/components/Exercises/Detail/ExerciseImagePlaceholder.tsx +21 -0
  187. package/src/components/Exercises/Detail/Head/ExerciseDeleteDialog.test.tsx +125 -0
  188. package/src/components/Exercises/Detail/Head/ExerciseDeleteDialog.tsx +185 -0
  189. package/src/components/Exercises/Detail/Head/head.module.css +73 -0
  190. package/src/components/Exercises/Detail/Head/head.module.css.map +7 -0
  191. package/src/components/Exercises/Detail/Head/head.module.scss +111 -0
  192. package/src/components/Exercises/Detail/Head/index.tsx +175 -0
  193. package/src/components/Exercises/Detail/OverviewCard.test.tsx +98 -0
  194. package/src/components/Exercises/Detail/OverviewCard.tsx +68 -0
  195. package/src/components/Exercises/Detail/SideGallery/index.tsx +65 -0
  196. package/src/components/Exercises/Detail/SideGallery/side_gallery.module.css +26 -0
  197. package/src/components/Exercises/Detail/SideGallery/side_gallery.module.css.map +7 -0
  198. package/src/components/Exercises/Detail/SideGallery/side_gallery.module.scss +34 -0
  199. package/src/components/Exercises/ExerciseOverview.test.tsx +183 -0
  200. package/src/components/Exercises/ExerciseOverview.tsx +293 -0
  201. package/src/components/Exercises/Filter/CategoryFilter.test.tsx +57 -0
  202. package/src/components/Exercises/Filter/CategoryFilter.tsx +105 -0
  203. package/src/components/Exercises/Filter/EquipmentFilter.test.tsx +55 -0
  204. package/src/components/Exercises/Filter/EquipmentFilter.tsx +105 -0
  205. package/src/components/Exercises/Filter/ExerciseFiltersContext.tsx +16 -0
  206. package/src/components/Exercises/Filter/FilterDrawer.tsx +38 -0
  207. package/src/components/Exercises/Filter/MuscleFilter.test.tsx +50 -0
  208. package/src/components/Exercises/Filter/MuscleFilter.tsx +130 -0
  209. package/src/components/Exercises/Filter/NameAutcompleter.tsx +146 -0
  210. package/src/components/Exercises/Filter/NameAutocompleter.test.tsx +76 -0
  211. package/src/components/Exercises/Overview/ExerciseGrid.tsx +44 -0
  212. package/src/components/Exercises/Overview/ExerciseGridLoadingSkeleton.test.tsx +10 -0
  213. package/src/components/Exercises/Overview/ExerciseGridLoadingSkeleton.tsx +26 -0
  214. package/src/components/Exercises/forms/Category.test.tsx +49 -0
  215. package/src/components/Exercises/forms/Category.tsx +41 -0
  216. package/src/components/Exercises/forms/Equipment.test.tsx +84 -0
  217. package/src/components/Exercises/forms/Equipment.tsx +38 -0
  218. package/src/components/Exercises/forms/ExerciseAliases.tsx +37 -0
  219. package/src/components/Exercises/forms/ExerciseDescription.tsx +57 -0
  220. package/src/components/Exercises/forms/ExerciseEquipmentSelect.tsx +29 -0
  221. package/src/components/Exercises/forms/ExerciseName.tsx +19 -0
  222. package/src/components/Exercises/forms/ExerciseNotes.tsx +72 -0
  223. package/src/components/Exercises/forms/ExerciseSelect.tsx +28 -0
  224. package/src/components/Exercises/forms/ImageCard.tsx +101 -0
  225. package/src/components/Exercises/forms/ImageStyle.tsx +74 -0
  226. package/src/components/Exercises/forms/Muscle.test.tsx +74 -0
  227. package/src/components/Exercises/forms/Muscle.tsx +41 -0
  228. package/src/components/Exercises/forms/VideoCard.tsx +109 -0
  229. package/src/components/Exercises/forms/yupValidators.ts +46 -0
  230. package/src/components/Exercises/models/alias.ts +29 -0
  231. package/src/components/Exercises/models/category.ts +35 -0
  232. package/src/components/Exercises/models/equipment.ts +33 -0
  233. package/src/components/Exercises/models/exercise.test.ts +74 -0
  234. package/src/components/Exercises/models/exercise.ts +159 -0
  235. package/src/components/Exercises/models/image.ts +41 -0
  236. package/src/components/Exercises/models/language.ts +23 -0
  237. package/src/components/Exercises/models/muscle.test.ts +17 -0
  238. package/src/components/Exercises/models/muscle.ts +39 -0
  239. package/src/components/Exercises/models/note.ts +29 -0
  240. package/src/components/Exercises/models/translation.test.ts +68 -0
  241. package/src/components/Exercises/models/translation.ts +83 -0
  242. package/src/components/Exercises/models/video.ts +30 -0
  243. package/src/components/Exercises/queries/exercises.ts +29 -0
  244. package/src/components/Exercises/queries/index.ts +133 -0
  245. package/src/components/Exercises/queries/variations.ts +15 -0
  246. package/src/components/Header/SubMenus/BodyWeightSubMenu.tsx +27 -0
  247. package/src/components/Header/SubMenus/MeasurementsSubMenu.tsx +28 -0
  248. package/src/components/Header/SubMenus/NutritionSubMenu.tsx +28 -0
  249. package/src/components/Header/SubMenus/TrainingSubMenu.tsx +43 -0
  250. package/src/components/Header/SubMenus/WorkoutSubMenu.tsx +28 -0
  251. package/src/components/Header/index.tsx +27 -0
  252. package/src/components/Measurements/Screens/MeasurementCategoryDetail.test.tsx +67 -0
  253. package/src/components/Measurements/Screens/MeasurementCategoryDetail.tsx +37 -0
  254. package/src/components/Measurements/Screens/MeasurementCategoryOverview.test.tsx +59 -0
  255. package/src/components/Measurements/Screens/MeasurementCategoryOverview.tsx +64 -0
  256. package/src/components/Measurements/models/Category.ts +38 -0
  257. package/src/components/Measurements/models/Entry.ts +37 -0
  258. package/src/components/Measurements/queries/index.ts +121 -0
  259. package/src/components/Measurements/widgets/CategoryDetailDataGrid.tsx +209 -0
  260. package/src/components/Measurements/widgets/CategoryDetailDropdown.tsx +83 -0
  261. package/src/components/Measurements/widgets/CategoryForm.test.tsx +96 -0
  262. package/src/components/Measurements/widgets/CategoryForm.tsx +88 -0
  263. package/src/components/Measurements/widgets/EntryForm.test.tsx +120 -0
  264. package/src/components/Measurements/widgets/EntryForm.tsx +139 -0
  265. package/src/components/Measurements/widgets/MeasurementChart.tsx +52 -0
  266. package/src/components/Measurements/widgets/fab.tsx +65 -0
  267. package/src/components/Muscles/MuscleOverview.tsx +37 -0
  268. package/src/components/Nutrition/components/BmiCalculator.test.tsx +55 -0
  269. package/src/components/Nutrition/components/BmiCalculator.tsx +203 -0
  270. package/src/components/Nutrition/components/IngredientSearch.tsx +24 -0
  271. package/src/components/Nutrition/components/NutritionDiaryOverview.test.tsx +51 -0
  272. package/src/components/Nutrition/components/NutritionDiaryOverview.tsx +47 -0
  273. package/src/components/Nutrition/components/PlanDetail.test.tsx +58 -0
  274. package/src/components/Nutrition/components/PlanDetail.tsx +100 -0
  275. package/src/components/Nutrition/components/PlanOverview.test.tsx +37 -0
  276. package/src/components/Nutrition/components/PlansOverview.tsx +62 -0
  277. package/src/components/Nutrition/helpers/nutritionalValues.test.ts +108 -0
  278. package/src/components/Nutrition/helpers/nutritionalValues.ts +128 -0
  279. package/src/components/Nutrition/models/Ingredient.ts +84 -0
  280. package/src/components/Nutrition/models/IngredientImage.ts +57 -0
  281. package/src/components/Nutrition/models/IngredientImageThumbnails.ts +59 -0
  282. package/src/components/Nutrition/models/diaryEntry.ts +129 -0
  283. package/src/components/Nutrition/models/ingredient.test.ts +37 -0
  284. package/src/components/Nutrition/models/meal.test.ts +54 -0
  285. package/src/components/Nutrition/models/meal.ts +128 -0
  286. package/src/components/Nutrition/models/mealItem.test.ts +23 -0
  287. package/src/components/Nutrition/models/mealItem.ts +134 -0
  288. package/src/components/Nutrition/models/nutritionalPlan.test.ts +169 -0
  289. package/src/components/Nutrition/models/nutritionalPlan.ts +268 -0
  290. package/src/components/Nutrition/models/weightUnit.ts +24 -0
  291. package/src/components/Nutrition/queries/diary.ts +59 -0
  292. package/src/components/Nutrition/queries/index.ts +20 -0
  293. package/src/components/Nutrition/queries/ingredient.ts +12 -0
  294. package/src/components/Nutrition/queries/meal.ts +41 -0
  295. package/src/components/Nutrition/queries/mealItem.ts +43 -0
  296. package/src/components/Nutrition/queries/plan.ts +93 -0
  297. package/src/components/Nutrition/widgets/DiaryDetail.tsx +39 -0
  298. package/src/components/Nutrition/widgets/DiaryOverview.tsx +51 -0
  299. package/src/components/Nutrition/widgets/Fab.tsx +65 -0
  300. package/src/components/Nutrition/widgets/IngredientAutcompleter.tsx +140 -0
  301. package/src/components/Nutrition/widgets/IngredientAutocompleter.test.tsx +60 -0
  302. package/src/components/Nutrition/widgets/IngredientDetailTable.tsx +91 -0
  303. package/src/components/Nutrition/widgets/LoggedPlannedNutritionalValuesTable.tsx +138 -0
  304. package/src/components/Nutrition/widgets/MealDetail.tsx +170 -0
  305. package/src/components/Nutrition/widgets/MealDetailDropdown.tsx +117 -0
  306. package/src/components/Nutrition/widgets/NutritionalValuesTable.tsx +103 -0
  307. package/src/components/Nutrition/widgets/PlanDetailDropdown.tsx +82 -0
  308. package/src/components/Nutrition/widgets/PlanSidebar.tsx +44 -0
  309. package/src/components/Nutrition/widgets/charts/LinearPlannedLoggedChart.tsx +27 -0
  310. package/src/components/Nutrition/widgets/charts/MacrosPieChart.tsx +66 -0
  311. package/src/components/Nutrition/widgets/charts/NutritionDiaryChart.tsx +95 -0
  312. package/src/components/Nutrition/widgets/charts/NutritionalValuesDashboardChart.tsx +84 -0
  313. package/src/components/Nutrition/widgets/charts/NutritionalValuesPlannedLoggedChart.tsx +54 -0
  314. package/src/components/Nutrition/widgets/forms/MealForm.test.tsx +85 -0
  315. package/src/components/Nutrition/widgets/forms/MealForm.tsx +105 -0
  316. package/src/components/Nutrition/widgets/forms/MealItemForm.test.tsx +106 -0
  317. package/src/components/Nutrition/widgets/forms/MealItemForm.tsx +118 -0
  318. package/src/components/Nutrition/widgets/forms/NutritionDiaryEntryForm.test.tsx +165 -0
  319. package/src/components/Nutrition/widgets/forms/NutritionDiaryEntryForm.tsx +161 -0
  320. package/src/components/Nutrition/widgets/forms/PlanForm.test.tsx +101 -0
  321. package/src/components/Nutrition/widgets/forms/PlanForm.tsx +361 -0
  322. package/src/components/User/models/profile.ts +81 -0
  323. package/src/components/User/queries/contribute.test.ts +132 -0
  324. package/src/components/User/queries/contribute.ts +33 -0
  325. package/src/components/User/queries/permission.ts +11 -0
  326. package/src/components/User/queries/profile.ts +22 -0
  327. package/src/components/WorkoutRoutines/Detail/RoutineAdd.tsx +12 -0
  328. package/src/components/WorkoutRoutines/Detail/RoutineDetail.test.tsx +71 -0
  329. package/src/components/WorkoutRoutines/Detail/RoutineDetail.tsx +87 -0
  330. package/src/components/WorkoutRoutines/Detail/RoutineDetailsTable.test.tsx +83 -0
  331. package/src/components/WorkoutRoutines/Detail/RoutineDetailsTable.tsx +371 -0
  332. package/src/components/WorkoutRoutines/Detail/RoutineEdit.test.tsx +51 -0
  333. package/src/components/WorkoutRoutines/Detail/RoutineEdit.tsx +95 -0
  334. package/src/components/WorkoutRoutines/Detail/SessionAdd.test.tsx +43 -0
  335. package/src/components/WorkoutRoutines/Detail/SessionAdd.tsx +50 -0
  336. package/src/components/WorkoutRoutines/Detail/SlotProgressionEdit.test.tsx +41 -0
  337. package/src/components/WorkoutRoutines/Detail/SlotProgressionEdit.tsx +145 -0
  338. package/src/components/WorkoutRoutines/Detail/TemplateDetail.test.tsx +44 -0
  339. package/src/components/WorkoutRoutines/Detail/TemplateDetail.tsx +84 -0
  340. package/src/components/WorkoutRoutines/Detail/WorkoutLogs.test.tsx +64 -0
  341. package/src/components/WorkoutRoutines/Detail/WorkoutLogs.tsx +98 -0
  342. package/src/components/WorkoutRoutines/Detail/WorkoutStats.test.tsx +65 -0
  343. package/src/components/WorkoutRoutines/Detail/WorkoutStats.tsx +244 -0
  344. package/src/components/WorkoutRoutines/Overview/Fab.tsx +91 -0
  345. package/src/components/WorkoutRoutines/Overview/PrivateTemplateOverview.test.tsx +36 -0
  346. package/src/components/WorkoutRoutines/Overview/PrivateTemplateOverview.tsx +41 -0
  347. package/src/components/WorkoutRoutines/Overview/PublicTemplateOverview.test.tsx +36 -0
  348. package/src/components/WorkoutRoutines/Overview/PublicTemplateOverview.tsx +40 -0
  349. package/src/components/WorkoutRoutines/Overview/RoutineOverview.test.tsx +38 -0
  350. package/src/components/WorkoutRoutines/Overview/RoutineOverview.tsx +76 -0
  351. package/src/components/WorkoutRoutines/models/BaseConfig.ts +118 -0
  352. package/src/components/WorkoutRoutines/models/Day.test.ts +15 -0
  353. package/src/components/WorkoutRoutines/models/Day.ts +117 -0
  354. package/src/components/WorkoutRoutines/models/LogStats.test.ts +44 -0
  355. package/src/components/WorkoutRoutines/models/LogStats.ts +110 -0
  356. package/src/components/WorkoutRoutines/models/RepetitionUnit.ts +22 -0
  357. package/src/components/WorkoutRoutines/models/Routine.test.ts +113 -0
  358. package/src/components/WorkoutRoutines/models/Routine.ts +218 -0
  359. package/src/components/WorkoutRoutines/models/RoutineDayData.ts +38 -0
  360. package/src/components/WorkoutRoutines/models/RoutineLogData.ts +22 -0
  361. package/src/components/WorkoutRoutines/models/SetConfigData.ts +121 -0
  362. package/src/components/WorkoutRoutines/models/Slot.test.ts +19 -0
  363. package/src/components/WorkoutRoutines/models/Slot.ts +83 -0
  364. package/src/components/WorkoutRoutines/models/SlotData.ts +30 -0
  365. package/src/components/WorkoutRoutines/models/SlotEntry.test.ts +31 -0
  366. package/src/components/WorkoutRoutines/models/SlotEntry.ts +245 -0
  367. package/src/components/WorkoutRoutines/models/WeightUnit.ts +22 -0
  368. package/src/components/WorkoutRoutines/models/WorkoutLog.ts +159 -0
  369. package/src/components/WorkoutRoutines/models/WorkoutSession.ts +124 -0
  370. package/src/components/WorkoutRoutines/queries/configs.ts +393 -0
  371. package/src/components/WorkoutRoutines/queries/days.ts +42 -0
  372. package/src/components/WorkoutRoutines/queries/index.ts +64 -0
  373. package/src/components/WorkoutRoutines/queries/logs.ts +49 -0
  374. package/src/components/WorkoutRoutines/queries/routines.ts +121 -0
  375. package/src/components/WorkoutRoutines/queries/sessions.ts +41 -0
  376. package/src/components/WorkoutRoutines/queries/slot_entries.ts +33 -0
  377. package/src/components/WorkoutRoutines/queries/slots.ts +40 -0
  378. package/src/components/WorkoutRoutines/queries/units.ts +15 -0
  379. package/src/components/WorkoutRoutines/widgets/DayDetails.test.tsx +69 -0
  380. package/src/components/WorkoutRoutines/widgets/DayDetails.tsx +441 -0
  381. package/src/components/WorkoutRoutines/widgets/LogWidgets.test.tsx +91 -0
  382. package/src/components/WorkoutRoutines/widgets/LogWidgets.tsx +334 -0
  383. package/src/components/WorkoutRoutines/widgets/RoutineDetailDropdown.test.tsx +36 -0
  384. package/src/components/WorkoutRoutines/widgets/RoutineDetailDropdown.tsx +184 -0
  385. package/src/components/WorkoutRoutines/widgets/RoutineDetailsCard.test.tsx +42 -0
  386. package/src/components/WorkoutRoutines/widgets/RoutineDetailsCard.tsx +202 -0
  387. package/src/components/WorkoutRoutines/widgets/RoutineStatistics.test.tsx +364 -0
  388. package/src/components/WorkoutRoutines/widgets/RoutineStatistics.tsx +249 -0
  389. package/src/components/WorkoutRoutines/widgets/SlotDetails.test.tsx +72 -0
  390. package/src/components/WorkoutRoutines/widgets/SlotDetails.tsx +233 -0
  391. package/src/components/WorkoutRoutines/widgets/forms/BaseConfigForm.test.tsx +161 -0
  392. package/src/components/WorkoutRoutines/widgets/forms/BaseConfigForm.tsx +508 -0
  393. package/src/components/WorkoutRoutines/widgets/forms/DayForm.test.tsx +86 -0
  394. package/src/components/WorkoutRoutines/widgets/forms/DayForm.tsx +202 -0
  395. package/src/components/WorkoutRoutines/widgets/forms/ProgressionForm.test.tsx +176 -0
  396. package/src/components/WorkoutRoutines/widgets/forms/ProgressionForm.tsx +494 -0
  397. package/src/components/WorkoutRoutines/widgets/forms/RoutineForm.test.tsx +94 -0
  398. package/src/components/WorkoutRoutines/widgets/forms/RoutineForm.tsx +309 -0
  399. package/src/components/WorkoutRoutines/widgets/forms/RoutineTemplateForm.test.tsx +70 -0
  400. package/src/components/WorkoutRoutines/widgets/forms/RoutineTemplateForm.tsx +68 -0
  401. package/src/components/WorkoutRoutines/widgets/forms/SessionForm.test.tsx +164 -0
  402. package/src/components/WorkoutRoutines/widgets/forms/SessionForm.tsx +263 -0
  403. package/src/components/WorkoutRoutines/widgets/forms/SessionLogsForm.test.tsx +126 -0
  404. package/src/components/WorkoutRoutines/widgets/forms/SessionLogsForm.tsx +330 -0
  405. package/src/components/WorkoutRoutines/widgets/forms/SlotEntryForm.test.tsx +227 -0
  406. package/src/components/WorkoutRoutines/widgets/forms/SlotEntryForm.tsx +206 -0
  407. package/src/components/WorkoutRoutines/widgets/forms/SlotForm.test.tsx +44 -0
  408. package/src/components/WorkoutRoutines/widgets/forms/SlotForm.tsx +36 -0
  409. package/src/components/index.ts +3 -0
  410. package/src/config.ts +12 -0
  411. package/src/i18n.ts +63 -0
  412. package/src/i18n.tsx +52 -0
  413. package/src/index.css +13 -0
  414. package/src/index.tsx +184 -0
  415. package/src/locales/README.md +7 -0
  416. package/src/pages/About/index.tsx +9 -0
  417. package/src/pages/AddExercise/index.tsx +15 -0
  418. package/src/pages/AddWeight/index.tsx +9 -0
  419. package/src/pages/ApiPage/index.tsx +9 -0
  420. package/src/pages/Calendar/index.tsx +10 -0
  421. package/src/pages/CaloriesCalculator/index.tsx +9 -0
  422. package/src/pages/Equipments/index.tsx +9 -0
  423. package/src/pages/ExerciseDetails/index.tsx +6 -0
  424. package/src/pages/Ingrdedients/index.tsx +9 -0
  425. package/src/pages/Login/index.tsx +9 -0
  426. package/src/pages/Preferences/index.tsx +9 -0
  427. package/src/pages/PublicTemplate/index.tsx +9 -0
  428. package/src/pages/TemplatePage/index.tsx +9 -0
  429. package/src/pages/WeightOverview/index.tsx +6 -0
  430. package/src/pages/index.ts +14 -0
  431. package/src/permissions/index.ts +13 -0
  432. package/src/reportWebVitals.ts +15 -0
  433. package/src/routes.tsx +137 -0
  434. package/src/services/alias.test.ts +47 -0
  435. package/src/services/alias.ts +34 -0
  436. package/src/services/base_config.test.ts +48 -0
  437. package/src/services/base_config.ts +86 -0
  438. package/src/services/category.test.ts +44 -0
  439. package/src/services/category.ts +21 -0
  440. package/src/services/config.test.ts +213 -0
  441. package/src/services/config.ts +50 -0
  442. package/src/services/day.test.ts +118 -0
  443. package/src/services/day.ts +44 -0
  444. package/src/services/equipment.test.ts +46 -0
  445. package/src/services/equipment.ts +20 -0
  446. package/src/services/exercise.test.ts +98 -0
  447. package/src/services/exercise.ts +182 -0
  448. package/src/services/exerciseTranslation.test.ts +98 -0
  449. package/src/services/exerciseTranslation.ts +112 -0
  450. package/src/services/image.test.ts +77 -0
  451. package/src/services/image.ts +54 -0
  452. package/src/services/index.ts +104 -0
  453. package/src/services/ingredient.test.ts +81 -0
  454. package/src/services/ingredient.ts +70 -0
  455. package/src/services/ingredientweightunit.ts +29 -0
  456. package/src/services/language.test.ts +86 -0
  457. package/src/services/language.ts +35 -0
  458. package/src/services/languageCheck.ts +33 -0
  459. package/src/services/meal.ts +67 -0
  460. package/src/services/mealItem.ts +32 -0
  461. package/src/services/measurements.test.ts +106 -0
  462. package/src/services/measurements.ts +173 -0
  463. package/src/services/muscles.test.ts +46 -0
  464. package/src/services/muscles.ts +20 -0
  465. package/src/services/note.ts +39 -0
  466. package/src/services/nutritionalDiary.test.ts +35 -0
  467. package/src/services/nutritionalDiary.ts +70 -0
  468. package/src/services/nutritionalPlan.test.ts +74 -0
  469. package/src/services/nutritionalPlan.ts +104 -0
  470. package/src/services/permission.ts +26 -0
  471. package/src/services/permissions.test.ts +34 -0
  472. package/src/services/profile.test.ts +40 -0
  473. package/src/services/profile.ts +49 -0
  474. package/src/services/responseType.ts +35 -0
  475. package/src/services/routine.test.ts +195 -0
  476. package/src/services/routine.ts +250 -0
  477. package/src/services/session.test.ts +157 -0
  478. package/src/services/session.ts +99 -0
  479. package/src/services/slot.test.ts +68 -0
  480. package/src/services/slot.ts +43 -0
  481. package/src/services/slot_entry.ts +43 -0
  482. package/src/services/variation.test.ts +24 -0
  483. package/src/services/variation.ts +18 -0
  484. package/src/services/video.test.ts +65 -0
  485. package/src/services/video.ts +47 -0
  486. package/src/services/weight.test.ts +75 -0
  487. package/src/services/weight.ts +58 -0
  488. package/src/services/workoutLogs.test.ts +148 -0
  489. package/src/services/workoutLogs.ts +89 -0
  490. package/src/services/workoutUnits.ts +29 -0
  491. package/src/setupTests.ts +40 -0
  492. package/src/state/exerciseSubmissionReducer.ts +170 -0
  493. package/src/state/exerciseSubmissionState.tsx +75 -0
  494. package/src/state/index.ts +15 -0
  495. package/src/state/notificationReducer.ts +29 -0
  496. package/src/state/notificationState.tsx +32 -0
  497. package/src/state/stateTypes.ts +24 -0
  498. package/src/tests/api/ingredientInfoEndpoint.ts +72 -0
  499. package/src/tests/exerciseTestdata.ts +159 -0
  500. package/src/tests/exercises/searchResponse.ts +23 -0
  501. package/src/tests/ingredientTestdata.ts +76 -0
  502. package/src/tests/measurementsTestData.ts +40 -0
  503. package/src/tests/nutritionDiaryTestdata.ts +167 -0
  504. package/src/tests/nutritionTestdata.ts +200 -0
  505. package/src/tests/queryClient/index.ts +7 -0
  506. package/src/tests/responseApi.ts +197 -0
  507. package/src/tests/setup.ts +10 -0
  508. package/src/tests/slotEntryApiResponse.ts +144 -0
  509. package/src/tests/userTestdata.ts +43 -0
  510. package/src/tests/weight/testData.ts +7 -0
  511. package/src/tests/workoutLogsRoutinesTestData.ts +90 -0
  512. package/src/tests/workoutRoutinesTestData.ts +451 -0
  513. package/src/tests/workoutStatisticsTestData.ts +219 -0
  514. package/src/theme.ts +73 -0
  515. package/src/types.ts +144 -0
  516. package/src/utils/Adapter.ts +10 -0
  517. package/src/utils/colors.test.ts +38 -0
  518. package/src/utils/colors.ts +17 -0
  519. package/src/utils/consts.ts +160 -0
  520. package/src/utils/date.test.ts +56 -0
  521. package/src/utils/date.ts +145 -0
  522. package/src/utils/forms.test.ts +41 -0
  523. package/src/utils/forms.ts +54 -0
  524. package/src/utils/numbers.test.ts +55 -0
  525. package/src/utils/numbers.ts +42 -0
  526. package/src/utils/requests.test.ts +61 -0
  527. package/src/utils/requests.ts +22 -0
  528. package/src/utils/strings.test.ts +62 -0
  529. package/src/utils/strings.ts +28 -0
  530. package/src/utils/url.test.ts +127 -0
  531. package/src/utils/url.ts +237 -0
@@ -0,0 +1,161 @@
1
+ import { Autocomplete, Button, InputAdornment, Stack, TextField } from "@mui/material";
2
+ import { DateTimePicker, LocalizationProvider } from "@mui/x-date-pickers";
3
+ import { AdapterLuxon } from "@mui/x-date-pickers/AdapterLuxon";
4
+ import { DiaryEntry } from "components/Nutrition/models/diaryEntry";
5
+ import { Ingredient } from "components/Nutrition/models/Ingredient";
6
+ import { Meal } from "components/Nutrition/models/meal";
7
+ import { useAddDiaryEntryQuery, useEditDiaryEntryQuery } from "components/Nutrition/queries";
8
+ import { IngredientAutocompleter } from "components/Nutrition/widgets/IngredientAutcompleter";
9
+ import { Form, Formik } from "formik";
10
+ import { DateTime } from "luxon";
11
+ import React, { useState } from 'react';
12
+ import { useTranslation } from "react-i18next";
13
+ import { dateToYYYYMMDD } from "utils/date";
14
+ import * as yup from "yup";
15
+
16
+ type NutritionDiaryEntryFormProps = {
17
+ planId: number,
18
+ entry?: DiaryEntry,
19
+ mealId?: number | null,
20
+ meals?: Meal[],
21
+ closeFn?: () => void,
22
+ }
23
+
24
+ export const NutritionDiaryEntryForm = ({ planId, entry, mealId, meals, closeFn }: NutritionDiaryEntryFormProps) => {
25
+
26
+ const meal = mealId === undefined ? null : mealId;
27
+ const mealObjs = meals === undefined ? [] : meals;
28
+
29
+ const [t, i18n] = useTranslation();
30
+ const addDiaryQuery = useAddDiaryEntryQuery(planId);
31
+ const editDiaryQuery = useEditDiaryEntryQuery(planId);
32
+ const [dateValue, setDateValue] = useState<DateTime | null>(entry ? DateTime.fromJSDate(entry.datetime) : DateTime.now());
33
+ const [selectedMeal, setSelectedMeal] = useState<number | null>(meal);
34
+ const validationSchema = yup.object({
35
+ amount: yup
36
+ .number()
37
+ .required(t('forms.fieldRequired'))
38
+ .max(1000, t('forms.maxValue', { value: '1000' }))
39
+ .min(1, t('forms.minValue', { value: '1' })),
40
+ ingredient: yup
41
+ .number()
42
+ .required(t('forms.fieldRequired')),
43
+ datetime: yup
44
+ .date()
45
+ .required(t('forms.fieldRequired')),
46
+ });
47
+
48
+
49
+ return (
50
+ (<Formik
51
+ initialValues={{
52
+ datetime: new Date(),
53
+ amount: 0,
54
+ ingredient: 0,
55
+ }}
56
+ validationSchema={validationSchema}
57
+ onSubmit={async (values) => {
58
+
59
+ // Make sure "amount" is a number
60
+ const newAmount = Number(values.amount);
61
+
62
+ if (entry) {
63
+ // Edit
64
+ const newDiaryEntry = DiaryEntry.clone(entry, {
65
+ mealId: selectedMeal,
66
+ planId: planId,
67
+ amount: newAmount,
68
+ datetime: values.datetime,
69
+ ingredientId: values.ingredient
70
+ });
71
+ editDiaryQuery.mutate(newDiaryEntry);
72
+ } else {
73
+ // Add
74
+ addDiaryQuery.mutate(new DiaryEntry({
75
+ planId: planId,
76
+ amount: newAmount,
77
+ datetime: values.datetime,
78
+ ingredientId: values.ingredient,
79
+ mealId: selectedMeal,
80
+ }));
81
+ }
82
+
83
+ // if closeFn is defined, close the modal (this form does not have to be displayed in one)
84
+ if (closeFn) {
85
+ closeFn();
86
+ }
87
+ }}
88
+ >
89
+ {formik => (
90
+ <Form>
91
+ <Stack spacing={2}>
92
+ <IngredientAutocompleter
93
+ callback={(value: Ingredient | null) => formik.setFieldValue('ingredient', value?.id)} />
94
+ <TextField
95
+ fullWidth
96
+ id="amount"
97
+ label={'amount'}
98
+ slotProps={{
99
+ input: {
100
+ endAdornment: <InputAdornment position="end">
101
+ {t('nutrition.gramShort')}
102
+ </InputAdornment>
103
+ }
104
+ }}
105
+ error={formik.touched.amount && Boolean(formik.errors.amount)}
106
+ helperText={formik.touched.amount && formik.errors.amount}
107
+ {...formik.getFieldProps('amount')}
108
+ />
109
+ {mealObjs.length > 0 && <Autocomplete
110
+ value={selectedMeal}
111
+ options={mealObjs.map(e => e.id)}
112
+ getOptionLabel={option => mealObjs.find(e => e.id === option)!.displayName!}
113
+ onChange={(event, newValue) => setSelectedMeal(newValue)}
114
+ renderInput={params => (
115
+ <TextField
116
+ label={t("nutrition.meal")}
117
+ value={selectedMeal}
118
+ {...params}
119
+ />
120
+ )}
121
+ />}
122
+ <LocalizationProvider dateAdapter={AdapterLuxon} adapterLocale={i18n.language}>
123
+
124
+ <DateTimePicker
125
+ format="yyyy-MM-dd HH:mm"
126
+ label={t('date')}
127
+ value={dateValue}
128
+ disableFuture={true}
129
+ onChange={(newValue) => {
130
+ formik.setFieldValue('datetime', newValue?.toJSDate());
131
+
132
+ setDateValue(newValue);
133
+ }}
134
+ shouldDisableDate={(date) => {
135
+
136
+ // Allow the date of the current weight entry, since we are editing it
137
+ // @ts-ignore - date is a Luxon DateTime!
138
+ if (entry && dateToYYYYMMDD(entry.datetime) === dateToYYYYMMDD(date.toJSDate())) {
139
+ return false;
140
+ }
141
+
142
+ // all other dates are allowed
143
+ return false;
144
+ }}
145
+ />
146
+ </LocalizationProvider>
147
+ <Stack direction="row" justifyContent="end" spacing={2}>
148
+ {closeFn !== undefined
149
+ && <Button color="primary" variant="outlined" onClick={() => closeFn()}>
150
+ {t('close')}
151
+ </Button>}
152
+ <Button color="primary" variant="contained" type="submit">
153
+ {t('submit')}
154
+ </Button>
155
+ </Stack>
156
+ </Stack>
157
+ </Form>
158
+ )}
159
+ </Formik>)
160
+ );
161
+ };
@@ -0,0 +1,101 @@
1
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2
+ import { render, screen } from '@testing-library/react';
3
+ import userEvent from "@testing-library/user-event";
4
+
5
+ import { useAddNutritionalPlanQuery, useEditNutritionalPlanQuery } from "components/Nutrition/queries";
6
+ import { PlanForm } from "components/Nutrition/widgets/forms/PlanForm";
7
+ import React from 'react';
8
+ import { TEST_NUTRITIONAL_PLAN_1 } from "tests/nutritionTestdata";
9
+
10
+ jest.mock("services/weight");
11
+ jest.mock("components/Nutrition/queries");
12
+
13
+ describe("Test the PlanForm component", () => {
14
+ const queryClient = new QueryClient();
15
+ let mutate = jest.fn();
16
+
17
+ beforeEach(() => {
18
+ mutate = jest.fn();
19
+
20
+ (useEditNutritionalPlanQuery as jest.Mock).mockImplementation(() => ({
21
+ mutate: mutate
22
+ }));
23
+
24
+ (useAddNutritionalPlanQuery as jest.Mock).mockImplementation(() => ({
25
+ mutate: mutate
26
+ }));
27
+ });
28
+
29
+ test('Passing an existing plan renders its values in the form', () => {
30
+
31
+ // Act
32
+ render(
33
+ <QueryClientProvider client={queryClient}>
34
+ <PlanForm plan={TEST_NUTRITIONAL_PLAN_1} />
35
+ </QueryClientProvider>
36
+ );
37
+
38
+ // Assert
39
+ expect(screen.getByDisplayValue('Summer body!!!')).toBeInTheDocument();
40
+ expect(screen.getByRole('button', { name: 'submit' })).toBeInTheDocument();
41
+ });
42
+
43
+ test('Editing an existing plan', async () => {
44
+
45
+ // Arrange
46
+ const user = userEvent.setup();
47
+
48
+
49
+ // Act
50
+ render(
51
+ <QueryClientProvider client={queryClient}>
52
+ <PlanForm plan={TEST_NUTRITIONAL_PLAN_1} />
53
+ </QueryClientProvider>
54
+ );
55
+ const descriptionInput = await screen.findByLabelText('description');
56
+ await user.clear(descriptionInput);
57
+ await user.type(descriptionInput, 'a better name');
58
+
59
+ // Assert
60
+ await user.click(screen.getByRole('button', { name: 'submit' }));
61
+ expect(mutate).toHaveBeenCalledWith(expect.objectContaining({
62
+ id: 101,
63
+ description: "a better name",
64
+ goalCarbohydrates: null,
65
+ goalFiber: null,
66
+ goalEnergy: null,
67
+ goalFat: null,
68
+ goalProtein: null,
69
+ onlyLogging: false,
70
+ })
71
+ );
72
+ });
73
+
74
+ test('Creating a new plan', async () => {
75
+ // Arrange
76
+ const user = userEvent.setup();
77
+
78
+ // Act
79
+ render(
80
+ <QueryClientProvider client={queryClient}>
81
+ <PlanForm />
82
+ </QueryClientProvider>
83
+ );
84
+ const descriptionInput = await screen.findByLabelText('description');
85
+ await user.clear(descriptionInput);
86
+ await user.type(descriptionInput, 'a new, cool plan');
87
+
88
+ // Assert
89
+ await user.click(screen.getByRole('button', { name: 'submit' }));
90
+ expect(mutate).toHaveBeenCalledWith(expect.objectContaining({
91
+ description: 'a new, cool plan',
92
+ onlyLogging: true,
93
+ goalCarbohydrates: null,
94
+ goalEnergy: null,
95
+ goalFat: null,
96
+ goalProtein: null,
97
+ goalFiber: null,
98
+ })
99
+ );
100
+ });
101
+ });
@@ -0,0 +1,361 @@
1
+ import {
2
+ Button,
3
+ FormControlLabel,
4
+ FormGroup,
5
+ FormHelperText,
6
+ InputAdornment,
7
+ Stack,
8
+ Switch,
9
+ TextField
10
+ } from "@mui/material";
11
+ import Grid from '@mui/material/Grid';
12
+ import { DatePicker, LocalizationProvider } from "@mui/x-date-pickers";
13
+ import { AdapterLuxon } from "@mui/x-date-pickers/AdapterLuxon";
14
+
15
+ import { ENERGY_FACTOR } from "components/Nutrition/helpers/nutritionalValues";
16
+ import { NutritionalPlan } from "components/Nutrition/models/nutritionalPlan";
17
+ import { useAddNutritionalPlanQuery, useEditNutritionalPlanQuery } from "components/Nutrition/queries";
18
+ import { Form, Formik } from "formik";
19
+ import i18n from "i18n";
20
+ import { DateTime } from "luxon";
21
+ import React, { useState } from 'react';
22
+ import { useTranslation } from "react-i18next";
23
+ import { dateToYYYYMMDD } from "utils/date";
24
+ import * as yup from 'yup';
25
+
26
+ interface PlanFormProps {
27
+ plan?: NutritionalPlan,
28
+ closeFn?: () => void,
29
+ }
30
+
31
+ export const PlanForm = ({ plan, closeFn }: PlanFormProps) => {
32
+
33
+ const [t] = useTranslation();
34
+ const addPlanQuery = useAddNutritionalPlanQuery();
35
+ const editPlanQuery = useEditNutritionalPlanQuery(plan?.id || 0);
36
+ const [useGoals, setUseGoals] = useState(plan?.hasAnyGoals);
37
+ const [startDateValue, setStartDateValue] = useState<DateTime | null>(plan ? DateTime.fromJSDate(plan.start) : DateTime.now);
38
+ const [endDateValue, setEndDateValue] = useState<DateTime | null>(plan && plan?.end !== null ? DateTime.fromJSDate(plan!.end) : null);
39
+
40
+ const validationSchema = yup.object({
41
+ description: yup
42
+ .string()
43
+ .required()
44
+ .max(25, t('forms.maxLength', { chars: '25' }))
45
+ .min(3, t('forms.minLength', { chars: '3' })),
46
+ onlyLogging: yup
47
+ .boolean(),
48
+ goalEnergy: yup
49
+ .number()
50
+ .notRequired()
51
+ .positive()
52
+ .max(6000, t('forms.maxValue', { value: '6000kcal' })),
53
+ goalProtein: yup
54
+ .number()
55
+ .notRequired()
56
+ .positive()
57
+ .max(500, t('forms.maxValue', { value: '500' })),
58
+ goalCarbohydrates: yup
59
+ .number()
60
+ .notRequired()
61
+ .positive() // TODO: allow 0 but not negative
62
+ .max(750, t('forms.maxValue', { value: '750' })),
63
+ goalFiber: yup
64
+ .number()
65
+ .notRequired()
66
+ .positive()
67
+ .max(500, t('forms.maxValue', { value: '500' })),
68
+ goalFat: yup
69
+ .number()
70
+ .notRequired()
71
+ .positive()
72
+ .max(500, t('forms.maxValue', { value: '500' })),
73
+ start: yup
74
+ .date()
75
+ .required(),
76
+ end: yup
77
+ .date()
78
+ .nullable()
79
+ .min(
80
+ yup.ref('start'),
81
+ t('forms.endBeforeStart')
82
+ )
83
+ });
84
+
85
+
86
+ return (
87
+ (<Formik
88
+ initialValues={{
89
+ description: plan ? plan.description : t('nutrition.plan'),
90
+
91
+ start: dateToYYYYMMDD(new Date()),
92
+ end: null,
93
+
94
+ onlyLogging: plan ? plan.onlyLogging : true,
95
+ goalEnergy: plan ? plan.goalEnergy : null,
96
+ goalProtein: plan ? plan.goalProtein : null,
97
+ goalCarbohydrates: plan ? plan.goalCarbohydrates : null,
98
+ goalFiber: plan ? plan.goalFiber : null,
99
+ goalFat: plan ? plan.goalFat : null,
100
+ }}
101
+ validationSchema={validationSchema}
102
+ onSubmit={async (values) => {
103
+ values.goalEnergy = values.goalEnergy ? values.goalEnergy : null;
104
+ values.goalProtein = values.goalProtein ? values.goalProtein : null;
105
+ values.goalCarbohydrates = values.goalCarbohydrates ? values.goalCarbohydrates : null;
106
+ values.goalFiber = values.goalFiber ? values.goalFiber : null;
107
+ values.goalFat = values.goalFat ? values.goalFat : null;
108
+
109
+ if (!useGoals) {
110
+ values.goalEnergy = null;
111
+ values.goalProtein = null;
112
+ values.goalCarbohydrates = null;
113
+ values.goalFiber = null;
114
+ values.goalFat = null;
115
+ }
116
+
117
+
118
+ const newPlan = new NutritionalPlan({
119
+
120
+ start: new Date(values.start),
121
+ end: values.end ? new Date(values.end) : null,
122
+
123
+ description: values.description,
124
+ onlyLogging: values.onlyLogging,
125
+ goalEnergy: values.goalEnergy,
126
+ goalProtein: values.goalProtein,
127
+ goalCarbohydrates: values.goalCarbohydrates,
128
+ goalFiber: values.goalFiber,
129
+ goalFat: values.goalFat,
130
+ });
131
+
132
+
133
+ if (plan) {
134
+ newPlan.id = plan.id!;
135
+ editPlanQuery.mutate(newPlan);
136
+ } else {
137
+ addPlanQuery.mutate(newPlan);
138
+ }
139
+
140
+ // if closeFn is defined, close the modal (this form does not have to be displayed in one)
141
+ if (closeFn) {
142
+ closeFn();
143
+ }
144
+ }}
145
+ >
146
+ {formik => (
147
+ <Form>
148
+ <Stack spacing={2}>
149
+ <TextField
150
+ fullWidth
151
+ id="description"
152
+ label={t('description')}
153
+ error={formik.touched.description && Boolean(formik.errors.description)}
154
+ // @ts-ignore - the description might come from t(), which might be undefined
155
+ helperText={formik.touched.description && formik.errors.description}
156
+ {...formik.getFieldProps('description')}
157
+ />
158
+ <Grid container spacing={1}>
159
+ <Grid size={6}>
160
+ <LocalizationProvider dateAdapter={AdapterLuxon} adapterLocale={i18n.language}>
161
+ <DatePicker
162
+ format="yyyy-MM-dd"
163
+ label={t('start')}
164
+ value={startDateValue}
165
+ slotProps={{
166
+ textField: {
167
+ variant: "standard",
168
+ fullWidth: true,
169
+ error: formik.touched.start && Boolean(formik.errors.start),
170
+ helperText: formik.touched.start && formik.errors.start ? String(formik.errors.start) : ''
171
+ }
172
+ }}
173
+ onChange={(newValue) => {
174
+ if (newValue) {
175
+ formik.setFieldValue('start', newValue.toJSDate());
176
+ }
177
+ setStartDateValue(newValue);
178
+ }}
179
+
180
+ />
181
+ </LocalizationProvider>
182
+ </Grid>
183
+
184
+ <Grid size={6}>
185
+ <LocalizationProvider dateAdapter={AdapterLuxon} adapterLocale={i18n.language}>
186
+ <DatePicker
187
+ format="yyyy-MM-dd"
188
+ label={t('end')}
189
+ value={endDateValue}
190
+ slotProps={{
191
+ textField: {
192
+ variant: "standard",
193
+ fullWidth: true,
194
+ error: formik.touched.end && Boolean(formik.errors.end),
195
+ helperText: formik.touched.end && formik.errors.end ? String(formik.errors.end) : ''
196
+ }
197
+ }}
198
+ onChange={(newValue) => {
199
+ if (newValue) {
200
+ formik.setFieldValue('end', newValue.toJSDate());
201
+ }
202
+ setEndDateValue(newValue);
203
+ }}
204
+
205
+ />
206
+ </LocalizationProvider>
207
+ </Grid>
208
+ </Grid>
209
+
210
+ <FormGroup>
211
+ <FormControlLabel
212
+ label={t('nutrition.onlyLoggingHelpText')}
213
+ control={
214
+ <Switch
215
+ id="onlyLogging"
216
+ checked={formik.values.onlyLogging}
217
+ {...formik.getFieldProps('onlyLogging')}
218
+ />}
219
+ />
220
+ </FormGroup>
221
+ {/*TODO: implement the options like in the mobile app */}
222
+ {/*<FormControl fullWidth>*/}
223
+ {/* <InputLabel id="demo-simple-select-label">Goal Setting</InputLabel>*/}
224
+ {/* <Select*/}
225
+ {/* labelId="demo-simple-select-label"*/}
226
+ {/* id="demo-simple-select"*/}
227
+ {/* value={10}*/}
228
+ {/* label="Goal setting"*/}
229
+ {/* onChange={() => {*/}
230
+ {/* }}*/}
231
+ {/* >*/}
232
+ {/* <MenuItem value={10}>Based on my meals</MenuItem>*/}
233
+ {/* <MenuItem value={20}>Set basic macros</MenuItem>*/}
234
+ {/* <MenuItem value={30}>Set advanced macros</MenuItem>*/}
235
+ {/* </Select>*/}
236
+ {/*</FormControl>*/}
237
+ <FormGroup>
238
+ <FormControlLabel
239
+ label={t('nutrition.useGoalsHelpText')}
240
+ control={
241
+ <Switch
242
+ id="goalEnergy"
243
+ checked={useGoals}
244
+ onChange={() => setUseGoals(!useGoals)}
245
+
246
+ />}
247
+ />
248
+ </FormGroup>
249
+ <FormHelperText>{t('nutrition.useGoalsHelpTextLong')}</FormHelperText>
250
+
251
+
252
+ {useGoals && <>
253
+ <TextField
254
+ fullWidth
255
+ id="energy"
256
+ label={t('nutrition.goalEnergy')}
257
+ error={formik.touched.goalEnergy && Boolean(formik.errors.goalEnergy)}
258
+ helperText={formik.touched.goalEnergy && formik.errors.goalEnergy}
259
+ {...formik.getFieldProps('goalEnergy')}
260
+ InputProps={{
261
+ endAdornment: <InputAdornment position="end">{t('nutrition.kcal')}</InputAdornment>
262
+ }}
263
+ />
264
+ <Grid container spacing={1}>
265
+ <Grid size={4}>
266
+ <TextField
267
+ id="protein"
268
+ fullWidth
269
+ label={t('nutrition.goalProtein')}
270
+ error={formik.touched.goalProtein && Boolean(formik.errors.goalProtein)}
271
+ helperText={formik.touched.goalProtein && formik.errors.goalProtein}
272
+ {...formik.getFieldProps('goalProtein')}
273
+ InputProps={{
274
+ startAdornment: <InputAdornment position="start">
275
+ {formik.values.goalProtein !== null && formik.values.goalProtein !== undefined
276
+ ? t('nutrition.valueEnergyKcal', { value: formik.values.goalProtein * ENERGY_FACTOR.protein })
277
+ : ''}
278
+ </InputAdornment>,
279
+ endAdornment: <InputAdornment position="end">
280
+ {t('nutrition.gramShort')}
281
+ </InputAdornment>
282
+ }}
283
+ />
284
+ </Grid>
285
+ <Grid size={4}>
286
+ <TextField
287
+ id="carbohydrates"
288
+ fullWidth
289
+ label={t('nutrition.goalCarbohydrates')}
290
+ error={formik.touched.goalCarbohydrates && Boolean(formik.errors.goalCarbohydrates)}
291
+ helperText={formik.touched.goalCarbohydrates && formik.errors.goalCarbohydrates}
292
+ {...formik.getFieldProps('goalCarbohydrates')}
293
+ InputProps={{
294
+ startAdornment: <InputAdornment position="start">
295
+ {formik.values.goalCarbohydrates !== null && formik.values.goalCarbohydrates !== undefined
296
+ ? t('nutrition.valueEnergyKcal', { value: formik.values.goalCarbohydrates * ENERGY_FACTOR.carbohydrates })
297
+ : ''}
298
+ </InputAdornment>,
299
+ endAdornment:
300
+ <InputAdornment
301
+ position="end">{t('nutrition.gramShort')}</InputAdornment>
302
+ }}
303
+ />
304
+ </Grid>
305
+ <Grid size={4}>
306
+ <TextField
307
+ id="fat"
308
+ fullWidth
309
+ label={t('nutrition.goalFat')}
310
+ error={formik.touched.goalFat && Boolean(formik.errors.goalFat)}
311
+ helperText={formik.touched.goalFat && formik.errors.goalFat}
312
+ {...formik.getFieldProps('goalFat')}
313
+ InputProps={{
314
+ startAdornment: <InputAdornment position="start">
315
+ {formik.values.goalFat !== null && formik.values.goalFat !== undefined
316
+ ? t('nutrition.valueEnergyKcal', { value: formik.values.goalFat * ENERGY_FACTOR.fat })
317
+ : ''}
318
+ </InputAdornment>,
319
+ endAdornment:
320
+ <InputAdornment
321
+ position="end">{t('nutrition.gramShort')}</InputAdornment>
322
+ }}
323
+ />
324
+ </Grid>
325
+ </Grid>
326
+ <Grid container spacing={1}>
327
+ <Grid size={4}>
328
+ <TextField
329
+ id="fiber"
330
+ fullWidth
331
+ label={t('nutrition.goalFiber')}
332
+ error={formik.touched.goalFiber && Boolean(formik.errors.goalFiber)}
333
+ helperText={formik.touched.goalFiber && formik.errors.goalFiber}
334
+ {...formik.getFieldProps('goalFiber')}
335
+ InputProps={{
336
+ startAdornment: <InputAdornment position="start">
337
+ {t('nutrition.valueEnergyKcal', { value: 0 })}
338
+ </InputAdornment>,
339
+ endAdornment: <InputAdornment position="end">
340
+ {t('nutrition.gramShort')}
341
+ </InputAdornment>
342
+ }}
343
+ />
344
+ </Grid>
345
+ </Grid>
346
+ </>}
347
+
348
+ <Stack direction="row" justifyContent="end" sx={{ mt: 2 }}>
349
+ <Button color="primary"
350
+ variant="contained"
351
+ type="submit"
352
+ sx={{ mt: 2 }}>
353
+ {t('submit')}
354
+ </Button>
355
+ </Stack>
356
+ </Stack>
357
+ </Form>
358
+ )}
359
+ </Formik>)
360
+ );
361
+ };