-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from bcgov/feature/bceid
add display of business profile on access approval page
- Loading branch information
Showing
17 changed files
with
1,122 additions
and
229 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { EnforcementPoint } from '../../authz/enforcement'; | ||
|
||
import { lookupCredentialReferenceByServiceAccess } from '../../services/keystone'; | ||
|
||
import { ConfigService } from '../../services/bceid/config.service'; | ||
import { BCeIDService } from '../../services/bceid/bceid.service'; | ||
|
||
const typeBusinessProfile = ` | ||
type BusinessProfile { | ||
user: UserDetails | ||
institution: InstitutionDetails | ||
} | ||
`; | ||
|
||
const typeUserDetails = ` | ||
type UserDetails { | ||
guid: String | ||
displayName: String | ||
firstname: String | ||
surname: String | ||
email: String | ||
isSuspended: Boolean | ||
isManagerDisabled: Boolean | ||
} | ||
`; | ||
|
||
const typeInstitutionDetails = ` | ||
type InstitutionDetails { | ||
guid: String | ||
type: String | ||
legalName: String | ||
address: AddressDetails | ||
isSuspended: Boolean | ||
businessTypeOther: String | ||
} | ||
`; | ||
|
||
const typeAddressDetails = ` | ||
type AddressDetails { | ||
addressLine1: String | ||
addressLine2: String | ||
city: String | ||
postal: String | ||
province: String | ||
country: String | ||
} | ||
`; | ||
|
||
module.exports = { | ||
extensions: [ | ||
(keystone: any) => { | ||
keystone.extendGraphQLSchema({ | ||
types: [ | ||
{ type: typeBusinessProfile }, | ||
{ type: typeUserDetails }, | ||
{ type: typeInstitutionDetails }, | ||
{ type: typeAddressDetails }, | ||
], | ||
queries: [ | ||
{ | ||
schema: 'BusinessProfile(serviceAccessId: ID!): BusinessProfile', | ||
resolver: async ( | ||
item: any, | ||
args: any, | ||
context: any, | ||
info: any, | ||
{ query, access }: any | ||
) => { | ||
const serviceAccess = await lookupCredentialReferenceByServiceAccess( | ||
context, | ||
args.serviceAccessId | ||
); | ||
|
||
const fullUsername = serviceAccess.application?.owner.username; | ||
|
||
if (fullUsername != null && fullUsername.endsWith('@bceid')) { | ||
const username = fullUsername.substring( | ||
0, | ||
fullUsername.length - 6 | ||
); | ||
|
||
const bc = new BCeIDService(new ConfigService()); | ||
return await bc.getAccountDetails(username); | ||
} else { | ||
return {}; | ||
} | ||
}, | ||
access: EnforcementPoint, | ||
}, | ||
], | ||
mutations: [], | ||
}); | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/nextapp/components/business-profile/business-profile-loading.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as React from 'react'; | ||
import { Box, SkeletonText } from '@chakra-ui/react'; | ||
|
||
const BusinessProfileLoading: React.FC = () => { | ||
return ( | ||
<Box p={0}> | ||
<SkeletonText noOfLines={1} spacing={2} skeletonHeight="4" /> | ||
<SkeletonText noOfLines={8} spacing={2} skeletonHeight="2" /> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default BusinessProfileLoading; |
90 changes: 90 additions & 0 deletions
90
src/nextapp/components/business-profile/business-profile.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import * as React from 'react'; | ||
import { Heading, Text } from '@chakra-ui/react'; | ||
import { gql } from 'graphql-request'; | ||
import { useApi } from '@/shared/services/api'; | ||
|
||
import Loading from './business-profile-loading'; | ||
|
||
interface BusinessProfileProps { | ||
serviceAccessId: string; | ||
} | ||
|
||
const BusinessProfileComponent: React.FC<BusinessProfileProps> = ({ | ||
serviceAccessId, | ||
}) => { | ||
const { data } = useApi( | ||
['BusinessProfile', serviceAccessId], | ||
{ | ||
query, | ||
variables: { serviceAccessId }, | ||
}, | ||
{ suspense: false } | ||
); | ||
|
||
if (!data) { | ||
return <Loading />; | ||
} | ||
if (data.BusinessProfile.institution == null) { | ||
return <></>; | ||
} | ||
const institution = data.BusinessProfile.institution; | ||
const contact = data.BusinessProfile.user; | ||
return ( | ||
<> | ||
<Heading size="sm" mb={2}> | ||
Business Profile | ||
</Heading> | ||
<Heading size="xs" mt={3} mb={1}> | ||
{institution.businessTypeOther} | ||
</Heading> | ||
<Text mb={0}>{institution.legalName}</Text> | ||
<Text mb={0}>{institution.address.addressLine1}</Text> | ||
<Text mb={0}>{institution.address.addressLine2}</Text> | ||
<Text mb={0}> | ||
{institution.address.city} {institution.address.province} | ||
</Text> | ||
<Text mb={0}>{institution.address.postal}</Text> | ||
<Text mb={0}>{institution.address.country}</Text> | ||
|
||
<Heading size="xs" mt={3} mb={1}> | ||
Contact | ||
</Heading> | ||
<Text mb={0}>{contact.displayName}</Text> | ||
<Text mb={0}> | ||
{contact.surname}, {contact.firstname} | ||
</Text> | ||
<Text mb={0}>{contact.email}</Text> | ||
</> | ||
); | ||
}; | ||
|
||
export default BusinessProfileComponent; | ||
|
||
const query = gql` | ||
query GetBusinessProfile($serviceAccessId: ID!) { | ||
BusinessProfile(serviceAccessId: $serviceAccessId) { | ||
user { | ||
displayName | ||
firstname | ||
surname | ||
isSuspended | ||
isManagerDisabled | ||
} | ||
institution { | ||
type | ||
legalName | ||
address { | ||
addressLine1 | ||
addressLine2 | ||
city | ||
postal | ||
province | ||
country | ||
} | ||
isSuspended | ||
businessTypeOther | ||
} | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './business-profile'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.