Skip to content

Commit

Permalink
permitee column, invitation request made successfully on modal load
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsyro committed Oct 18, 2023
1 parent 8621fc9 commit 838a179
Show file tree
Hide file tree
Showing 17 changed files with 267 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from flask_restplus import Resource
from werkzeug.exceptions import NotFound
from app.extensions import api
from app.api.utils.access_decorators import requires_any_of, VIEW_ALL, MINESPACE_PROPONENT

from app.api.parties.party.models.party import Party
from app.api.services.traction_service import TractionService
Expand All @@ -10,6 +11,7 @@

class VerifiableCredentialConnectionResource(Resource, UserMixin):
@api.doc(description='Create a connection invitation for a party by guid', params={})
@requires_any_of([VIEW_ALL, MINESPACE_PROPONENT])
def post(self, party_guid: str):
#mine_guid will be param. just easy this way for development
party = Party.find_by_party_guid(party_guid)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { notification } from "antd";
import { ENVIRONMENT } from "@mds/common";
import { request, success, error } from "../actions/genericActions";
import * as reducerTypes from "../constants/reducerTypes";
import * as verfiableCredentialActions from "../actions/verfiableCredentialActions";
import { createRequestHeader } from "../utils/RequestHeaders";
import { showLoading, hideLoading } from "react-redux-loading-bar";
import CustomAxios from "../customAxios";

export const createVCWalletInvitation = (party_guid) => (dispatch) => {
dispatch(showLoading("modal"));
dispatch(request(reducerTypes.CREATE_VC_WALLET_CONNECTION_INVITATION));
return CustomAxios()
.post(
`${ENVIRONMENT.apiUrl}/verifiable-credentials/oob-invitation/${party_guid}`,
null,
createRequestHeader()
)
.then((response) => {
dispatch(success(reducerTypes.CREATE_VC_WALLET_CONNECTION_INVITATION));
dispatch(verfiableCredentialActions.storeVCConnectionInvitation(response.data));
dispatch(hideLoading("modal"));
})
.catch((err) => {
notification.error({
message: err.response ? err.response.data.message : String.ERROR,
duration: 10,
});
dispatch(error(reducerTypes.CREATE_VC_WALLET_CONNECTION_INVITATION));
dispatch(hideLoading("modal"));
});
};
3 changes: 3 additions & 0 deletions services/minespace-web/common/constants/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,6 @@ export const CLEAR_TAILINGS_STORAGE_FACILITY = "CLEAR_TAILINGS_STORAGE_FACILITY"

// Dams
export const STORE_DAM = "STORE_DAM";

// Verifiable Credentials
export const STORE_VC_WALLET_CONNECTION_INVITATION = "STORE_VC_WALLET_CONNECTION_INVITATION";
4 changes: 4 additions & 0 deletions services/minespace-web/common/constants/reducerTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,7 @@ export const GET_DAM = "GET_DAM";

// Alerts
export const GET_GLOBAL_ALERTS = "GET_GLOBAL_ALERTS";

//Verficable Credentials
export const VERIFIABLE_CREDENTIALS = "VERIFIABLE_CREDENTIALS";
export const CREATE_VC_WALLET_CONNECTION_INVITATION = "CREATE_VC_WALLET_CONNECTION_INVITATION";
2 changes: 2 additions & 0 deletions services/minespace-web/common/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import tailingsReducerObject from "./reducers/tailingsReducer";
import userReducerObject from "./reducers/userReducer";
import varianceReducerObject from "./reducers/varianceReducer";
import workInformationReducerObject from "./reducers/workInformationReducer";
import verifiableCredentialReducerObject from "./reducers/verifiableCredentialReducer";

export const complianceReducer = complianceReducerObject;
export const authenticationReducer = authenticationReducerObject;
Expand All @@ -50,3 +51,4 @@ export const noticeOfDepartureReducer = noticeOfDepartureReducerObject;
export const activityReducer = activityReducerObject;
export const tailingsReducer = tailingsReducerObject;
export const damReducer = damReducerObject;
export const verifiableCredentialReducer = verifiableCredentialReducerObject;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as actionTypes from "../constants/actionTypes";
import { VERIFIABLE_CREDENTIALS } from "../constants/reducerTypes";

/**
* @file verifiableCredentialReducer.js
* all data associated with verificable credential records.
*/

const initialState = {
vcWalletConnectionInvitation: {},
};

const verifiableCredentialReducer = (state = initialState, action) => {
switch (action.type) {
case actionTypes.STORE_VC_WALLET_CONNECTION_INVITATION:
return {
...state,
vcWalletConnectionInvitation: action.payload,
};
default:
return state;
}
};

const verifiableCredentialReducerObject = {
[VERIFIABLE_CREDENTIALS]: verifiableCredentialReducer,
};

export const getVCWalletConnectionInvitation = (state) =>
state[VERIFIABLE_CREDENTIALS].vcWalletConnectionInvitation;

export default verifiableCredentialReducerObject;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as verifiableCredentialReducer from "../reducers/verifiableCredentialReducer";

export const { getVCWalletConnectionInvitation } = verifiableCredentialReducer;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { showLoading, hideLoading } from "react-redux-loading-bar";
import { ENVIRONMENT } from "@mds/common";
import { request, success, error } from "@/actions/genericActions";
import * as userMineActions from "@/actions/userMineActions";
import * as verfiableCredentialActions from "@/actions/verfiableCredentialActions";
import * as reducerTypes from "@/constants/reducerTypes";
import * as API from "@/constants/API";
import { createRequestHeader } from "@/utils/RequestHeaders";
Expand Down Expand Up @@ -48,23 +47,3 @@ export const fetchMineRecordById = (mineId) => (dispatch) => {
dispatch(hideLoading());
});
};

export const createVCWalletInvitation = (party_guid) => (dispatch) => {
dispatch(showLoading());
dispatch(request(reducerTypes.CREATE_VC_WALLET_CONNECTION_INVITATION));
return axios
.get(`${ENVIRONMENT.apiUrl}/oob-invitation/${party_guid}`, createRequestHeader())
.then((response) => {
dispatch(success(reducerTypes.CREATE_VC_WALLET_CONNECTION_INVITATION));
dispatch(verfiableCredentialActions.storeVCConnectionInvitation(response.data));
dispatch(hideLoading());
})
.catch((err) => {
notification.error({
message: err.response ? err.response.data.message : String.ERROR,
duration: 10,
});
dispatch(error(reducerTypes.CREATE_VC_WALLET_CONNECTION_INVITATION));
dispatch(hideLoading());
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { reduxForm } from "redux-form";
import { Form } from "@ant-design/compatible";
import "@ant-design/compatible/assets/index.css";
import { Button, Popconfirm } from "antd";
import { resetForm } from "@common/utils/helpers";
import * as FORM from "@/constants/forms";

const propTypes = {
handleSubmit: PropTypes.func.isRequired,
createVCWalletInvitation: PropTypes.func.isRequired,
closeModal: PropTypes.func.isRequired,
submitting: PropTypes.bool.isRequired,
partyGuid: PropTypes.string.isRequired,
partyName: PropTypes.string.isRequired,
invitation: PropTypes.any.isRequired,
};

export class CreateInvitationForm extends Component {
render() {
return (
<Form layout="vertical">
<Button
className="secondary"
type="secondary"
disabled={this.props.submitting}
onClick={this.props.createVCWalletInvitation(this.props.partyGuid)}
>
Generate Invitation for {this.props.partyName}.
</Button>
<br />
<br />
<p>
<b>
Accept this invitation url using the digital wallet of {this.props.partyName}. to
establish a secure connection for the purposes of recieving Mines Act Permits
</b>
</p>
<br />
<Button className="primary" type="primary">
Copy to Clipboard
</Button>
<br />
<p></p>

<Popconfirm
placement="topRight"
title="Are you sure you want to cancel?"
onConfirm={this.props.closeModal}
okText="Yes"
cancelText="No"
disabled={this.props.submitting}
>
<Button disabled={this.props.submitting}>Cancel</Button>
</Popconfirm>
</Form>
);
}
}

CreateInvitationForm.propTypes = propTypes;

export default reduxForm({
form: FORM.CREATE_VC_CONNECTION_INVITATION,
touchOnBlur: false,
onSubmitSuccess: resetForm(FORM.CREATE_VC_CONNECTION_INVITATION),
})(CreateInvitationForm);
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import React from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import PropTypes from "prop-types";
import { openModal, closeModal } from "@common/actions/modalActions";
import { truncateFilename, dateSorter } from "@common/utils/helpers";
import { getDropdownPermitStatusOptions } from "@common/selectors/staticContentSelectors";
import { downloadFileFromDocumentManager } from "@common/utils/actionlessNetworkCalls";
import { formatDate } from "@/utils/helpers";
import LinkButton from "@/components/common/LinkButton";
import { modalConfig } from "@/components/modalContent/config";
import CustomPropTypes from "@/customPropTypes";
import * as Strings from "@/constants/strings";
import CoreTable from "@/components/common/CoreTable";
import { Button } from "antd";

const draftAmendment = "DFT";

Expand All @@ -25,6 +29,26 @@ const columns = [
key: "number",
sorter: (a, b) => (a.number > b.number ? -1 : 1),
},
{
title: "Permitee",
dataIndex: "permitee",
key: "permitee",
},
{
title: "",
dataIndex: "permitee_guid",
render: (text, record) => (
<div title="">
<Button
style={{ display: "inline" }}
type="secondary"
onClick={(event) => record.openVCWalletInvitationModal(event, text, record.permitee)}
>
Wallet Connection Info
</Button>
</div>
),
},
{
title: "Permit Status",
dataIndex: "status",
Expand Down Expand Up @@ -64,7 +88,7 @@ const finalApplicationPackage = (amendment) => {
return finalAppPackageCore.concat(finalAppPackageImported);
};

const transformRowData = (permit, permitStatusOptions) => {
const transformRowData = (permit, permitStatusOptions, openVCWalletInvitationModal) => {
const filteredAmendments = permit.permit_amendments.filter(
(a) => a.permit_amendment_status_code !== draftAmendment
);
Expand All @@ -73,6 +97,9 @@ const transformRowData = (permit, permitStatusOptions) => {
return {
key: permit.permit_no || Strings.EMPTY_FIELD,
number: permit.permit_no || Strings.EMPTY_FIELD,
permitee: permit.current_permittee || Strings.EMPTY_FIELD,
permitee_guid: permit.current_permittee_guid || Strings.EMPTY_FIELD,
openVCWalletInvitationModal: openVCWalletInvitationModal,
status:
(permit.permit_status_code &&
permitStatusOptions.find((item) => item.value === permit.permit_status_code).label) ||
Expand Down Expand Up @@ -100,8 +127,20 @@ const transformExpandedRowData = (amendment, amendmentNumber) => ({
});

export const PermitsTable = (props) => {
const openVCWalletInvitationModal = (event, partyGuid, partyName) => {
event.preventDefault();
props.openModal({
props: {
title: "Digital Wallet Connection Invitation",
partyGuid: partyGuid,
partyName: partyName,
},
content: modalConfig.VC_WALLET_INVITATION,
});
};

const rowData = props.permits.map((permit) =>
transformRowData(permit, props.permitStatusOptions)
transformRowData(permit, props.permitStatusOptions, openVCWalletInvitationModal)
);

const getExpandedRowData = (permit) =>
Expand Down Expand Up @@ -169,6 +208,17 @@ export const PermitsTable = (props) => {
</div>
),
},
{
title: "",
dataIndex: "",
render: (text, record) => (
<div title="">
<Button style={{ display: "inline" }} type="primary">
Issue Digital Credential
</Button>
</div>
),
},
];

return (
Expand All @@ -191,4 +241,13 @@ const mapStateToProps = (state) => ({
permitStatusOptions: getDropdownPermitStatusOptions(state),
});

export default connect(mapStateToProps)(PermitsTable);
const mapDispatchToProps = (dispatch) =>
bindActionCreators(
{
openModal,
closeModal,
},
dispatch
);

export default connect(mapStateToProps, mapDispatchToProps)(PermitsTable);
2 changes: 2 additions & 0 deletions services/minespace-web/src/components/modalContent/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import UploadIncidentDocumentModal from "@/components/modalContent/incidents/Upl
import ArchiveDocumentModal from "@common/components/documents/ArchiveDocumentModal";
import DeleteDocumentModal from "@common/components/documents/DeleteDocumentModal";
import ReplaceDocumentModal from "@common/components/documents/ReplaceDocumentModal";
import CreateInvitationModal from "@/components/modalContent/verifiableCredentials/createInvitationModal";

export const modalConfig = {
ADD_REPORT: AddReportModal,
Expand All @@ -36,6 +37,7 @@ export const modalConfig = {
IMPORT_IRT_FAILURE: ImportIRTErrorModal,
VIEW_FILE_HISTORY: ViewFileHistoryModal,
UPLOAD_INCIDENT_DOCUMENT: UploadIncidentDocumentModal,
VC_WALLET_INVITATION: CreateInvitationModal,
};

export default modalConfig;
Loading

0 comments on commit 838a179

Please sign in to comment.