Commit a808e9d0 authored by Florent Chehab's avatar Florent Chehab

fix(frontend): history and todos

* Testing a bit the new setup
* need to merge this
parent a875ca41
Pipeline #53388 passed with stages
in 7 minutes and 42 seconds
......@@ -78,7 +78,6 @@ const buildParams = modelInfo => {
return RequestParams.Builder.withEndPointAttrs([contentTypeId, id]).build();
};
// TODO check what is displayed
function History({
versions,
modelInfo,
......@@ -89,8 +88,9 @@ function History({
rawModelDataEx
}) {
const resetVersions = useApiInvalidateAll("versions");
useEffect(() => {
return resetVersions(); // only on unmount
return () => resetVersions(); // only on unmount
}, []);
// keep the component up to date
......@@ -102,7 +102,10 @@ function History({
const maxSteps = versions.length;
const newRawModelData = { ...rawModelDataEx, ...versions[currentVersion] };
const newRawModelData = {
...rawModelDataEx,
...versions[currentVersion].data
};
return (
<FullScreenDialogFrame
......
......@@ -80,7 +80,7 @@ function PendingModeration({
const resetData = useApiInvalidateAll("pendingModerationObj");
useEffect(() => {
return resetData();
return () => resetData();
}, []);
// keep the component up to date
......
......@@ -36,13 +36,12 @@ function NumberField({
const serializeFromField = useCallback(v => {
const parsed = parseFloat(v);
if (isNaN(parsed)) return null;
return parsed;
});
}, []);
const [number, setNumberInt, error] = useField(fieldMapping, {
defaultNullValue: "",
defaultNullValue: null,
serializeFromField,
getError
});
......
......@@ -26,7 +26,6 @@ import {
useApiRead
} from "../../hooks/wrappers/api";
// TODO check if reload still works
function Introduction() {
const invalidateData = useApiInvalidateAll("exchanges");
const [, read] = useApiRead("updateStudentExchanges", "all");
......
......@@ -81,7 +81,11 @@ export const scholarshipFormLevelErrors = [
new FormLevelError(
["amount_min", "amount_max"],
(amountMin, amountMax) =>
amountMin !== null && amountMax !== null && amountMax < amountMin,
amountMin !== "" &&
amountMax !== "" &&
amountMin !== null &&
amountMax !== null &&
amountMax < amountMin,
"La logique voudrait que la borne supérieure de la bourse soit... supérieure à la borne inférieure."
),
new FormLevelError(
......
......@@ -105,7 +105,7 @@ function ModuleWrapper({
id: rawModelData.id
}}
editFromPendingModeration={openEditorTmp}
// TODO
// TODO Repare pending moderation validation
moderatePendingModeration={() => {}}
userCanModerate={rawModelData.obj_info.user_can_moderate}
/>
......
......@@ -5,11 +5,11 @@ import useConstantState from "./useConstantState";
export const globalState = new Map();
/**
* TODO
* Gets the latest data retrieved from the api for the key
* @param {string} key - route / sing or plur
*/
export function getLatestApiReadData(key) {
return getLatestRead(globalState.get(`api-${key}`)).data; // TODO move helper functions elsewhere
return getLatestRead(globalState.get(`api-${key}`)).data;
}
/**
......
......@@ -5,7 +5,7 @@ import CrudActions from "../../utils/api/CrudActions";
import RequestParams from "../../utils/api/RequestParams";
/**
* TODO
* Hook to use the API, provides several actions
*
* @param {string} route
* @param {"one"|"all"} variant
......@@ -31,10 +31,11 @@ export function useApi(route, variant) {
}
/**
* TODO
* Wrapper around useApi: only to read data
*
* @param route
* @param variant
* @returns {}
* @returns {[{}, function]}
*/
export function useApiRead(route, variant) {
const [data, dispatch, actions] = useApi(route, variant);
......@@ -52,7 +53,9 @@ export function useApiRead(route, variant) {
}
/**
* TODO
* Private helper to invalidate
*
* @private
* @param route
* @param variant
* @returns {Function}
......@@ -69,16 +72,26 @@ function _useApiInvalidate(route, variant) {
}, []);
}
/**
* Wrapper to invalidate "one" endpoint
* @param route
* @returns {function(): void}
*/
export function useApiInvalidateOne(route) {
return _useApiInvalidate(route, "one");
}
/**
* Wrapper to invalidate "all" endpoint
* @param route
* @returns {function(): void}
*/
export function useApiInvalidateAll(route) {
return _useApiInvalidate(route, "all");
}
/**
* TODO
* Private helper to delete
* @param route
* @private
*/
......@@ -90,7 +103,7 @@ function _useDeleteAction(route) {
/**
* Hook that can be used to delete api instance
*
* @param {string} routes
* @param {string} route
* @returns {Function}
*/
export function useApiDelete(route) {
......@@ -146,8 +159,6 @@ export function useApiCreate(route) {
return useMemo(() => createOne, [createOne]);
}
// todo better setup ?
/**
* Hook that can be used to update an api instance
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment