diff --git a/src/components/study-container.jsx b/src/components/study-container.jsx index f8d5224c9e..eb9d9cc0ee 100644 --- a/src/components/study-container.jsx +++ b/src/components/study-container.jsx @@ -38,7 +38,7 @@ import { useIntlRef, useNotificationsListener, useSnackMessage, - BuildStatus, + BuildStatus, fetchUserQuotaState, } from '@gridsuite/commons-ui'; import NetworkModificationTreeModel from './graph/network-modification-tree-model'; import { getFirstNodeOfType } from './graph/util/model-functions'; @@ -493,6 +493,28 @@ export function StudyContainer() { listenerCallbackMessage: handleEvent, }); + const handleQuotaEvent = useCallback( + (event) => { + const eventData = parseEventData(event); + const quotaType = eventData.headers.quotaType; + + fetchUserQuotaState(userName).then((response) => { + const currentComputationQuota = response[quotaType] + if (currentComputationQuota != null) { + if (currentComputationQuota.current >= currentComputationQuota.max) { + console.info('TODO: Quota reached', quotaType, currentComputationQuota); + } else { + console.info('TODO: Quota available', quotaType, currentComputationQuota); + } + } + }) + } + ); + + useNotificationsListener(NotificationsUrlKeys.QUOTA, { + listenerCallbackMessage: handleQuotaEvent, + }); + useEffect(() => { if (studyUuid) { websocketExpectedCloseRef.current = false; diff --git a/src/hooks/use-notifications-url-generator.ts b/src/hooks/use-notifications-url-generator.ts index f2fe99a026..ea30be0328 100644 --- a/src/hooks/use-notifications-url-generator.ts +++ b/src/hooks/use-notifications-url-generator.ts @@ -20,6 +20,7 @@ const useNotificationsUrlGenerator = (): Partial state.studyUuid); + const userId = useSelector((state: AppState) => state.user?.profile.sub); // return a mapColumns with NOTIFICATIONS_URL_KEYS and undefined value if URL is not yet buildable (studyUuid) // it will be used to register listeners as soon as possible. @@ -30,6 +31,9 @@ const useNotificationsUrlGenerator = (): Partial