Replace Redux + Redux-Saga with React Query (useMutation/useQuery) for server state and React Context for UI/form state across all modules: login, registration, forgot-password, reset-password, progressive- profiling, and common-components. Port of master commits0d709d15and93bd0f24, adapted for @openedx/frontend-base: - getSiteConfig() instead of getConfig() - useAppConfig() for per-app configuration - @tanstack/react-query as peerDependency (shell provides QueryClient) - CurrentAppProvider instead of AppProvider Also fixes EnvironmentTypes circular dependency in site.config.test.tsx by using string literal instead of enum import. Co-Authored-By: Jesus Balderrama <jesus.balderrama.wgu@gmail.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import { getHttpClient, getSiteConfig } from '@openedx/frontend-base';
|
|
import formurlencoded from 'form-urlencoded';
|
|
|
|
const validateToken = async (token: string) => {
|
|
const requestConfig = {
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
};
|
|
|
|
const { data } = await getHttpClient()
|
|
.post(
|
|
`${getSiteConfig().lmsBaseUrl}/user_api/v1/account/password_reset/token/validate/`,
|
|
formurlencoded({ token }),
|
|
requestConfig,
|
|
)
|
|
.catch((e) => {
|
|
throw (e);
|
|
});
|
|
return data;
|
|
};
|
|
|
|
const resetPassword = async (payload, token, queryParams) => {
|
|
const requestConfig = {
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
};
|
|
const url = new URL(`${getSiteConfig().lmsBaseUrl}/password/reset/${token}/`);
|
|
|
|
if (queryParams.is_account_recovery) {
|
|
url.searchParams.append('is_account_recovery', 'true');
|
|
}
|
|
|
|
const { data } = await getHttpClient()
|
|
.post(url.href, formurlencoded(payload), requestConfig)
|
|
.catch((e) => {
|
|
throw (e);
|
|
});
|
|
return data;
|
|
};
|
|
|
|
const validatePassword = async (payload) => {
|
|
const requestConfig = {
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
};
|
|
const { data } = await getHttpClient()
|
|
.post(
|
|
`${getSiteConfig().lmsBaseUrl}/api/user/v1/validation/registration`,
|
|
formurlencoded(payload),
|
|
requestConfig,
|
|
)
|
|
.catch((e) => {
|
|
throw (e);
|
|
});
|
|
|
|
let errorMessage = '';
|
|
// Be careful about grabbing this message, since we could have received an HTTP error or the
|
|
// endpoint didn't give us what we expect. We only care if we get a clear error message.
|
|
if (data.validation_decisions?.password) {
|
|
errorMessage = data.validation_decisions.password;
|
|
}
|
|
|
|
return errorMessage;
|
|
};
|
|
|
|
export {
|
|
validateToken,
|
|
resetPassword,
|
|
validatePassword,
|
|
};
|