Skip to content

Commit

Permalink
feat: build governance UI
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstefanequilobe committed Jun 10, 2022
1 parent cc87084 commit 0e1eff2
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 9 deletions.
15 changes: 13 additions & 2 deletions src/pages/Governance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
Body,
} from '../../components';
import { useDispatch, useSelector } from 'react-redux';
import { getGovernanceOrgList } from '../../store/actions/climateWarehouseActions';
import {
getGovernanceOrgList,
updateGovernanceOrgLists,
updateGovernancePickLists,
} from '../../store/actions/climateWarehouseActions';
import { isJsonString } from '../../utils/json';

const StyledGovernanceContainer = styled('div')`
Expand Down Expand Up @@ -98,6 +102,13 @@ const Governance = () => {
[orgListTextarea],
);

const handleOnSend = () => {
if (isOrgListValid && arePickListsValid) {
dispatch(updateGovernanceOrgLists(orgListTextarea));
dispatch(updateGovernancePickLists(picklistsTextarea));
}
};

return (
<StyledGovernanceContainer>
<H2>
Expand Down Expand Up @@ -167,7 +178,7 @@ const Governance = () => {
disabled={!isOrgListValid && !arePickListsValid}
label={intl.formatMessage({ id: 'Send' })}
size="large"
onClick={() => console.log('pac pac')}
onClick={handleOnSend}
/>
</StyledButtonContainer>
</StyledGovernanceContainer>
Expand Down
100 changes: 100 additions & 0 deletions src/store/actions/climateWarehouseActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,106 @@ export const commitStagingData = (data, comment) => {
};
};

export const updateGovernancePickLists = data => {
return async dispatch => {
try {
dispatch(activateProgressIndicator);

const url = `${constants.API_HOST}/governance/meta/pickLists`;
const payload = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: data,
};

const response = await fetchWrapper(url, payload);

if (response.ok) {
dispatch(setConnectionCheck(true));
dispatch(
setNotificationMessage(
NotificationMessageTypeEnum.success,
'governance-picklists-updated-successfully',
),
);
} else {
const errorResponse = await response.json();
dispatch(
setNotificationMessage(
NotificationMessageTypeEnum.error,
formatApiErrorResponse(
errorResponse,
'governance-picklists-update-failed',
),
),
);
}
} catch {
dispatch(
setNotificationMessage(
NotificationMessageTypeEnum.error,
'governance-picklists-update-failed',
),
);
dispatch(setConnectionCheck(false));
} finally {
dispatch(deactivateProgressIndicator);
}
};
};

export const updateGovernanceOrgLists = data => {
return async dispatch => {
try {
dispatch(activateProgressIndicator);

const url = `${constants.API_HOST}/governance/meta/orgList`;
const payload = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: data,
};

const response = await fetchWrapper(url, payload);

if (response.ok) {
dispatch(setConnectionCheck(true));
dispatch(
setNotificationMessage(
NotificationMessageTypeEnum.success,
'governance-orglist-updated-successfully',
),
);
} else {
const errorResponse = await response.json();
dispatch(
setNotificationMessage(
NotificationMessageTypeEnum.error,
formatApiErrorResponse(
errorResponse,
'governance-orglist-update-failed',
),
),
);
}
} catch {
dispatch(
setNotificationMessage(
NotificationMessageTypeEnum.error,
'governance-orglist-update-failed',
),
);
dispatch(setConnectionCheck(false));
} finally {
dispatch(deactivateProgressIndicator);
}
};
};

export const deleteStagingData = uuid => {
return async dispatch => {
try {
Expand Down
10 changes: 7 additions & 3 deletions src/translations/tokens/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,13 @@
"governance": "Governance",
"initiate-governance": "Initiate Governance",
"governance-initiating-please0wait": "Your governance body is initiating, please 5 minutes then refresh.",
"picklists": "All picklists",
"picklists": "All pick lists",
"json-is-valid": "JSON is valid",
"json-not-valid": "Please add valid JSON",
"valid-json-example": "Valid JSON example",
"send": "Send"
}
"send": "Send",
"governance-picklists-updated-successfully": "The governance pick lists were updated successfully.",
"governance-picklists-update-failed": "The governance pick lists could not be updated.",
"governance-orglist-updated-successfully": "The governance organization list was updated successfully.",
"governance-orglist-update-failed": "The governance organization list could not be updated."
}
8 changes: 6 additions & 2 deletions src/translations/tokens/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,5 +371,9 @@
"json-is-valid": "JSON es válida",
"json-not-valid": "Agregue JSON válido",
"valid-json-example": "Ejemplo válido de JSON",
"send": "Enviar"
}
"send": "Enviar",
"governance-picklists-updated-successfully": "Las listas de selección de gobernanza se actualizaron correctamente.",
"governance-picklists-update-failed": "Las listas de selección de gobernanza no se pudieron actualizar.",
"governance-orglist-updated-successfully": "La lista de organizaciones de gobierno se actualizó correctamente.",
"governance-orglist-update-failed": "No se pudo actualizar la lista de organizaciones de gobierno."
}
7 changes: 5 additions & 2 deletions src/translations/tokens/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,16 @@
"governance-data-failed": "ガバナンスデータを読み込めませんでした。管理者に連絡してください。",
"ui-data-model-mismatch": "UIとデータモデルの間に不一致があります。",
"comment": "コメント",
"organization-information": "組織情報",
"governance": "Governance",
"initiate-governance": "ガバナンス",
"governance-initiating-please0wait": "ガバナンス機関が開始しています。5分後に更新してください。",
"picklists": "すべての選択リスト",
"json-is-valid": "JSONは有効です",
"json-not-valid": "JSONは有効です",
"valid-json-example": "有効なJSONの例",
"send": "送信"
"send": "送信",
"governance-picklists-updated-successfully": "ガバナンス選択リストは正常に更新されました。",
"governance-picklists-update-failed": "ガバナンス選択リストを更新できませんでした。",
"governance-orglist-updated-successfully": "ガバナンス組織リストが正常に更新されました。",
"governance-orglist-update-failed": "ガバナンス組織リストを更新できませんでした。"
}

0 comments on commit 0e1eff2

Please sign in to comment.