@openedx/frontend-app-authn 1.0.0-alpha.6 → 1.0.0-alpha.8

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 (259) hide show
  1. package/dist/Main.js +1 -3
  2. package/dist/Main.js.map +1 -1
  3. package/dist/app.js +0 -2
  4. package/dist/app.js.map +1 -1
  5. package/dist/common-components/EmbeddedRegistrationRoute.js +2 -2
  6. package/dist/common-components/EmbeddedRegistrationRoute.js.map +1 -1
  7. package/dist/common-components/EnterpriseSSO.js +6 -3
  8. package/dist/common-components/EnterpriseSSO.js.map +1 -1
  9. package/dist/common-components/PasswordField.d.ts +17 -9
  10. package/dist/common-components/PasswordField.js +10 -6
  11. package/dist/common-components/PasswordField.js.map +1 -1
  12. package/dist/common-components/RedirectLogistration.js +7 -3
  13. package/dist/common-components/RedirectLogistration.js.map +1 -1
  14. package/dist/common-components/SocialAuthProviders.d.ts +2 -2
  15. package/dist/common-components/SocialAuthProviders.js +5 -4
  16. package/dist/common-components/SocialAuthProviders.js.map +1 -1
  17. package/dist/common-components/ThirdPartyAuth.js +3 -2
  18. package/dist/common-components/ThirdPartyAuth.js.map +1 -1
  19. package/dist/common-components/ThirdPartyAuthAlert.d.ts +2 -2
  20. package/dist/common-components/ThirdPartyAuthAlert.js +4 -4
  21. package/dist/common-components/ThirdPartyAuthAlert.js.map +1 -1
  22. package/dist/common-components/UnAuthOnlyRoute.js +5 -4
  23. package/dist/common-components/UnAuthOnlyRoute.js.map +1 -1
  24. package/dist/common-components/components/ThirdPartyAuthContext.d.ts +31 -0
  25. package/dist/common-components/components/ThirdPartyAuthContext.js +84 -0
  26. package/dist/common-components/components/ThirdPartyAuthContext.js.map +1 -0
  27. package/dist/common-components/data/api.d.ts +6 -0
  28. package/dist/common-components/data/api.js +26 -0
  29. package/dist/common-components/data/api.js.map +1 -0
  30. package/dist/common-components/data/apiHook.d.ts +9 -0
  31. package/dist/common-components/data/apiHook.js +14 -0
  32. package/dist/common-components/data/apiHook.js.map +1 -0
  33. package/dist/common-components/data/queryKeys.d.ts +4 -0
  34. package/dist/common-components/data/queryKeys.js +6 -0
  35. package/dist/common-components/data/queryKeys.js.map +1 -0
  36. package/dist/common-components/index.d.ts +0 -3
  37. package/dist/common-components/index.js +0 -3
  38. package/dist/common-components/index.js.map +1 -1
  39. package/dist/constants.d.ts +13 -0
  40. package/dist/constants.js +15 -0
  41. package/dist/constants.js.map +1 -1
  42. package/dist/data/constants.d.ts +0 -8
  43. package/dist/data/constants.js +0 -9
  44. package/dist/data/constants.js.map +1 -1
  45. package/dist/data/utils/dataUtils.d.ts +1 -0
  46. package/dist/data/utils/dataUtils.js +14 -0
  47. package/dist/data/utils/dataUtils.js.map +1 -1
  48. package/dist/data/utils/index.d.ts +1 -2
  49. package/dist/data/utils/index.js +1 -2
  50. package/dist/data/utils/index.js.map +1 -1
  51. package/dist/forgot-password/ForgotPasswordPage.d.ts +2 -36
  52. package/dist/forgot-password/ForgotPasswordPage.js +45 -44
  53. package/dist/forgot-password/ForgotPasswordPage.js.map +1 -1
  54. package/dist/forgot-password/data/api.d.ts +2 -0
  55. package/dist/forgot-password/data/{service.js → api.js} +13 -14
  56. package/dist/forgot-password/data/api.js.map +1 -0
  57. package/dist/forgot-password/data/apiHook.d.ts +16 -0
  58. package/dist/forgot-password/data/apiHook.js +26 -0
  59. package/dist/forgot-password/data/apiHook.js.map +1 -0
  60. package/dist/forgot-password/index.d.ts +0 -4
  61. package/dist/forgot-password/index.js +0 -4
  62. package/dist/forgot-password/index.js.map +1 -1
  63. package/dist/forgot-password/messages.js +1 -1
  64. package/dist/forgot-password/messages.js.map +1 -1
  65. package/dist/i18n/index.d.ts +1 -25
  66. package/dist/i18n/index.js +1 -25
  67. package/dist/i18n/index.js.map +1 -1
  68. package/dist/login/ChangePasswordPrompt.js +11 -5
  69. package/dist/login/ChangePasswordPrompt.js.map +1 -1
  70. package/dist/login/LoginPage.d.ts +12 -10
  71. package/dist/login/LoginPage.js +85 -127
  72. package/dist/login/LoginPage.js.map +1 -1
  73. package/dist/login/components/LoginContext.d.ts +21 -0
  74. package/dist/login/components/LoginContext.js +28 -0
  75. package/dist/login/components/LoginContext.js.map +1 -0
  76. package/dist/login/data/api.d.ts +2 -0
  77. package/dist/login/data/api.js +27 -0
  78. package/dist/login/data/api.js.map +1 -0
  79. package/dist/login/data/apiHook.d.ts +13 -0
  80. package/dist/login/data/apiHook.js +57 -0
  81. package/dist/login/data/apiHook.js.map +1 -0
  82. package/dist/login/index.d.ts +0 -3
  83. package/dist/login/index.js +0 -3
  84. package/dist/login/index.js.map +1 -1
  85. package/dist/logistration/Logistration.d.ts +5 -32
  86. package/dist/logistration/Logistration.js +28 -54
  87. package/dist/logistration/Logistration.js.map +1 -1
  88. package/dist/progressive-profiling/ProgressiveProfiling.d.ts +2 -46
  89. package/dist/progressive-profiling/ProgressiveProfiling.js +47 -71
  90. package/dist/progressive-profiling/ProgressiveProfiling.js.map +1 -1
  91. package/dist/progressive-profiling/ProgressiveProfilingPageModal.js +8 -1
  92. package/dist/progressive-profiling/ProgressiveProfilingPageModal.js.map +1 -1
  93. package/dist/progressive-profiling/components/ProgressiveProfilingContext.d.ts +18 -0
  94. package/dist/progressive-profiling/components/ProgressiveProfilingContext.js +52 -0
  95. package/dist/progressive-profiling/components/ProgressiveProfilingContext.js.map +1 -0
  96. package/dist/progressive-profiling/data/api.d.ts +2 -0
  97. package/dist/progressive-profiling/data/{service.js → api.js} +11 -12
  98. package/dist/progressive-profiling/data/api.js.map +1 -0
  99. package/dist/progressive-profiling/data/apiHook.d.ts +10 -0
  100. package/dist/progressive-profiling/data/apiHook.js +36 -0
  101. package/dist/progressive-profiling/data/apiHook.js.map +1 -0
  102. package/dist/progressive-profiling/index.d.ts +0 -2
  103. package/dist/progressive-profiling/index.js +0 -2
  104. package/dist/progressive-profiling/index.js.map +1 -1
  105. package/dist/register/RegistrationFields/CountryField/CountryField.d.ts +1 -1
  106. package/dist/register/RegistrationFields/CountryField/CountryField.js +5 -7
  107. package/dist/register/RegistrationFields/CountryField/CountryField.js.map +1 -1
  108. package/dist/register/RegistrationFields/EmailField/EmailField.js +17 -9
  109. package/dist/register/RegistrationFields/EmailField/EmailField.js.map +1 -1
  110. package/dist/register/RegistrationFields/NameField/NameField.js +14 -7
  111. package/dist/register/RegistrationFields/NameField/NameField.js.map +1 -1
  112. package/dist/register/RegistrationFields/NameField/validator.d.ts +1 -0
  113. package/dist/register/RegistrationFields/NameField/validator.js +4 -0
  114. package/dist/register/RegistrationFields/NameField/validator.js.map +1 -1
  115. package/dist/register/RegistrationFields/UsernameField/UsernameField.js +20 -14
  116. package/dist/register/RegistrationFields/UsernameField/UsernameField.js.map +1 -1
  117. package/dist/register/RegistrationPage.d.ts +1 -1
  118. package/dist/register/RegistrationPage.js +102 -59
  119. package/dist/register/RegistrationPage.js.map +1 -1
  120. package/dist/register/components/RegisterContext.d.ts +8 -0
  121. package/dist/register/components/RegisterContext.js +167 -0
  122. package/dist/register/components/RegisterContext.js.map +1 -0
  123. package/dist/register/components/RegistrationFailure.js +4 -1
  124. package/dist/register/components/RegistrationFailure.js.map +1 -1
  125. package/dist/register/data/api.d.ts +9 -0
  126. package/dist/register/data/api.js +45 -0
  127. package/dist/register/data/api.js.map +1 -0
  128. package/dist/register/data/apiHook.d.ts +33 -0
  129. package/dist/register/data/apiHook.js +66 -0
  130. package/dist/register/data/apiHook.js.map +1 -0
  131. package/dist/register/data/constants.d.ts +1 -0
  132. package/dist/register/data/constants.js +1 -0
  133. package/dist/register/data/constants.js.map +1 -1
  134. package/dist/register/index.d.ts +0 -2
  135. package/dist/register/index.js +0 -3
  136. package/dist/register/index.js.map +1 -1
  137. package/dist/register/messages.d.ts +10 -0
  138. package/dist/register/messages.js +10 -0
  139. package/dist/register/messages.js.map +1 -1
  140. package/dist/register/types.d.ts +74 -0
  141. package/dist/register/types.js +2 -0
  142. package/dist/register/types.js.map +1 -0
  143. package/dist/reset-password/ResetPasswordPage.d.ts +2 -32
  144. package/dist/reset-password/ResetPasswordPage.js +90 -58
  145. package/dist/reset-password/ResetPasswordPage.js.map +1 -1
  146. package/dist/reset-password/data/api.d.ts +4 -0
  147. package/dist/reset-password/data/api.js +57 -0
  148. package/dist/reset-password/data/api.js.map +1 -0
  149. package/dist/reset-password/data/apiHook.d.ts +31 -0
  150. package/dist/reset-password/data/apiHook.js +74 -0
  151. package/dist/reset-password/data/apiHook.js.map +1 -0
  152. package/dist/reset-password/index.d.ts +0 -4
  153. package/dist/reset-password/index.js +0 -4
  154. package/dist/reset-password/index.js.map +1 -1
  155. package/dist/routes.d.ts +1 -0
  156. package/dist/routes.js +15 -14
  157. package/dist/routes.js.map +1 -1
  158. package/dist/sass/_registration.scss +8 -10
  159. package/dist/slots/LoginComponentSlot/index.d.ts +12 -0
  160. package/dist/slots/LoginComponentSlot/index.js +11 -0
  161. package/dist/slots/LoginComponentSlot/index.js.map +1 -0
  162. package/package.json +25 -14
  163. package/dist/common-components/data/actions.d.ts +0 -26
  164. package/dist/common-components/data/actions.js +0 -22
  165. package/dist/common-components/data/actions.js.map +0 -1
  166. package/dist/common-components/data/reducers.d.ts +0 -62
  167. package/dist/common-components/data/reducers.js +0 -39
  168. package/dist/common-components/data/reducers.js.map +0 -1
  169. package/dist/common-components/data/sagas.d.ts +0 -12
  170. package/dist/common-components/data/sagas.js +0 -21
  171. package/dist/common-components/data/sagas.js.map +0 -1
  172. package/dist/common-components/data/selectors.d.ts +0 -98
  173. package/dist/common-components/data/selectors.js +0 -11
  174. package/dist/common-components/data/selectors.js.map +0 -1
  175. package/dist/common-components/data/service.d.ts +0 -5
  176. package/dist/common-components/data/service.js +0 -31
  177. package/dist/common-components/data/service.js.map +0 -1
  178. package/dist/data/configureStore.d.ts +0 -3
  179. package/dist/data/configureStore.js +0 -24
  180. package/dist/data/configureStore.js.map +0 -1
  181. package/dist/data/reducers.d.ts +0 -254
  182. package/dist/data/reducers.js +0 -17
  183. package/dist/data/reducers.js.map +0 -1
  184. package/dist/data/sagas.d.ts +0 -1
  185. package/dist/data/sagas.js +0 -18
  186. package/dist/data/sagas.js.map +0 -1
  187. package/dist/data/utils/reduxUtils.d.ts +0 -15
  188. package/dist/data/utils/reduxUtils.js +0 -29
  189. package/dist/data/utils/reduxUtils.js.map +0 -1
  190. package/dist/forgot-password/data/actions.d.ts +0 -30
  191. package/dist/forgot-password/data/actions.js +0 -26
  192. package/dist/forgot-password/data/actions.js.map +0 -1
  193. package/dist/forgot-password/data/reducers.d.ts +0 -13
  194. package/dist/forgot-password/data/reducers.js +0 -46
  195. package/dist/forgot-password/data/reducers.js.map +0 -1
  196. package/dist/forgot-password/data/sagas.d.ts +0 -4
  197. package/dist/forgot-password/data/sagas.js +0 -28
  198. package/dist/forgot-password/data/sagas.js.map +0 -1
  199. package/dist/forgot-password/data/selectors.d.ts +0 -23
  200. package/dist/forgot-password/data/selectors.js +0 -5
  201. package/dist/forgot-password/data/selectors.js.map +0 -1
  202. package/dist/forgot-password/data/service.d.ts +0 -1
  203. package/dist/forgot-password/data/service.js.map +0 -1
  204. package/dist/login/data/actions.d.ts +0 -36
  205. package/dist/login/data/actions.js +0 -32
  206. package/dist/login/data/actions.js.map +0 -1
  207. package/dist/login/data/reducers.d.ts +0 -82
  208. package/dist/login/data/reducers.js +0 -44
  209. package/dist/login/data/reducers.js.map +0 -1
  210. package/dist/login/data/sagas.d.ts +0 -10
  211. package/dist/login/data/sagas.js +0 -34
  212. package/dist/login/data/sagas.js.map +0 -1
  213. package/dist/login/data/service.d.ts +0 -4
  214. package/dist/login/data/service.js +0 -32
  215. package/dist/login/data/service.js.map +0 -1
  216. package/dist/progressive-profiling/data/actions.d.ts +0 -19
  217. package/dist/progressive-profiling/data/actions.js +0 -18
  218. package/dist/progressive-profiling/data/actions.js.map +0 -1
  219. package/dist/progressive-profiling/data/reducers.d.ts +0 -22
  220. package/dist/progressive-profiling/data/reducers.js +0 -23
  221. package/dist/progressive-profiling/data/reducers.js.map +0 -1
  222. package/dist/progressive-profiling/data/sagas.d.ts +0 -4
  223. package/dist/progressive-profiling/data/sagas.js +0 -17
  224. package/dist/progressive-profiling/data/sagas.js.map +0 -1
  225. package/dist/progressive-profiling/data/selectors.d.ts +0 -39
  226. package/dist/progressive-profiling/data/selectors.js +0 -9
  227. package/dist/progressive-profiling/data/selectors.js.map +0 -1
  228. package/dist/progressive-profiling/data/service.d.ts +0 -1
  229. package/dist/progressive-profiling/data/service.js.map +0 -1
  230. package/dist/register/data/actions.d.ts +0 -80
  231. package/dist/register/data/actions.js +0 -69
  232. package/dist/register/data/actions.js.map +0 -1
  233. package/dist/register/data/reducers.d.ts +0 -237
  234. package/dist/register/data/reducers.js +0 -86
  235. package/dist/register/data/reducers.js.map +0 -1
  236. package/dist/register/data/sagas.d.ts +0 -19
  237. package/dist/register/data/sagas.js +0 -45
  238. package/dist/register/data/sagas.js.map +0 -1
  239. package/dist/register/data/selectors.d.ts +0 -26
  240. package/dist/register/data/selectors.js +0 -25
  241. package/dist/register/data/selectors.js.map +0 -1
  242. package/dist/register/data/service.d.ts +0 -8
  243. package/dist/register/data/service.js +0 -46
  244. package/dist/register/data/service.js.map +0 -1
  245. package/dist/reset-password/data/actions.d.ts +0 -56
  246. package/dist/reset-password/data/actions.js +0 -41
  247. package/dist/reset-password/data/actions.js.map +0 -1
  248. package/dist/reset-password/data/reducers.d.ts +0 -19
  249. package/dist/reset-password/data/reducers.js +0 -25
  250. package/dist/reset-password/data/reducers.js.map +0 -1
  251. package/dist/reset-password/data/sagas.d.ts +0 -7
  252. package/dist/reset-password/data/sagas.js +0 -63
  253. package/dist/reset-password/data/sagas.js.map +0 -1
  254. package/dist/reset-password/data/selectors.d.ts +0 -23
  255. package/dist/reset-password/data/selectors.js +0 -5
  256. package/dist/reset-password/data/selectors.js.map +0 -1
  257. package/dist/reset-password/data/service.d.ts +0 -3
  258. package/dist/reset-password/data/service.js +0 -62
  259. package/dist/reset-password/data/service.js.map +0 -1
@@ -0,0 +1,52 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo, useState, useCallback } from 'react';
3
+ import { DEFAULT_STATE, } from '../../data/constants';
4
+ const ProgressiveProfilingContext = createContext(undefined);
5
+ export const ProgressiveProfilingProvider = ({ children }) => {
6
+ const [isLoading, setIsLoading] = useState(false);
7
+ const [showError, setShowError] = useState(false);
8
+ const [success, setSuccess] = useState(false);
9
+ const [submitState, setSubmitState] = useState(DEFAULT_STATE);
10
+ const setLoading = useCallback((loading) => {
11
+ setIsLoading(loading);
12
+ if (loading) {
13
+ setShowError(false);
14
+ setSuccess(false);
15
+ }
16
+ }, []);
17
+ const clearState = useCallback(() => {
18
+ setIsLoading(false);
19
+ setShowError(false);
20
+ setSuccess(false);
21
+ }, []);
22
+ const value = useMemo(() => ({
23
+ isLoading,
24
+ showError,
25
+ success,
26
+ setLoading,
27
+ setShowError,
28
+ setSuccess,
29
+ clearState,
30
+ submitState,
31
+ setSubmitState,
32
+ }), [
33
+ isLoading,
34
+ showError,
35
+ success,
36
+ setLoading,
37
+ setShowError,
38
+ setSuccess,
39
+ clearState,
40
+ submitState,
41
+ setSubmitState,
42
+ ]);
43
+ return (_jsx(ProgressiveProfilingContext.Provider, { value: value, children: children }));
44
+ };
45
+ export const useProgressiveProfilingContext = () => {
46
+ const context = useContext(ProgressiveProfilingContext);
47
+ if (context === undefined) {
48
+ throw new Error('useProgressiveProfilingContext must be used within a ProgressiveProfilingProvider');
49
+ }
50
+ return context;
51
+ };
52
+ //# sourceMappingURL=ProgressiveProfilingContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProgressiveProfilingContext.js","sourceRoot":"","sources":["../../../src/progressive-profiling/components/ProgressiveProfilingContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAiB,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEjG,OAAO,EACL,aAAa,GACd,MAAM,sBAAsB,CAAC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Q,IAAC,KAAK,EAAE,KAAK,YAC/C,QAAQ,GAC4B,CACxC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAoC,EAAE;IAClF,MAAM,OAAO,GAAG,UAAU,CAAC,2BAA2B,CAAC,CAAC;IACxD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAC;IACvG,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import { createContext, FC, ReactNode, useContext, useMemo, useState, useCallback } from 'react';\n\nimport {\n DEFAULT_STATE,\n} from '../../data/constants';\n\ninterface ProgressiveProfilingContextType {\n isLoading: boolean,\n showError: boolean,\n success: boolean,\n submitState?: string,\n setLoading: (loading: boolean) => void,\n setShowError: (showError: boolean) => void,\n setSuccess: (success: boolean) => void,\n setSubmitState: (state: string) => void,\n clearState: () => void,\n}\n\nconst ProgressiveProfilingContext = createContext<ProgressiveProfilingContextType | undefined>(undefined);\n\ninterface ProgressiveProfilingProviderProps {\n children: ReactNode,\n}\n\nexport const ProgressiveProfilingProvider: FC<ProgressiveProfilingProviderProps> = ({ children }) => {\n const [isLoading, setIsLoading] = useState(false);\n const [showError, setShowError] = useState(false);\n const [success, setSuccess] = useState(false);\n const [submitState, setSubmitState] = useState<string>(DEFAULT_STATE);\n\n const setLoading = useCallback((loading: boolean) => {\n setIsLoading(loading);\n if (loading) {\n setShowError(false);\n setSuccess(false);\n }\n }, []);\n\n const clearState = useCallback(() => {\n setIsLoading(false);\n setShowError(false);\n setSuccess(false);\n }, []);\n\n const value = useMemo(() => ({\n isLoading,\n showError,\n success,\n setLoading,\n setShowError,\n setSuccess,\n clearState,\n submitState,\n setSubmitState,\n }), [\n isLoading,\n showError,\n success,\n setLoading,\n setShowError,\n setSuccess,\n clearState,\n submitState,\n setSubmitState,\n ]);\n\n return (\n <ProgressiveProfilingContext.Provider value={value}>\n {children}\n </ProgressiveProfilingContext.Provider>\n );\n};\n\nexport const useProgressiveProfilingContext = (): ProgressiveProfilingContextType => {\n const context = useContext(ProgressiveProfilingContext);\n if (context === undefined) {\n throw new Error('useProgressiveProfilingContext must be used within a ProgressiveProfilingProvider');\n }\n return context;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ declare const patchAccount: (username: any, commitValues: any) => Promise<void>;
2
+ export { patchAccount, };
@@ -8,16 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { getAuthenticatedHttpClient, getSiteConfig } from '@openedx/frontend-base';
11
- export function patchAccount(username, commitValues) {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- const requestConfig = {
14
- headers: { 'Content-Type': 'application/merge-patch+json' },
15
- };
16
- yield getAuthenticatedHttpClient()
17
- .patch(`${getSiteConfig().lmsBaseUrl}/api/user/v1/accounts/${username}`, commitValues, requestConfig)
18
- .catch((error) => {
19
- throw (error);
20
- });
11
+ const patchAccount = (username, commitValues) => __awaiter(void 0, void 0, void 0, function* () {
12
+ const requestConfig = {
13
+ headers: { 'Content-Type': 'application/merge-patch+json' },
14
+ };
15
+ yield getAuthenticatedHttpClient()
16
+ .patch(`${getSiteConfig().lmsBaseUrl}/api/user/v1/accounts/${username}`, commitValues, requestConfig)
17
+ .catch((error) => {
18
+ throw (error);
21
19
  });
22
- }
23
- //# sourceMappingURL=service.js.map
20
+ });
21
+ export { patchAccount, };
22
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/progressive-profiling/data/api.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEnF,MAAM,YAAY,GAAG,CAAO,QAAQ,EAAE,YAAY,EAAE,EAAE;IACpD,MAAM,aAAa,GAAG;QACpB,OAAO,EAAE,EAAE,cAAc,EAAE,8BAA8B,EAAE;KAC5D,CAAC;IAEF,MAAM,0BAA0B,EAAE;SAC/B,KAAK,CACJ,GAAG,aAAa,EAAE,CAAC,UAAU,yBAAyB,QAAQ,EAAE,EAChE,YAAY,EACZ,aAAa,CACd;SACA,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,CAAC,KAAK,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;AACP,CAAC,CAAA,CAAC;AAEF,OAAO,EACL,YAAY,GACb,CAAC","sourcesContent":["import { getAuthenticatedHttpClient, getSiteConfig } from '@openedx/frontend-base';\n\nconst patchAccount = async (username, commitValues) => {\n const requestConfig = {\n headers: { 'Content-Type': 'application/merge-patch+json' },\n };\n\n await getAuthenticatedHttpClient()\n .patch(\n `${getSiteConfig().lmsBaseUrl}/api/user/v1/accounts/${username}`,\n commitValues,\n requestConfig,\n )\n .catch((error) => {\n throw (error);\n });\n};\n\nexport {\n patchAccount,\n};\n"]}
@@ -0,0 +1,10 @@
1
+ interface SaveUserProfilePayload {
2
+ username: string;
3
+ data: Record<string, any>;
4
+ }
5
+ interface UseSaveUserProfileOptions {
6
+ onSuccess?: () => void;
7
+ onError?: (error: unknown) => void;
8
+ }
9
+ declare const useSaveUserProfile: (options?: UseSaveUserProfileOptions) => import("@tanstack/react-query").UseMutationResult<void, unknown, SaveUserProfilePayload, unknown>;
10
+ export { useSaveUserProfile, };
@@ -0,0 +1,36 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { useMutation } from '@tanstack/react-query';
11
+ import { patchAccount } from './api';
12
+ import { COMPLETE_STATE, DEFAULT_STATE, } from '../../data/constants';
13
+ import { useProgressiveProfilingContext } from '../components/ProgressiveProfilingContext';
14
+ const useSaveUserProfile = (options = {}) => {
15
+ const { setSuccess, setSubmitState } = useProgressiveProfilingContext();
16
+ return useMutation({
17
+ mutationFn: (_a) => __awaiter(void 0, [_a], void 0, function* ({ username, data }) {
18
+ return (patchAccount(username, data));
19
+ }),
20
+ onSuccess: () => {
21
+ setSuccess(true);
22
+ setSubmitState(COMPLETE_STATE);
23
+ if (options.onSuccess) {
24
+ options.onSuccess();
25
+ }
26
+ },
27
+ onError: (error) => {
28
+ setSubmitState(DEFAULT_STATE);
29
+ if (options.onError) {
30
+ options.onError(error);
31
+ }
32
+ },
33
+ });
34
+ };
35
+ export { useSaveUserProfile, };
36
+ //# sourceMappingURL=apiHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiHook.js","sourceRoot":"","sources":["../../../src/progressive-profiling/data/apiHook.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EACL,cAAc,EAAE,aAAa,GAC9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,8BAA8B,EAAE,MAAM,2CAA2C,CAAC;AAY3F,MAAM,kBAAkB,GAAG,CAAC,UAAqC,EAAE,EAAE,EAAE;IACrE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,8BAA8B,EAAE,CAAC;IACxE,OAAO,WAAW,CAAC;QACjB,UAAU,EAAE,KAAmD,EAAE,4CAA9C,EAAE,QAAQ,EAAE,IAAI,EAA0B;YAAK,OAAA,CAChE,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,CAC7B,CAAA;UAAA;QACD,SAAS,EAAE,GAAG,EAAE;YACd,UAAU,CAAC,IAAI,CAAC,CAAC;YACjB,cAAc,CAAC,cAAc,CAAC,CAAC;YAC/B,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;gBACtB,OAAO,CAAC,SAAS,EAAE,CAAC;YACtB,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC,KAAc,EAAE,EAAE;YAC1B,cAAc,CAAC,aAAa,CAAC,CAAC;YAC9B,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,OAAO,EACL,kBAAkB,GACnB,CAAC","sourcesContent":["import { useMutation } from '@tanstack/react-query';\n\nimport { patchAccount } from './api';\nimport {\n COMPLETE_STATE, DEFAULT_STATE,\n} from '../../data/constants';\nimport { useProgressiveProfilingContext } from '../components/ProgressiveProfilingContext';\n\ninterface SaveUserProfilePayload {\n username: string,\n data: Record<string, any>,\n}\n\ninterface UseSaveUserProfileOptions {\n onSuccess?: () => void,\n onError?: (error: unknown) => void,\n}\n\nconst useSaveUserProfile = (options: UseSaveUserProfileOptions = {}) => {\n const { setSuccess, setSubmitState } = useProgressiveProfilingContext();\n return useMutation({\n mutationFn: async ({ username, data }: SaveUserProfilePayload) => (\n patchAccount(username, data)\n ),\n onSuccess: () => {\n setSuccess(true);\n setSubmitState(COMPLETE_STATE);\n if (options.onSuccess) {\n options.onSuccess();\n }\n },\n onError: (error: unknown) => {\n setSubmitState(DEFAULT_STATE);\n if (options.onError) {\n options.onError(error);\n }\n },\n });\n};\n\nexport {\n useSaveUserProfile,\n};\n"]}
@@ -1,4 +1,2 @@
1
1
  export const storeName: "welcomePage";
2
2
  export { default as ProgressiveProfiling } from "./ProgressiveProfiling";
3
- export { default as reducer } from "./data/reducers";
4
- export { default as saga } from "./data/sagas";
@@ -1,5 +1,3 @@
1
1
  export const storeName = 'welcomePage';
2
2
  export { default as ProgressiveProfiling } from './ProgressiveProfiling';
3
- export { default as reducer } from './data/reducers';
4
- export { default as saga } from './data/sagas';
5
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/progressive-profiling/index.js"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,aAAa,CAAC;AAEvC,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export const storeName = 'welcomePage';\n\nexport { default as ProgressiveProfiling } from './ProgressiveProfiling';\nexport { default as reducer } from './data/reducers';\nexport { default as saga } from './data/sagas';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/progressive-profiling/index.js"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export const storeName = 'welcomePage';\nexport { default as ProgressiveProfiling } from './ProgressiveProfiling';\n"]}
@@ -5,7 +5,7 @@ export default CountryField;
5
5
  * - handleErrorChange for setting error
6
6
  *
7
7
  * It is responsible for
8
- * - Auto populating country field if backendCountryCode is available in redux
8
+ * - Auto populating country field if backendCountryCode is available in context
9
9
  * - Performing country field validations
10
10
  * - clearing error on focus
11
11
  * - setting value on change and selection
@@ -1,20 +1,19 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect } from 'react';
3
- import { useDispatch, useSelector } from 'react-redux';
4
3
  import { useIntl } from '@openedx/frontend-base';
5
4
  import { FormAutosuggest, FormAutosuggestOption, FormControlFeedback } from '@openedx/paragon';
6
5
  import classNames from 'classnames';
7
6
  import PropTypes from 'prop-types';
8
- import { clearRegistrationBackendError } from '../../data/actions';
9
- import messages from '../../messages';
10
7
  import validateCountryField, { COUNTRY_CODE_KEY, COUNTRY_DISPLAY_KEY } from './validator';
8
+ import { useRegisterContext } from '../../components/RegisterContext';
9
+ import messages from '../../messages';
11
10
  /**
12
11
  * Country field wrapper. It accepts following handlers
13
12
  * - handleChange for setting value change and
14
13
  * - handleErrorChange for setting error
15
14
  *
16
15
  * It is responsible for
17
- * - Auto populating country field if backendCountryCode is available in redux
16
+ * - Auto populating country field if backendCountryCode is available in context
18
17
  * - Performing country field validations
19
18
  * - clearing error on focus
20
19
  * - setting value on change and selection
@@ -22,13 +21,12 @@ import validateCountryField, { COUNTRY_CODE_KEY, COUNTRY_DISPLAY_KEY } from './v
22
21
  const CountryField = (props) => {
23
22
  const { countryList, selectedCountry, onChangeHandler, handleErrorChange, onFocusHandler, } = props;
24
23
  const { formatMessage } = useIntl();
25
- const dispatch = useDispatch();
24
+ const { clearRegistrationBackendError, backendCountryCode, } = useRegisterContext();
26
25
  const countryFieldValue = {
27
26
  userProvidedText: selectedCountry.displayValue,
28
27
  selectionValue: selectedCountry.displayValue,
29
28
  selectionId: selectedCountry.countryCode,
30
29
  };
31
- const backendCountryCode = useSelector(state => state.register.backendCountryCode);
32
30
  useEffect(() => {
33
31
  if (backendCountryCode && backendCountryCode !== (selectedCountry === null || selectedCountry === void 0 ? void 0 : selectedCountry.countryCode)) {
34
32
  let countryCode = '';
@@ -55,7 +53,7 @@ const CountryField = (props) => {
55
53
  };
56
54
  const handleOnFocus = (event) => {
57
55
  handleErrorChange('country', '');
58
- dispatch(clearRegistrationBackendError('country'));
56
+ clearRegistrationBackendError('country');
59
57
  onFocusHandler(event);
60
58
  };
61
59
  const handleOnChange = (value) => {
@@ -1 +1 @@
1
- {"version":3,"file":"CountryField.js","sourceRoot":"","sources":["../../../../src/register/RegistrationFields/CountryField/CountryField.jsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAA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O,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAChC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,EAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,YAEzC,cAAc,EAAE,GACD,EACjB,KAAK,CAAC,YAAY,KAAK,EAAE,IAAI,CAC5B,KAAC,mBAAmB,IAElB,SAAS,EAAC,gBAAgB,EAC1B,OAAO,EAAE,KAAK,kBACD,SAAS,EACtB,IAAI,EAAC,SAAS,YAEb,KAAK,CAAC,YAAY,IANf,OAAO,CAOS,CACvB,IACG,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,GAAG;IACvB,WAAW,EAAE,SAAS,CAAC,OAAO,CAC5B,SAAS,CAAC,KAAK,CAAC;QACd,IAAI,EAAE,SAAS,CAAC,MAAM;QACtB,IAAI,EAAE,SAAS,CAAC,MAAM;KACvB,CAAC,CACH,CAAC,UAAU;IACZ,YAAY,EAAE,SAAS,CAAC,MAAM;IAC9B,eAAe,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IAC1C,iBAAiB,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IAC5C,cAAc,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IACzC,eAAe,EAAE,SAAS,CAAC,KAAK,CAAC;QAC/B,YAAY,EAAE,SAAS,CAAC,MAAM;QAC9B,WAAW,EAAE,SAAS,CAAC,MAAM;KAC9B,CAAC;CACH,CAAC;AAEF,YAAY,CAAC,YAAY,GAAG;IAC1B,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE;QACf,KAAK,EAAE,EAAE;KACV;CACF,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { useEffect } from 'react';\nimport { useDispatch, useSelector } from 'react-redux';\n\nimport { useIntl } from '@openedx/frontend-base';\nimport { FormAutosuggest, FormAutosuggestOption, FormControlFeedback } from '@openedx/paragon';\nimport classNames from 'classnames';\nimport PropTypes from 'prop-types';\n\nimport { clearRegistrationBackendError } from '../../data/actions';\nimport messages from '../../messages';\nimport validateCountryField, { COUNTRY_CODE_KEY, COUNTRY_DISPLAY_KEY } from './validator';\n\n/**\n * Country field wrapper. It accepts following handlers\n * - handleChange for setting value change and\n * - handleErrorChange for setting error\n *\n * It is responsible for\n * - Auto populating country field if backendCountryCode is available in redux\n * - Performing country field validations\n * - clearing error on focus\n * - setting value on change and selection\n */\nconst CountryField = (props) => {\n const {\n countryList,\n selectedCountry,\n onChangeHandler,\n handleErrorChange,\n onFocusHandler,\n } = props;\n const { formatMessage } = useIntl();\n const dispatch = useDispatch();\n\n const countryFieldValue = {\n userProvidedText: selectedCountry.displayValue,\n selectionValue: selectedCountry.displayValue,\n selectionId: selectedCountry.countryCode,\n };\n\n const backendCountryCode = useSelector(state => state.register.backendCountryCode);\n\n useEffect(() => {\n if (backendCountryCode && backendCountryCode !== selectedCountry?.countryCode) {\n let countryCode = '';\n let countryDisplayValue = '';\n\n const countryVal = countryList.find(\n (country) => (country[COUNTRY_CODE_KEY].toLowerCase() === backendCountryCode.toLowerCase()),\n );\n if (countryVal) {\n countryCode = countryVal[COUNTRY_CODE_KEY];\n countryDisplayValue = countryVal[COUNTRY_DISPLAY_KEY];\n }\n onChangeHandler(\n { target: { name: 'country' } },\n { countryCode, displayValue: countryDisplayValue },\n );\n } else if (!selectedCountry.displayValue) {\n onChangeHandler(\n { target: { name: 'country' } },\n { countryCode: '', displayValue: '' },\n );\n }\n }, [backendCountryCode, countryList]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const handleOnBlur = (event) => {\n // Do not run validations when drop-down arrow is clicked\n if (event.relatedTarget && event.relatedTarget.className.includes('pgn__form-autosuggest__icon-button')) {\n return;\n }\n\n const { value } = event.target;\n\n const { error } = validateCountryField(\n value.trim(),\n countryList,\n formatMessage(messages['empty.country.field.error']),\n formatMessage(messages['invalid.country.field.error'])\n );\n handleErrorChange('country', error);\n };\n\n const handleOnFocus = (event) => {\n handleErrorChange('country', '');\n dispatch(clearRegistrationBackendError('country'));\n onFocusHandler(event);\n };\n\n const handleOnChange = (value) => {\n onChangeHandler(\n { target: { name: 'country' } },\n { countryCode: value.selectionId, displayValue: value.userProvidedText }\n );\n\n // We have put this check because proviously we also had onSelected event handler and we call\n // the onBlur on that event handler but now there is no such handler and we only have\n // onChange so we check the is there is proper sectionId which only be\n // proper one when we select it from dropdown's item otherwise its null.\n if (value.selectionId !== '') {\n handleOnBlur({ target: { name: 'country', value: value.userProvidedText } });\n }\n };\n\n const getCountryList = () => countryList.map((country) => (\n <FormAutosuggestOption key={country[COUNTRY_DISPLAY_KEY]} id={country[COUNTRY_CODE_KEY]}>\n {country[COUNTRY_DISPLAY_KEY]}\n </FormAutosuggestOption>\n ));\n\n return (\n <div className=\"mb-4\">\n <FormAutosuggest\n floatingLabel={formatMessage(messages['registration.country.label'])}\n aria-label=\"form autosuggest\"\n name=\"country\"\n value={countryFieldValue || {}}\n className={classNames({ 'form-field-error': props.errorMessage })}\n onFocus={(e) => handleOnFocus(e)}\n onBlur={(e) => handleOnBlur(e)}\n onChange={(value) => handleOnChange(value)}\n >\n {getCountryList()}\n </FormAutosuggest>\n {props.errorMessage !== '' && (\n <FormControlFeedback\n key=\"error\"\n className=\"form-text-size\"\n hasIcon={false}\n feedback-for=\"country\"\n type=\"invalid\"\n >\n {props.errorMessage}\n </FormControlFeedback>\n )}\n </div>\n );\n};\n\nCountryField.propTypes = {\n countryList: PropTypes.arrayOf(\n PropTypes.shape({\n code: PropTypes.string,\n name: PropTypes.string,\n }),\n ).isRequired,\n errorMessage: PropTypes.string,\n onChangeHandler: PropTypes.func.isRequired,\n handleErrorChange: PropTypes.func.isRequired,\n onFocusHandler: PropTypes.func.isRequired,\n selectedCountry: PropTypes.shape({\n displayValue: PropTypes.string,\n countryCode: PropTypes.string,\n }),\n};\n\nCountryField.defaultProps = {\n errorMessage: null,\n selectedCountry: {\n value: '',\n },\n};\n\nexport default CountryField;\n"]}
1
+ {"version":3,"file":"CountryField.js","sourceRoot":"","sources":["../../../../src/register/RegistrationFields/CountryField/CountryField.jsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC/F,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,oBAAoB,EAAE,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC;;;;;;;;;;GAUG;AACH,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,EAAE;IAC7B,MAAM,EACJ,WAAW,EACX,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,cAAc,GACf,GAAG,KAAK,CAAC;IACV,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,EAAE,CAAC;IAEpC,MAAM,EACJ,6BAA6B,EAC7B,kBAAkB,GACnB,GAAG,kBAAkB,EAAE,CAAC;IAEzB,MAAM,iBAAiB,GAAG;QACxB,gBAAgB,EAAE,eAAe,CAAC,YAAY;QAC9C,cAAc,EAAE,eAAe,CAAC,YAAY;QAC5C,WAAW,EAAE,eAAe,CAAC,WAAW;KACzC,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,kBAAkB,IAAI,kBAAkB,MAAK,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,WAAW,CAAA,EAAE,CAAC;YAC9E,IAAI,WAAW,GAAG,EAAE,CAAC;YACrB,IAAI,mBAAmB,GAAG,EAAE,CAAC;YAE7B,M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FormAutosuggestOption, FormControlFeedback } from '@openedx/paragon';\nimport classNames from 'classnames';\nimport PropTypes from 'prop-types';\n\nimport validateCountryField, { COUNTRY_CODE_KEY, COUNTRY_DISPLAY_KEY } from './validator';\nimport { useRegisterContext } from '../../components/RegisterContext';\nimport messages from '../../messages';\n\n/**\n * Country field wrapper. It accepts following handlers\n * - handleChange for setting value change and\n * - handleErrorChange for setting error\n *\n * It is responsible for\n * - Auto populating country field if backendCountryCode is available in context\n * - Performing country field validations\n * - clearing error on focus\n * - setting value on change and selection\n */\nconst CountryField = (props) => {\n const {\n countryList,\n selectedCountry,\n onChangeHandler,\n handleErrorChange,\n onFocusHandler,\n } = props;\n const { formatMessage } = useIntl();\n\n const {\n clearRegistrationBackendError,\n backendCountryCode,\n } = useRegisterContext();\n\n const countryFieldValue = {\n userProvidedText: selectedCountry.displayValue,\n selectionValue: selectedCountry.displayValue,\n selectionId: selectedCountry.countryCode,\n };\n\n useEffect(() => {\n if (backendCountryCode && backendCountryCode !== selectedCountry?.countryCode) {\n let countryCode = '';\n let countryDisplayValue = '';\n\n const countryVal = countryList.find(\n (country) => (country[COUNTRY_CODE_KEY].toLowerCase() === backendCountryCode.toLowerCase()),\n );\n if (countryVal) {\n countryCode = countryVal[COUNTRY_CODE_KEY];\n countryDisplayValue = countryVal[COUNTRY_DISPLAY_KEY];\n }\n onChangeHandler(\n { target: { name: 'country' } },\n { countryCode, displayValue: countryDisplayValue },\n );\n } else if (!selectedCountry.displayValue) {\n onChangeHandler(\n { target: { name: 'country' } },\n { countryCode: '', displayValue: '' },\n );\n }\n }, [backendCountryCode, countryList]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const handleOnBlur = (event) => {\n // Do not run validations when drop-down arrow is clicked\n if (event.relatedTarget && event.relatedTarget.className.includes('pgn__form-autosuggest__icon-button')) {\n return;\n }\n\n const { value } = event.target;\n\n const { error } = validateCountryField(\n value.trim(), countryList, formatMessage(messages['empty.country.field.error']), formatMessage(messages['invalid.country.field.error']),\n );\n handleErrorChange('country', error);\n };\n\n const handleOnFocus = (event) => {\n handleErrorChange('country', '');\n clearRegistrationBackendError('country');\n onFocusHandler(event);\n };\n\n const handleOnChange = (value) => {\n onChangeHandler({ target: { name: 'country' } }, { countryCode: value.selectionId, displayValue: value.userProvidedText });\n\n // We have put this check because proviously we also had onSelected event handler and we call\n // the onBlur on that event handler but now there is no such handler and we only have\n // onChange so we check the is there is proper sectionId which only be\n // proper one when we select it from dropdown's item otherwise its null.\n if (value.selectionId !== '') {\n handleOnBlur({ target: { name: 'country', value: value.userProvidedText } });\n }\n };\n\n const getCountryList = () => countryList.map((country) => (\n <FormAutosuggestOption key={country[COUNTRY_DISPLAY_KEY]} id={country[COUNTRY_CODE_KEY]}>\n {country[COUNTRY_DISPLAY_KEY]}\n </FormAutosuggestOption>\n ));\n\n return (\n <div className=\"mb-4\">\n <FormAutosuggest\n floatingLabel={formatMessage(messages['registration.country.label'])}\n aria-label=\"form autosuggest\"\n name=\"country\"\n value={countryFieldValue || {}}\n className={classNames({ 'form-field-error': props.errorMessage })}\n onFocus={(e) => handleOnFocus(e)}\n onBlur={(e) => handleOnBlur(e)}\n onChange={(value) => handleOnChange(value)}\n >\n {getCountryList()}\n </FormAutosuggest>\n {props.errorMessage !== '' && (\n <FormControlFeedback\n key=\"error\"\n className=\"form-text-size\"\n hasIcon={false}\n feedback-for=\"country\"\n type=\"invalid\"\n >\n {props.errorMessage}\n </FormControlFeedback>\n )}\n </div>\n );\n};\n\nCountryField.propTypes = {\n countryList: PropTypes.arrayOf(\n PropTypes.shape({\n code: PropTypes.string,\n name: PropTypes.string,\n }),\n ).isRequired,\n errorMessage: PropTypes.string,\n onChangeHandler: PropTypes.func.isRequired,\n handleErrorChange: PropTypes.func.isRequired,\n onFocusHandler: PropTypes.func.isRequired,\n selectedCountry: PropTypes.shape({\n displayValue: PropTypes.string,\n countryCode: PropTypes.string,\n }),\n};\n\nCountryField.defaultProps = {\n errorMessage: null,\n selectedCountry: {\n value: '',\n },\n};\n\nexport default CountryField;\n"]}
@@ -1,14 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from 'react';
3
- import { useDispatch, useSelector } from 'react-redux';
4
3
  import { useIntl } from '@openedx/frontend-base';
5
4
  import { Alert, Icon } from '@openedx/paragon';
6
5
  import { Close, Error } from '@openedx/paragon/icons';
7
6
  import PropTypes from 'prop-types';
7
+ import validateEmail from './validator';
8
8
  import { FormGroup } from '../../../common-components';
9
- import { clearRegistrationBackendError, fetchRealtimeValidations, setEmailSuggestionInStore, } from '../../data/actions';
9
+ import { useRegisterContext } from '../../components/RegisterContext';
10
+ import { useFieldValidations } from '../../data/apiHook';
10
11
  import messages from '../../messages';
11
- import validateEmail from './validator';
12
12
  /**
13
13
  * Email field wrapper. It accepts following handlers
14
14
  * - handleChange for setting value change and
@@ -23,10 +23,17 @@ import validateEmail from './validator';
23
23
  */
24
24
  const EmailField = (props) => {
25
25
  const { formatMessage } = useIntl();
26
- const dispatch = useDispatch();
26
+ const { setValidationsSuccess, setValidationsFailure, validationApiRateLimited, clearRegistrationBackendError, registrationFormData, setEmailSuggestionContext, } = useRegisterContext();
27
27
  const { handleChange, handleErrorChange, confirmEmailValue, } = props;
28
- const backedUpFormData = useSelector(state => state.register.registrationFormData);
29
- const validationApiRateLimited = useSelector(state => state.register.validationApiRateLimited);
28
+ const fieldValidationsMutation = useFieldValidations({
29
+ onSuccess: (data) => {
30
+ setValidationsSuccess(data);
31
+ },
32
+ onError: () => {
33
+ setValidationsFailure();
34
+ },
35
+ });
36
+ const backedUpFormData = registrationFormData;
30
37
  const [emailSuggestion, setEmailSuggestion] = useState(Object.assign({}, backedUpFormData === null || backedUpFormData === void 0 ? void 0 : backedUpFormData.emailSuggestion));
31
38
  useEffect(() => {
32
39
  setEmailSuggestion(backedUpFormData.emailSuggestion);
@@ -37,24 +44,25 @@ const EmailField = (props) => {
37
44
  if (confirmEmailError) {
38
45
  handleErrorChange('confirm_email', confirmEmailError);
39
46
  }
40
- dispatch(setEmailSuggestionInStore(suggestion));
47
+ setEmailSuggestionContext(suggestion.suggestion, suggestion.type);
41
48
  setEmailSuggestion(suggestion);
42
49
  if (fieldError) {
43
50
  handleErrorChange('email', fieldError);
44
51
  }
45
52
  else if (!validationApiRateLimited) {
46
- dispatch(fetchRealtimeValidations({ email: value }));
53
+ fieldValidationsMutation.mutate({ email: value });
47
54
  }
48
55
  };
49
56
  const handleOnFocus = () => {
50
57
  handleErrorChange('email', '');
51
- dispatch(clearRegistrationBackendError('email'));
58
+ clearRegistrationBackendError('email');
52
59
  };
53
60
  const handleSuggestionClick = (event) => {
54
61
  event.preventDefault();
55
62
  handleErrorChange('email', '');
56
63
  handleChange({ target: { name: 'email', value: emailSuggestion.suggestion } });
57
64
  setEmailSuggestion({ suggestion: '', type: '' });
65
+ setEmailSuggestionContext('', '');
58
66
  };
59
67
  const handleSuggestionClosed = () => setEmailSuggestion({ suggestion: '', type: '' });
60
68
  const renderEmailFeedback = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"EmailField.js","sourceRoot":"","sources":["../../../../src/register/RegistrationFields/EmailField/EmailField.jsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,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CAAC,MAAM;CACpC,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { useEffect, useState } from 'react';\nimport { useDispatch, useSelector } from 'react-redux';\n\nimport { useIntl } from '@openedx/frontend-base';\nimport { Alert, Icon } from '@openedx/paragon';\nimport { Close, Error } from '@openedx/paragon/icons';\nimport PropTypes from 'prop-types';\n\nimport { FormGroup } from '../../../common-components';\nimport {\n clearRegistrationBackendError,\n fetchRealtimeValidations,\n setEmailSuggestionInStore,\n} from '../../data/actions';\nimport messages from '../../messages';\nimport validateEmail from './validator';\n\n/**\n * Email field wrapper. It accepts following handlers\n * - handleChange for setting value change and\n * - handleErrorChange for setting error\n *\n * It is responsible for\n * - Generating email warning and error suggestions\n * - Setting and clearing email suggestions\n * - Performing email field validations\n * - clearing error on focus\n * - setting value on change\n */\nconst EmailField = (props) => {\n const { formatMessage } = useIntl();\n const dispatch = useDispatch();\n\n const {\n handleChange,\n handleErrorChange,\n confirmEmailValue,\n } = props;\n\n const backedUpFormData = useSelector(state => state.register.registrationFormData);\n const validationApiRateLimited = useSelector(state => state.register.validationApiRateLimited);\n\n const [emailSuggestion, setEmailSuggestion] = useState({ ...backedUpFormData?.emailSuggestion });\n\n useEffect(() => {\n setEmailSuggestion(backedUpFormData.emailSuggestion);\n }, [backedUpFormData.emailSuggestion]);\n\n const handleOnBlur = (e) => {\n const { value } = e.target;\n const { fieldError, confirmEmailError, suggestion } = validateEmail(value, confirmEmailValue, formatMessage);\n\n if (confirmEmailError) {\n handleErrorChange('confirm_email', confirmEmailError);\n }\n\n dispatch(setEmailSuggestionInStore(suggestion));\n setEmailSuggestion(suggestion);\n\n if (fieldError) {\n handleErrorChange('email', fieldError);\n } else if (!validationApiRateLimited) {\n dispatch(fetchRealtimeValidations({ email: value }));\n }\n };\n\n const handleOnFocus = () => {\n handleErrorChange('email', '');\n dispatch(clearRegistrationBackendError('email'));\n };\n\n const handleSuggestionClick = (event) => {\n event.preventDefault();\n handleErrorChange('email', '');\n handleChange({ target: { name: 'email', value: emailSuggestion.suggestion } });\n setEmailSuggestion({ suggestion: '', type: '' });\n };\n\n const handleSuggestionClosed = () => setEmailSuggestion({ suggestion: '', type: '' });\n\n const renderEmailFeedback = () => {\n if (emailSuggestion.type === 'error') {\n return (\n <Alert variant=\"danger\" className=\"email-suggestion-alert-error mt-1\" icon={Error}>\n <span className=\"email-suggestion__text\">\n {formatMessage(messages['did.you.mean.alert.text'])}{' '}\n <Alert.Link\n href=\"#\"\n name=\"email\"\n onClick={handleSuggestionClick}\n >\n {emailSuggestion.suggestion}\n </Alert.Link>?\n <Icon src={Close} className=\"email-suggestion__close\" onClick={handleSuggestionClosed} tabIndex=\"0\" />\n </span>\n </Alert>\n );\n }\n return (\n <span id=\"email-warning\" className=\"small\">\n {formatMessage(messages['did.you.mean.alert.text'])}:{' '}\n <Alert.Link\n href=\"#\"\n name=\"email\"\n className=\"email-suggestion-alert-warning\"\n onClick={handleSuggestionClick}\n >\n {emailSuggestion.suggestion}\n </Alert.Link>?\n </span>\n );\n };\n\n return (\n <FormGroup\n borderClass={emailSuggestion.type === 'warning' ? 'yellow-border' : ''}\n maxLength={254} // Limit per RFCs is 254\n {...props}\n handleBlur={handleOnBlur}\n handleFocus={handleOnFocus}\n >\n {emailSuggestion.suggestion ? renderEmailFeedback() : null}\n </FormGroup>\n );\n};\n\nEmailField.defaultProps = {\n errorMessage: '',\n confirmEmailValue: null,\n};\n\nEmailField.propTypes = {\n errorMessage: PropTypes.string,\n value: PropTypes.string.isRequired,\n handleChange: PropTypes.func.isRequired,\n handleErrorChange: PropTypes.func.isRequired,\n confirmEmailValue: PropTypes.string,\n};\n\nexport default EmailField;\n"]}
1
+ {"version":3,"file":"EmailField.js","sourceRoot":"","sources":["../../../../src/register/RegistrationFields/EmailField/EmailField.jsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,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,GAAG,IACV,KAAK,IACT,UAAU,EAAE,YAAY,EACxB,WAAW,EAAE,aAAa,YAEzB,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC,IAAI,IAChD,CACb,CAAC;AACJ,CAAC,CAAC;AAEF,UAAU,CAAC,YAAY,GAAG;IACxB,YAAY,EAAE,EAAE;IAChB,iBAAiB,EAAE,IAAI;CACxB,CAAC;AAEF,UAAU,CAAC,SAAS,GAAG;IACrB,YAAY,EAAE,SAAS,CAAC,MAAM;IAC9B,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,UAAU;IAClC,YAAY,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IACvC,iBAAiB,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IAC5C,iBAAiB,EAAE,SAAS,CAAC,MAAM;CACpC,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { useIntl } from '@openedx/frontend-base';\nimport { Alert, Icon } from '@openedx/paragon';\nimport { Close, Error } from '@openedx/paragon/icons';\nimport PropTypes from 'prop-types';\n\nimport validateEmail from './validator';\nimport { FormGroup } from '../../../common-components';\nimport { useRegisterContext } from '../../components/RegisterContext';\nimport { useFieldValidations } from '../../data/apiHook';\nimport messages from '../../messages';\n\n/**\n * Email field wrapper. It accepts following handlers\n * - handleChange for setting value change and\n * - handleErrorChange for setting error\n *\n * It is responsible for\n * - Generating email warning and error suggestions\n * - Setting and clearing email suggestions\n * - Performing email field validations\n * - clearing error on focus\n * - setting value on change\n */\nconst EmailField = (props) => {\n const { formatMessage } = useIntl();\n\n const {\n setValidationsSuccess,\n setValidationsFailure,\n validationApiRateLimited,\n clearRegistrationBackendError,\n registrationFormData,\n setEmailSuggestionContext,\n } = useRegisterContext();\n\n const {\n handleChange,\n handleErrorChange,\n confirmEmailValue,\n } = props;\n\n const fieldValidationsMutation = useFieldValidations({\n onSuccess: (data) => {\n setValidationsSuccess(data);\n },\n onError: () => {\n setValidationsFailure();\n },\n });\n\n const backedUpFormData = registrationFormData;\n const [emailSuggestion, setEmailSuggestion] = useState({ ...backedUpFormData?.emailSuggestion });\n\n useEffect(() => {\n setEmailSuggestion(backedUpFormData.emailSuggestion);\n }, [backedUpFormData.emailSuggestion]);\n\n const handleOnBlur = (e) => {\n const { value } = e.target;\n const { fieldError, confirmEmailError, suggestion } = validateEmail(value, confirmEmailValue, formatMessage);\n\n if (confirmEmailError) {\n handleErrorChange('confirm_email', confirmEmailError);\n }\n setEmailSuggestionContext(suggestion.suggestion, suggestion.type);\n setEmailSuggestion(suggestion);\n\n if (fieldError) {\n handleErrorChange('email', fieldError);\n } else if (!validationApiRateLimited) {\n fieldValidationsMutation.mutate({ email: value });\n }\n };\n\n const handleOnFocus = () => {\n handleErrorChange('email', '');\n clearRegistrationBackendError('email');\n };\n\n const handleSuggestionClick = (event) => {\n event.preventDefault();\n handleErrorChange('email', '');\n handleChange({ target: { name: 'email', value: emailSuggestion.suggestion } });\n setEmailSuggestion({ suggestion: '', type: '' });\n setEmailSuggestionContext('', '');\n };\n\n const handleSuggestionClosed = () => setEmailSuggestion({ suggestion: '', type: '' });\n\n const renderEmailFeedback = () => {\n if (emailSuggestion.type === 'error') {\n return (\n <Alert variant=\"danger\" className=\"email-suggestion-alert-error mt-1\" icon={Error}>\n <span className=\"email-suggestion__text\">\n {formatMessage(messages['did.you.mean.alert.text'])}{' '}\n <Alert.Link\n href=\"#\"\n name=\"email\"\n onClick={handleSuggestionClick}\n >\n {emailSuggestion.suggestion}\n </Alert.Link>?\n <Icon src={Close} className=\"email-suggestion__close\" onClick={handleSuggestionClosed} tabIndex=\"0\" />\n </span>\n </Alert>\n );\n }\n return (\n <span id=\"email-warning\" className=\"small\">\n {formatMessage(messages['did.you.mean.alert.text'])}:{' '}\n <Alert.Link\n href=\"#\"\n name=\"email\"\n className=\"email-suggestion-alert-warning\"\n onClick={handleSuggestionClick}\n >\n {emailSuggestion.suggestion}\n </Alert.Link>?\n </span>\n );\n };\n\n return (\n <FormGroup\n borderClass={emailSuggestion.type === 'warning' ? 'yellow-border' : ''}\n maxLength={254} // Limit per RFCs is 254\n {...props}\n handleBlur={handleOnBlur}\n handleFocus={handleOnFocus}\n >\n {emailSuggestion.suggestion ? renderEmailFeedback() : null}\n </FormGroup>\n );\n};\n\nEmailField.defaultProps = {\n errorMessage: '',\n confirmEmailValue: null,\n};\n\nEmailField.propTypes = {\n errorMessage: PropTypes.string,\n value: PropTypes.string.isRequired,\n handleChange: PropTypes.func.isRequired,\n handleErrorChange: PropTypes.func.isRequired,\n confirmEmailValue: PropTypes.string,\n};\n\nexport default EmailField;\n"]}
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useDispatch, useSelector } from 'react-redux';
3
2
  import { useIntl } from '@openedx/frontend-base';
4
3
  import PropTypes from 'prop-types';
5
- import { FormGroup } from '../../../common-components';
6
- import { clearRegistrationBackendError, fetchRealtimeValidations } from '../../data/actions';
7
4
  import validateName from './validator';
5
+ import { FormGroup } from '../../../common-components';
6
+ import { useRegisterContext } from '../../components/RegisterContext';
7
+ import { useFieldValidations } from '../../data/apiHook';
8
8
  /**
9
9
  * Name field wrapper. It accepts following handlers
10
10
  * - handleChange for setting value change and
@@ -18,8 +18,15 @@ import validateName from './validator';
18
18
  */
19
19
  const NameField = (props) => {
20
20
  const { formatMessage } = useIntl();
21
- const dispatch = useDispatch();
22
- const validationApiRateLimited = useSelector(state => state.register.validationApiRateLimited);
21
+ const { setValidationsSuccess, setValidationsFailure, validationApiRateLimited, clearRegistrationBackendError, } = useRegisterContext();
22
+ const fieldValidationsMutation = useFieldValidations({
23
+ onSuccess: (data) => {
24
+ setValidationsSuccess(data);
25
+ },
26
+ onError: () => {
27
+ setValidationsFailure();
28
+ },
29
+ });
23
30
  const { handleErrorChange, shouldFetchUsernameSuggestions, } = props;
24
31
  const handleOnBlur = (e) => {
25
32
  const { value } = e.target;
@@ -28,12 +35,12 @@ const NameField = (props) => {
28
35
  handleErrorChange('name', fieldError);
29
36
  }
30
37
  else if (shouldFetchUsernameSuggestions && !validationApiRateLimited) {
31
- dispatch(fetchRealtimeValidations({ name: value }));
38
+ fieldValidationsMutation.mutate({ name: value });
32
39
  }
33
40
  };
34
41
  const handleOnFocus = () => {
35
42
  handleErrorChange('name', '');
36
- dispatch(clearRegistrationBackendError('name'));
43
+ clearRegistrationBackendError('name');
37
44
  };
38
45
  return (_jsx(FormGroup, Object.assign({}, props, { handleBlur: handleOnBlur, handleFocus: handleOnFocus })));
39
46
  };
@@ -1 +1 @@
1
- {"version":3,"file":"NameField.js","sourceRoot":"","sources":["../../../../src/register/RegistrationFields/NameField/NameField.jsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,6BAA6B,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,YAAY,MAAM,aAAa,CAAC;AAEvC;;;;;;;;;;GAUG;AACH,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,EAAE;IAC1B,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,EAAE,CAAC;IACpC,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,wBAAwB,GAAG,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC;IAE/F,MAAM,EACJ,iBAAiB,EACjB,8BAA8B,GAC/B,GAAG,KAAK,CAAC;IAEV,MAAM,YAAY,GAAG,CAAC,CAAC,EAAE,EAAE;QACzB,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC;QAC3B,MAAM,UAAU,GAAG,YAAY,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QACtD,IAAI,UAAU,EAAE,CAAC;YACf,iBAAiB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACxC,CAAC;aAAM,IAAI,8BAA8B,IAAI,CAAC,wBAAwB,EAAE,CAAC;YACvE,QAAQ,CAAC,wBAAwB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QACtD,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG,GAAG,EAAE;QACzB,iBAAiB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC9B,QAAQ,CAAC,6BAA6B,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC;IAEF,OAAO,CACL,KAAC,SAAS,oBACJ,KAAK,IACT,UAAU,EAAE,YAAY,EACxB,WAAW,EAAE,aAAa,IAC1B,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,SAAS,CAAC,YAAY,GAAG;IACvB,YAAY,EAAE,EAAE;IAChB,8BAA8B,EAAE,KAAK;CACtC,CAAC;AAEF,SAAS,CAAC,SAAS,GAAG;IACpB,YAAY,EAAE,SAAS,CAAC,MAAM;IAC9B,8BAA8B,EAAE,SAAS,CAAC,IAAI;IAC9C,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,UAAU;IAClC,YAAY,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IACvC,iBAAiB,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;CAC7C,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import { useDispatch, useSelector } from 'react-redux';\n\nimport { useIntl } from '@openedx/frontend-base';\nimport PropTypes from 'prop-types';\n\nimport { FormGroup } from '../../../common-components';\nimport { clearRegistrationBackendError, fetchRealtimeValidations } from '../../data/actions';\nimport validateName from './validator';\n\n/**\n * Name field wrapper. It accepts following handlers\n * - handleChange for setting value change and\n * - handleErrorChange for setting error\n *\n * It is responsible for\n * - Making backend call for generating username suggestions\n * - Performing name field validations\n * - Clearing error on focus\n * - Setting value on change\n */\nconst NameField = (props) => {\n const { formatMessage } = useIntl();\n const dispatch = useDispatch();\n const validationApiRateLimited = useSelector(state => state.register.validationApiRateLimited);\n\n const {\n handleErrorChange,\n shouldFetchUsernameSuggestions,\n } = props;\n\n const handleOnBlur = (e) => {\n const { value } = e.target;\n const fieldError = validateName(value, formatMessage);\n if (fieldError) {\n handleErrorChange('name', fieldError);\n } else if (shouldFetchUsernameSuggestions && !validationApiRateLimited) {\n dispatch(fetchRealtimeValidations({ name: value }));\n }\n };\n\n const handleOnFocus = () => {\n handleErrorChange('name', '');\n dispatch(clearRegistrationBackendError('name'));\n };\n\n return (\n <FormGroup\n {...props}\n handleBlur={handleOnBlur}\n handleFocus={handleOnFocus}\n />\n );\n};\n\nNameField.defaultProps = {\n errorMessage: '',\n shouldFetchUsernameSuggestions: false,\n};\n\nNameField.propTypes = {\n errorMessage: PropTypes.string,\n shouldFetchUsernameSuggestions: PropTypes.bool,\n value: PropTypes.string.isRequired,\n handleChange: PropTypes.func.isRequired,\n handleErrorChange: PropTypes.func.isRequired,\n};\n\nexport default NameField;\n"]}
1
+ {"version":3,"file":"NameField.js","sourceRoot":"","sources":["../../../../src/register/RegistrationFields/NameField/NameField.jsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,YAAY,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,EAAE;IAC1B,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,EAAE,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AS,CAAC,MAAM;IAC9B,8BAA8B,EAAE,SAAS,CAAC,IAAI;IAC9C,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,UAAU;IAClC,YAAY,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IACvC,iBAAiB,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;CAC7C,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import { useIntl } from '@openedx/frontend-base';\nimport PropTypes from 'prop-types';\n\nimport validateName from './validator';\nimport { FormGroup } from '../../../common-components';\nimport { useRegisterContext } from '../../components/RegisterContext';\nimport { useFieldValidations } from '../../data/apiHook';\n\n/**\n * Name field wrapper. It accepts following handlers\n * - handleChange for setting value change and\n * - handleErrorChange for setting error\n *\n * It is responsible for\n * - Making backend call for generating username suggestions\n * - Performing name field validations\n * - Clearing error on focus\n * - Setting value on change\n */\nconst NameField = (props) => {\n const { formatMessage } = useIntl();\n const {\n setValidationsSuccess,\n setValidationsFailure,\n validationApiRateLimited,\n clearRegistrationBackendError,\n } = useRegisterContext();\n\n const fieldValidationsMutation = useFieldValidations({\n onSuccess: (data) => {\n setValidationsSuccess(data);\n },\n onError: () => {\n setValidationsFailure();\n },\n });\n const {\n handleErrorChange,\n shouldFetchUsernameSuggestions,\n } = props;\n\n const handleOnBlur = (e) => {\n const { value } = e.target;\n const fieldError = validateName(value, formatMessage);\n if (fieldError) {\n handleErrorChange('name', fieldError);\n } else if (shouldFetchUsernameSuggestions && !validationApiRateLimited) {\n fieldValidationsMutation.mutate({ name: value });\n }\n };\n\n const handleOnFocus = () => {\n handleErrorChange('name', '');\n clearRegistrationBackendError('name');\n };\n\n return (\n <FormGroup\n {...props}\n handleBlur={handleOnBlur}\n handleFocus={handleOnFocus}\n />\n );\n};\n\nNameField.defaultProps = {\n errorMessage: '',\n shouldFetchUsernameSuggestions: false,\n};\n\nNameField.propTypes = {\n errorMessage: PropTypes.string,\n shouldFetchUsernameSuggestions: PropTypes.bool,\n value: PropTypes.string.isRequired,\n handleChange: PropTypes.func.isRequired,\n handleErrorChange: PropTypes.func.isRequired,\n};\n\nexport default NameField;\n"]}
@@ -1,5 +1,6 @@
1
1
  export const URL_REGEX: RegExp;
2
2
  export const HTML_REGEX: RegExp;
3
3
  export const INVALID_NAME_REGEX: RegExp;
4
+ export const MAX_FULL_NAME_LENGTH: 255;
4
5
  export default validateName;
5
6
  declare function validateName(value: any, formatMessage: any): string;
@@ -5,6 +5,7 @@ export const URL_REGEX = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-
5
5
  export const HTML_REGEX = /<|>/u;
6
6
  // regex from backend
7
7
  export const INVALID_NAME_REGEX = /https?:\/\/(?:[-\w.]|(?:%[\da-fA-F]{2}))*/g;
8
+ export const MAX_FULL_NAME_LENGTH = 255;
8
9
  const validateName = (value, formatMessage) => {
9
10
  let fieldError = '';
10
11
  if (!value.trim()) {
@@ -13,6 +14,9 @@ const validateName = (value, formatMessage) => {
13
14
  else if (URL_REGEX.test(value) || HTML_REGEX.test(value) || INVALID_NAME_REGEX.test(value)) {
14
15
  fieldError = formatMessage(messages['name.validation.message']);
15
16
  }
17
+ else if (value && value.length > MAX_FULL_NAME_LENGTH) {
18
+ fieldError = formatMessage(messages['name.validation.length.message'], { limit: MAX_FULL_NAME_LENGTH });
19
+ }
16
20
  return fieldError;
17
21
  };
18
22
  export default validateName;
@@ -1 +1 @@
1
- {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../../../src/register/RegistrationFields/NameField/validator.js"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,0CAA0C;AAC1C,MAAM,CAAC,MAAM,SAAS,GAAG,uFAAuF,CAAC,CAAC,wCAAwC;AAE1J,sBAAsB;AACtB,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC;AAEjC,qBAAqB;AACrB,MAAM,CAAC,MAAM,kBAAkB,GAAG,4CAA4C,CAAC;AAE/E,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;IAC5C,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QAClB,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC,CAAC;IACjE,CAAC;SAAM,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7F,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import messages from '../../messages';\n\n// regex more focused towards url matching\nexport const URL_REGEX = /[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)?/gi; // eslint-disable-line no-useless-escape\n\n// regex for html tags\nexport const HTML_REGEX = /<|>/u;\n\n// regex from backend\nexport const INVALID_NAME_REGEX = /https?:\\/\\/(?:[-\\w.]|(?:%[\\da-fA-F]{2}))*/g;\n\nconst validateName = (value, formatMessage) => {\n let fieldError = '';\n if (!value.trim()) {\n fieldError = formatMessage(messages['empty.name.field.error']);\n } else if (URL_REGEX.test(value) || HTML_REGEX.test(value) || INVALID_NAME_REGEX.test(value)) {\n fieldError = formatMessage(messages['name.validation.message']);\n }\n return fieldError;\n};\n\nexport default validateName;\n"]}
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../../../src/register/RegistrationFields/NameField/validator.js"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,0CAA0C;AAC1C,MAAM,CAAC,MAAM,SAAS,GAAG,uFAAuF,CAAC,CAAC,wCAAwC;AAE1J,sBAAsB;AACtB,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC;AAEjC,qBAAqB;AACrB,MAAM,CAAC,MAAM,kBAAkB,GAAG,4CAA4C,CAAC;AAE/E,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAExC,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;IAC5C,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QAClB,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC,CAAC;IACjE,CAAC;SAAM,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7F,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC,CAAC;IAClE,CAAC;SAAM,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,oBAAoB,EAAE,CAAC;QACxD,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,gCAAgC,CAAC,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC,CAAC;IAC1G,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import messages from '../../messages';\n\n// regex more focused towards url matching\nexport const URL_REGEX = /[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)?/gi; // eslint-disable-line no-useless-escape\n\n// regex for html tags\nexport const HTML_REGEX = /<|>/u;\n\n// regex from backend\nexport const INVALID_NAME_REGEX = /https?:\\/\\/(?:[-\\w.]|(?:%[\\da-fA-F]{2}))*/g;\n\nexport const MAX_FULL_NAME_LENGTH = 255;\n\nconst validateName = (value, formatMessage) => {\n let fieldError = '';\n if (!value.trim()) {\n fieldError = formatMessage(messages['empty.name.field.error']);\n } else if (URL_REGEX.test(value) || HTML_REGEX.test(value) || INVALID_NAME_REGEX.test(value)) {\n fieldError = formatMessage(messages['name.validation.message']);\n } else if (value && value.length > MAX_FULL_NAME_LENGTH) {\n fieldError = formatMessage(messages['name.validation.length.message'], { limit: MAX_FULL_NAME_LENGTH });\n }\n return fieldError;\n};\n\nexport default validateName;\n"]}
@@ -1,14 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect } from 'react';
3
- import { useDispatch, useSelector } from 'react-redux';
4
3
  import { useIntl } from '@openedx/frontend-base';
5
4
  import { Button, Icon, IconButton } from '@openedx/paragon';
6
5
  import { Close } from '@openedx/paragon/icons';
7
6
  import PropTypes from 'prop-types';
7
+ import validateUsername from './validator';
8
8
  import { FormGroup } from '../../../common-components';
9
- import { clearRegistrationBackendError, clearUsernameSuggestions, fetchRealtimeValidations, } from '../../data/actions';
9
+ import { useRegisterContext } from '../../components/RegisterContext';
10
+ import { useFieldValidations } from '../../data/apiHook';
10
11
  import messages from '../../messages';
11
- import validateUsername from './validator';
12
12
  /**
13
13
  * Username field wrapper. It accepts following handlers
14
14
  * - handleChange for setting value change and
@@ -23,13 +23,19 @@ import validateUsername from './validator';
23
23
  */
24
24
  const UsernameField = (props) => {
25
25
  const { formatMessage } = useIntl();
26
- const dispatch = useDispatch();
27
26
  const { value, errorMessage, handleChange, handleErrorChange, } = props;
28
27
  let className = '';
29
28
  let suggestedUsernameDiv = null;
30
29
  let iconButton = null;
31
- const usernameSuggestions = useSelector(state => state.register.usernameSuggestions);
32
- const validationApiRateLimited = useSelector(state => state.register.validationApiRateLimited);
30
+ const { usernameSuggestions, validationApiRateLimited, setValidationsSuccess, setValidationsFailure, clearUsernameSuggestions, clearRegistrationBackendError, } = useRegisterContext();
31
+ const fieldValidationsMutation = useFieldValidations({
32
+ onSuccess: (data) => {
33
+ setValidationsSuccess(data);
34
+ },
35
+ onError: () => {
36
+ setValidationsFailure();
37
+ },
38
+ });
33
39
  /**
34
40
  * We need to remove the placeholder from the field, adding a space will do that.
35
41
  * This is needed because we are placing the username suggestions on top of the field.
@@ -46,7 +52,7 @@ const UsernameField = (props) => {
46
52
  handleErrorChange('username', fieldError);
47
53
  }
48
54
  else if (!validationApiRateLimited) {
49
- dispatch(fetchRealtimeValidations({ username }));
55
+ fieldValidationsMutation.mutate({ username });
50
56
  }
51
57
  };
52
58
  const handleOnChange = (event) => {
@@ -61,7 +67,7 @@ const UsernameField = (props) => {
61
67
  };
62
68
  const handleOnFocus = (event) => {
63
69
  const username = event.target.value;
64
- dispatch(clearUsernameSuggestions());
70
+ clearUsernameSuggestions();
65
71
  // If we added a space character to username field to display the suggestion
66
72
  // remove it before user enters the input. This is to ensure user doesn't
67
73
  // have a space prefixed to the username.
@@ -69,21 +75,21 @@ const UsernameField = (props) => {
69
75
  handleChange({ target: { name: 'username', value: '' } });
70
76
  }
71
77
  handleErrorChange('username', '');
72
- dispatch(clearRegistrationBackendError('username'));
78
+ clearRegistrationBackendError('username');
73
79
  };
74
80
  const handleSuggestionClick = (event, suggestion = '') => {
75
81
  event.preventDefault();
76
82
  handleErrorChange('username', ''); // clear error
77
83
  handleChange({ target: { name: 'username', value: suggestion } }); // to set suggestion as value
78
- dispatch(clearUsernameSuggestions());
84
+ clearUsernameSuggestions();
79
85
  };
80
86
  const handleUsernameSuggestionClose = () => {
81
87
  handleChange({ target: { name: 'username', value: '' } }); // to remove space in field
82
- dispatch(clearUsernameSuggestions());
88
+ clearUsernameSuggestions();
83
89
  };
84
- const suggestedUsernames = () => (_jsxs("div", { className: className, children: [_jsx("span", { className: "text-gray username-suggestion--label", children: formatMessage(messages['registration.username.suggestion.label']) }), _jsx("div", { className: "username-scroll-suggested--form-field", children: usernameSuggestions.map((username, index) => (_jsx(Button, { type: "button", name: "username", variant: "outline-dark", className: "username-suggestions--chip data-hj-suppress", autoComplete: props.autoComplete, onClick: (e) => handleSuggestionClick(e, username), children: username }, `suggestion-${index.toString()}`))) }), iconButton] }));
90
+ const suggestedUsernames = () => (_jsxs("div", { className: className, role: "listbox", children: [_jsx("span", { className: "text-gray username-suggestion--label", children: formatMessage(messages['registration.username.suggestion.label']) }), _jsx("div", { className: "username-scroll-suggested--form-field", children: usernameSuggestions.map((username, index) => (_jsx(Button, { type: "button", name: "username", variant: "outline-dark", className: "username-suggestions--chip data-hj-suppress", autoComplete: props.autoComplete, tabIndex: 0, onClick: (e) => handleSuggestionClick(e, username), role: "option", children: username }, `suggestion-${index.toString()}`))) }), iconButton] }));
85
91
  if (usernameSuggestions.length > 0 && errorMessage && value === ' ') {
86
- className = 'username-suggestions__error';
92
+ className = 'username-suggestions';
87
93
  iconButton = _jsx(IconButton, { src: Close, iconAs: Icon, alt: "Close", onClick: () => handleUsernameSuggestionClose(), variant: "black", size: "sm", className: "username-suggestions__close__button" });
88
94
  suggestedUsernameDiv = suggestedUsernames();
89
95
  }
@@ -95,7 +101,7 @@ const UsernameField = (props) => {
95
101
  else if (usernameSuggestions.length > 0 && errorMessage) {
96
102
  suggestedUsernameDiv = suggestedUsernames();
97
103
  }
98
- return (_jsx(FormGroup, Object.assign({}, props, { handleChange: handleOnChange, handleFocus: handleOnFocus, handleBlur: handleOnBlur, children: suggestedUsernameDiv })));
104
+ return (_jsxs("div", { className: "username__form-group-wrapper", children: [suggestedUsernameDiv, _jsx(FormGroup, Object.assign({}, props, { handleChange: handleOnChange, handleFocus: handleOnFocus, handleBlur: handleOnBlur }))] }));
99
105
  };
100
106
  UsernameField.defaultProps = {
101
107
  errorMessage: '',