diff --git a/i18n/en_CA/LC_MESSAGES/src/components/profile/profileCard/GEDSAudit.js.po b/i18n/en_CA/LC_MESSAGES/src/components/profile/profileCard/GEDSAudit.js.po new file mode 100644 index 0000000..dd012b1 --- /dev/null +++ b/i18n/en_CA/LC_MESSAGES/src/components/profile/profileCard/GEDSAudit.js.po @@ -0,0 +1,94 @@ + +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2019-04-16 13:18-0400\n" +"PO-Revision-Date: 2019-02-13 10:51-0500\n" +"Last-Translator: FULL NAME \n" +"Language: en_CA\n" +"Language-Team: en_CA \n" +"Plural-Forms: nplurals=2; plural=(n != 1)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.6.0\n" + +#: 28:67 src/components/profile/profileCard/ProfileCardDisplay.js +msgid "Please select data" +msgstr "Please select the correct information" + +msgid "Other" +msgstr "" + +msgid "Other Value" +msgstr "" + +msgid "Your data is the same" +msgstr "You Directory and GEDS information are the same" + +msgid "GEDS Audit" +msgstr "" + +msgid "GEDS Audit" +msgstr "" + +msgid "GEDS" +msgstr "" + +msgid "Directory" +msgstr "" + +msgid "There are differences" +msgstr "We have found differences in the following information:" + +msgid "Directory Information" +msgstr "" + +msgid "Name" +msgstr "" + +msgid "Job Title - English" +msgstr "" + +msgid "Job Title - French" +msgstr "" + +msgid "Office Phone" +msgstr "" + +msgid "Mobile Phone" +msgstr "" + +msgid "Office Address" +msgstr "" + +msgid "Department" +msgstr "" + +msgid "Department" +msgstr "" + +msgid "auditName" +msgstr "Name" + +msgid "titleEn" +msgstr "Job Title - English" + +msgid "titleFr" +msgstr "Job Title - French" + +msgid "auditPhone" +msgstr "Office Phone" + +msgid "auditMobile" +msgstr "Mobile Phone" + +msgid "auditAddress" +msgstr "Office Address" + +msgid "auditOrg" +msgstr "Department" + +msgid "Save" +msgstr "" diff --git a/i18n/fr_CA/LC_MESSAGES/src/components/profile/profileCard/GEDSAudit.js.po b/i18n/fr_CA/LC_MESSAGES/src/components/profile/profileCard/GEDSAudit.js.po new file mode 100644 index 0000000..7c6653f --- /dev/null +++ b/i18n/fr_CA/LC_MESSAGES/src/components/profile/profileCard/GEDSAudit.js.po @@ -0,0 +1,94 @@ + +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2019-04-16 13:18-0400\n" +"PO-Revision-Date: 2019-02-13 10:51-0500\n" +"Last-Translator: FULL NAME \n" +"Language: fr_CA\n" +"Language-Team: fr_CA \n" +"Plural-Forms: nplurals=2; plural=(n > 1)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.6.0\n" + +#: 28:67 src/components/profile/profileCard/ProfileCardDisplay.js +msgid "Please select data" +msgstr "Veuillez sélectionner les renseignements exacts" + +msgid "Other" +msgstr "Autre" + +msgid "Other Value" +msgstr "Autre" + +msgid "Your data is the same" +msgstr "Votre répertoire et les renseignements du SAGE sont les mêmes" + +msgid "GEDS Audit" +msgstr "Vérification du SAGE" + +msgid "GEDS Audit" +msgstr "Vérification du SAGE" + +msgid "GEDS" +msgstr "SAGE" + +msgid "Directory" +msgstr "Annuiare" + +msgid "There are differences" +msgstr "Nous avons constaté des différences dans les renseignements suivants :" + +msgid "Directory Information" +msgstr "Renseignements du répertoire" + +msgid "Name" +msgstr "Nom" + +msgid "Job Title - English" +msgstr "Titre du poste - Anglais" + +msgid "Job Title - French" +msgstr "Titre du poste - Français" + +msgid "Office Phone" +msgstr "Téléphone" + +msgid "Mobile Phone" +msgstr "Cellulaire" + +msgid "Office Address" +msgstr "Adresse au travail" + +msgid "Department" +msgstr "Ministère" + +msgid "Department" +msgstr "Ministère" + +msgid "auditName" +msgstr "" + +msgid "titleEn" +msgstr "" + +msgid "titleFr" +msgstr "" + +msgid "auditPhone" +msgstr "" + +msgid "auditMobile" +msgstr "" + +msgid "auditAddress" +msgstr "" + +msgid "auditOrg" +msgstr "" + +msgid "Save" +msgstr "Sauvegarder les changements" diff --git a/src/components/profile/profileCard/GEDSAudit.js b/src/components/profile/profileCard/GEDSAudit.js new file mode 100644 index 0000000..875118b --- /dev/null +++ b/src/components/profile/profileCard/GEDSAudit.js @@ -0,0 +1,643 @@ +import React, { Component, useState } from 'react'; +import PropTypes from 'prop-types'; +import LocalizedComponent + from '@gctools-components/react-i18n-translation-webpack'; + +import { ApolloConsumer, Mutation } from 'react-apollo'; + +import { + Button, + Modal, + ModalBody, + ModalHeader, + Row, + Col, + Form, + FormGroup, + Label, + Alert +} from 'reactstrap'; + +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faCheck, faSpinner } from '@fortawesome/free-solid-svg-icons'; + +import { INTEGRATION, EDIT, prepareEditProfile } from '../../../gql/profile'; + +const AuditSelector = (props) => { + const { + field, + inputName, + gedsValue, + paasValue, + changeFunc, + } = props; + + const [otherSel, setOtherSel] = useState(false); + return ( +
+ +
+ {field} +
+ + {__('Please select data')} + +
+ +
+
+ +
+ { + // Don't show other option for address + } + {inputName !== 'auditAddress' && + +
+ +
+ {otherSel && +
+ + { + changeFunc({ + target: { + name: e.target.name, + value: e.target.value, + id: e.target.id, + }, + }); + }} + /> +
+ } +
+ } +
+
+ ); +}; + +class GEDSAudit extends Component { + constructor(props) { + super(props); + this.state = { + modal: false, + loading: false, + gName: '', + gTitleEn: '', + gTitleFr: '', + gOfficePhone: '', + gMobilePhone: '', + gStreetAddress: '', + gCity: '', + gProvince: '', + gPostalCode: '', + gCountry: '', + gOrganization: '', + }; + this.toggle = this.toggle.bind(this); + this.handleChange = this.handleChange.bind(this); + } + + toggle() { + this.setState({ + modal: !this.state.modal, + }); + } + + handleChange(e) { + const { name, value, id } = e.target; + + if (name === 'auditAddress') { + if (id === 'auditAddress-1') { + this.setState({ + streetAddress: this.state.gStreetAddress, + city: this.state.gCity, + province: this.state.gProvince, + country: this.state.gCountry, + postalCode: this.state.gPostalCode, + }); + } else if (id === 'auditAddress-2') { + this.setState({ + streetAddress: this.props.profile.address.streetAddress, + city: this.props.profile.address.city, + province: this.props.profile.address.province, + country: this.props.profile.address.country, + postalCode: this.props.profile.address.postalCode, + }); + } + } else { + this.setState({ + [name]: value, + }); + } + } + + render() { + const formatGAddress = ` + ${this.state.gStreetAddress} + ${this.state.gCity} + ${this.state.gProvince} + ${this.state.gCountry} + ${this.state.gPostalCode} + `; + const formatPAddress = (this.props.profile.address) && ` + ${this.props.profile.address.streetAddress} + ${this.props.profile.address.city} + ${this.props.profile.address.province} + ${this.props.profile.address.country} + ${this.props.profile.address.postalCode} + `; + const diffs = []; + if (this.state.gName !== this.props.profile.name) { + diffs.push('auditName'); + } + if (this.state.gTitleEn !== this.props.profile.titleEn) { + diffs.push('titleEn'); + } + if (this.state.gTitleFr !== this.props.profile.titleFr) { + diffs.push('titleFr'); + } + if (this.state.gOfficePhone !== this.props.profile.officePhone) { + diffs.push('auditPhone'); + } + if (this.state.gMobilePhone !== this.props.profile.mobilePhone) { + diffs.push('auditMobile'); + } + if (formatGAddress !== formatPAddress) { + diffs.push('auditAddress'); + } + // eslint-disable-next-line + if (this.state.gOrganization !== this.props.profile.team.organization.nameEn) { + diffs.push('auditOrg'); + } + const diffList = (diffs) ? + diffs.map(d => ( +
  • + + { + (d === 'auditName') && + {__('auditName')} + }{ + (d === 'titleEn') && + {__('titleEn')} + }{ + (d === 'titleFr') && + {__('titleFr')} + }{ + (d === 'auditPhone') && + {__('auditPhone')} + }{ + (d === 'auditMobile') && + {__('auditMobile')} + }{ + (d === 'auditAddress') && + {__('auditAddress')} + }{ + (d === 'auditOrg') && + {__('auditOrg')} + } + +
  • + )) : ( +
    + + {__('Your data is the same')} +
    + ); + return ( + + {client => ( +
    + + + + {__('GEDS Audit')} + + + + + + { + (diffs.length > 1) && +
    {__('There are differences')}
    + } +
      + {diffList} +
    +
    + { + console.log(error); + }} + context={ + { + headers: { + integrationsource: 'GEDS', + }, + } + } + onCompleted={() => { + this.setState({ + loading: false, + modal: false, + }); + }} + > + {(modifyProfile, { loading }) => ( +
    { + e.preventDefault(); + // updating the state + this.handleChange({ + target: { + name: 'update', + val: 'update', + id: 'update', + }, + }); + const { + auditName, titleEn, titleFr, + auditPhone, auditMobile, + streetAddress, city, province, + postalCode, country, + } = this.state; + modifyProfile(prepareEditProfile({ + gcID: this.props.profile.gcID, + name: auditName, + email: this.props.profile.email, + titleEn, + titleFr, + officePhone: auditPhone, + mobilePhone: auditMobile, + streetAddress, + city, + province, + postalCode, + country, + })); + }} + > +
    +
    + {__('Directory Information')} +
    +
    + { + // eslint-disable-next-line + (this.state.gName === this.props.profile.name) ? +
    + + {this.props.profile.name} +
    : + + } +
    +
    + { + /* + same string ? Display string : + Display inputs + */ + // eslint-disable-next-line + (this.state.gTitleEn === this.props.profile.titleEn) ? + + + + {this.props.profile.titleEn} + + : + + } +
    +
    + { + // eslint-disable-next-line + (this.state.gTitleFr === this.props.profile.titleFr) ? +
    + + + {this.props.profile.titleFr} + +
    : + + } +
    +
    + { + /** + * Email should be correct + */ + } +
    + + {this.props.profile.email} +
    +
    +
    + { + // eslint-disable-next-line + (this.state.gOfficePhone === this.props.profile.officePhone) ? +
    + + {this.props.profile.officePhone} +
    : + + } +
    +
    + { + // eslint-disable-next-line + (this.state.gMobilePhone === this.props.profile.mobilePhone) ? +
    + + {this.props.profile.mobilePhone} +
    : + + } +
    +
    + { + // eslint-disable-next-line + (formatGAddress === formatPAddress) ? +
    + + {formatPAddress} +
    : + + } +
    +
    +
    +
    + {__('Department')} +
    +
    + { + // eslint-disable-next-line + (this.state.gOrganization === this.props.profile.team.organization.nameEn) ? +
    + + { + (localizer.lang === 'en_CA') ? ( + // eslint-disable-next-line + this.props.profile.team.organization.nameEn + ) : ( + // eslint-disable-next-line + this.props.profile.team.organization.nameFr + ) + } +
    : + + } +
    +
    +
    + +
    +
    + )} +
    + +
    +
    +
    +
    + )} +
    + ); + } +} + +AuditSelector.defaultProps = { + field: '', + inputName: '', + gedsValue: '', + paasValue: '', + changeFunc: () => {}, +}; + +AuditSelector.propTypes = { + field: PropTypes.string, + inputName: PropTypes.string, + gedsValue: PropTypes.string, + paasValue: PropTypes.string, + changeFunc: PropTypes.func, +}; + +GEDSAudit.defaultProps = { + profile: undefined, +}; + +GEDSAudit.propTypes = { + profile: PropTypes.shape({ + gcID: PropTypes.string, + name: PropTypes.string, + email: PropTypes.string, + titleEn: PropTypes.string, + titleFr: PropTypes.string, + officePhone: PropTypes.string, + mobilePhone: PropTypes.string, + address: PropTypes.shape({ + streetAddress: PropTypes.string, + city: PropTypes.string, + province: PropTypes.string, + postalCode: PropTypes.string, + country: PropTypes.string, + }), + team: PropTypes.shape({ + organization: PropTypes.shape({ + id: PropTypes.string, + nameEn: PropTypes.string, + nameFr: PropTypes.string, + }), + }), + supervisor: PropTypes.shape({ + gcID: PropTypes.string, + name: PropTypes.string, + titleEn: PropTypes.string, + titleFr: PropTypes.string, + }), + }), +}; + +export default LocalizedComponent(GEDSAudit); diff --git a/src/components/profile/profileCard/GQLProfileCard.js b/src/components/profile/profileCard/GQLProfileCard.js index 933bcf6..b1e5572 100644 --- a/src/components/profile/profileCard/GQLProfileCard.js +++ b/src/components/profile/profileCard/GQLProfileCard.js @@ -11,9 +11,11 @@ import { Card, CardBody, CardTitle } from 'reactstrap'; import LocalizedProfileCardDisplay from './ProfileCardDisplay'; import LocalizedEditProfile from './EditProfile'; +import LocalizedGEDSAudit from './GEDSAudit'; import Loading from './Loading'; import GQLYourInfoApprovalStatus from './GQLYourInfoApprovalStatus'; +import isGovEmail from '../../../utils/isGovEmail'; import { GET } from '../../../gql/profile'; const mapStateToProps = ({ user }) => { @@ -62,6 +64,8 @@ export const GQLProfileCard = (props) => { if (loading) return ; if (error) return `Error!: ${error}`; const userInfo = (!data) ? '' : data.profiles[0]; + // Check for a valid GC email + const canAudit = isGovEmail(userInfo.email); return ( {userInfo ? ( @@ -74,10 +78,20 @@ export const GQLProfileCard = (props) => {

    {__('Profile')}

    {canEdit ? - : ''} +
    + { + canAudit && + + } + +
    : ''}
    {canEdit && ( { + domains.map((value) => { + if (email.includes(value)) { + govEmail = true; + } + return null; + }); + + return govEmail; +}; + +export default isGovEmail;