Skip to content

Commit

Permalink
Add publishing status and metadata of requests loading methods (#17)
Browse files Browse the repository at this point in the history
* update request entity, update verify request and vc group preview card

* req creds parser

* add rejecting request method

* add loading publishing status and metadata of requests, add appropriate components

* upd filter status for org group reqs, add progress for approved reqs

* refactored org-details context
  • Loading branch information
lukachi authored Jan 12, 2024
1 parent 752b9f8 commit 3b93749
Show file tree
Hide file tree
Showing 14 changed files with 453 additions and 201 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@mui/icons-material": "^5.14.19",
"@mui/material": "^5.14.20",
"@mui/x-date-pickers": "^6.18.7",
"@rarimo/rarime-connector": "^2.0.0-rc.1",
"@rarimo/rarime-connector": "^2.0.0-rc.3",
"@walletconnect/modal": "^2.6.2",
"i18next": "^22.4.3",
"lodash": "^4.17.21",
Expand Down
7 changes: 7 additions & 0 deletions src/api/modules/orgs/enums/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ export enum OrgGroupRequestIncludes {
Organization = 'Organization',
Group = 'Group',
}

export enum OrgGroupRequestPublishingStatuses {
Created = 'created',
Transacted = 'transacted',
Confirmed = 'confirmed',
Failed = 'failed',
}
50 changes: 46 additions & 4 deletions src/api/modules/orgs/helpers/org-groups-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
OrgGroupCreateRequest,
OrgGroupRequest,
OrgGroupRequestFilters,
OrgGroupRequestPublishing,
OrgGroupRequestQueryParams,
OrgGroupRequestStatuses,
OrgGroupVCsMetadata,
Expand All @@ -30,6 +31,7 @@ const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json',
credential_subject: {
birthday: '1704810332',
metadata_id: 'uuid-1234-5678-9101',
},
type: '',
expiration: '',
Expand Down Expand Up @@ -76,6 +78,7 @@ const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json',
credential_subject: {
birthday: '1704810332',
metadata_id: 'uuid-1234-5678-9101',
},
type: '',
expiration: '',
Expand Down Expand Up @@ -122,6 +125,7 @@ const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json',
credential_subject: {
birthday: '1704810332',
metadata_id: 'uuid-1234-5678-9101',
},
type: '',
expiration: '',
Expand Down Expand Up @@ -168,6 +172,7 @@ const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json',
credential_subject: {
birthday: '1704810332',
metadata_id: 'uuid-1234-5678-9101',
},
type: '',
expiration: '',
Expand All @@ -176,8 +181,8 @@ const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
},
],
status: {
name: 'submitted',
value: OrgGroupRequestStatuses.Submitted,
name: 'approved',
value: OrgGroupRequestStatuses.Approved,
},
created_at: '2021-08-12T14:00:00Z',
updated_at: '2021-08-12T13:00:00Z',
Expand Down Expand Up @@ -214,6 +219,7 @@ const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json',
credential_subject: {
birthday: '1704810332',
metadata_id: 'uuid-1234-5678-9101',
},
type: '',
expiration: '',
Expand Down Expand Up @@ -260,6 +266,7 @@ const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json',
credential_subject: {
birthday: '1704810332',
metadata_id: 'uuid-1234-5678-9101',
},
type: '',
expiration: '',
Expand Down Expand Up @@ -306,6 +313,7 @@ const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json',
credential_subject: {
birthday: '1704810332',
metadata_id: 'uuid-1234-5678-9101',
},
type: '',
expiration: '',
Expand Down Expand Up @@ -352,6 +360,7 @@ const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json',
credential_subject: {
birthday: '1704810332',
metadata_id: 'uuid-1234-5678-9101',
},
type: '',
expiration: '',
Expand Down Expand Up @@ -407,13 +416,13 @@ const fakeLoadRequestsAll = async (query?: OrgGroupRequestQueryParams) => {
query.filter?.[OrgGroupRequestFilters.UserDid]
) {
return (
req.status.value === query.filter[OrgGroupRequestFilters.Status] &&
query.filter[OrgGroupRequestFilters.Status].includes(req.status.value) &&
req.user_did === query.filter[OrgGroupRequestFilters.UserDid]
)
}

if (query?.filter?.[OrgGroupRequestFilters.Status]) {
return req.status.value === query.filter[OrgGroupRequestFilters.Status]
return query.filter[OrgGroupRequestFilters.Status].includes(req.status.value)
}

if (query?.filter?.[OrgGroupRequestFilters.UserDid]) {
Expand Down Expand Up @@ -587,6 +596,22 @@ export const rejectOrgGroupRequest = async ({
return data
}

export const getOrgGroupPublishingRequests = async ({
orgId,
groupId,
reqId,
}: {
orgId: string
groupId: string
reqId: string
}): Promise<OrgGroupRequestPublishing[]> => {
const { data } = await api.get<OrgGroupRequestPublishing[]>(
`/v1/orgs/${orgId}/groups/${groupId}/requests/${reqId}/publishing`,
)

return data
}

export const loadAndParseRequestCredentialSchemas = async (
request: OrgGroupRequest,
): Promise<
Expand Down Expand Up @@ -614,3 +639,20 @@ export const loadAndParseRequestCredentialSchemas = async (
}),
)
}

export const loadOrgGroupReqMetadataById = async (
metadataId: string,
): Promise<OrgGroupVCsMetadata> => {
const { data } = await api.get<OrgGroupVCsMetadata>(`/v1/orgs/metadata/${metadataId}`)

return data

// TODO: remove once backend is ready
// return {
// title: 'title',
// subtitle: 'subtitle',
// appearance: {
// background: '#ffffff',
// },
// }
}
88 changes: 61 additions & 27 deletions src/api/modules/orgs/helpers/orgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,72 @@ import {
type OrgVerificationCode,
} from '@/api'

export const DUMMY_ORG: Organization = {
id: '3a798290-caf1-496a-a7e5-4db32551b13d',
type: 'organizations',
did: 'did:iden3:readonly:tUDjWxnVJNi7t3FudukqrUcNwF5KVGoWgim5pp2jV',
domain: 'https://organization-domain.com',
metadata: {
logoUrl: 'https://organization-domain.com/logo.png',
name: 'Organization Name',
description: 'Organization Description',
},
status: {
name: 'unverified',
value: OrgsStatuses.Unverified,
export const DUMMY_ORGS: Organization[] = [
{
id: '3a798290-caf1-496a-a7e5-4db32551b13d',
type: 'organizations',
did: 'did:iden3:readonly:tUDjWxnVJNi7t3FudukqrUcNwF5KVGoWgim5pp2jV',
domain: 'https://organization-domain.com',
metadata: {
logoUrl: 'https://organization-domain.com/logo.png',
name: 'Organization Name',
description: 'Organization Description',
},
status: {
name: 'unverified',
value: OrgsStatuses.Unverified,
},
verification_code: '6A4GSfUNKwM9hHuZVg4aUw==',
issued_claims_count: '0',
members_count: '1',
created_at: '2021-08-12T12:00:00Z',
updated_at: '2021-08-12T13:00:00Z',
owner: {
id: '81c32ef4-2878-4f86-9277-4c3c82913b87',
type: 'users',
did: 'did:iden3:readonly:tTNsD7orsf2f5So34v3RMpektAZerLmHhaLZYddhZ',
role: {
name: 'undefined',
value: 0,
},
org_id: '3a798290-caf1-496a-a7e5-4db32551b13d',
created_at: '2021-08-12T12:00:00Z',
updated_at: '2021-08-12T13:00:00Z',
},
},
verification_code: '6A4GSfUNKwM9hHuZVg4aUw==',
issued_claims_count: '0',
members_count: '1',
created_at: '2021-08-12T12:00:00Z',
updated_at: '2021-08-12T13:00:00Z',
owner: {
id: '81c32ef4-2878-4f86-9277-4c3c82913b87',
type: 'users',
did: 'did:iden3:tUxw1kwfVZMVa4A4ji3mLRYwiy9aVqzGG1kmY46tZ',
role: {
name: 'undefined',
value: 0,
{
id: '3a798290-caf1-496a-a7e5-4db32551b13d',
type: 'organizations',
did: 'did:iden3:readonly:tUDjWxnVJNi7t3FudukqrUcNwF5KVGoWgim5pp2jV',
domain: 'https://organization-domain.com',
metadata: {
logoUrl: 'https://organization-domain.com/logo.png',
name: 'Organization Name',
description: 'Organization Description',
},
status: {
name: 'verified',
value: OrgsStatuses.Verified,
},
org_id: '3a798290-caf1-496a-a7e5-4db32551b13d',
verification_code: '6A4GSfUNKwM9hHuZVg4aUw==',
issued_claims_count: '0',
members_count: '1',
created_at: '2021-08-12T12:00:00Z',
updated_at: '2021-08-12T13:00:00Z',
owner: {
id: '81c32ef4-2878-4f86-9277-4c3c82913b87',
type: 'users',
did: 'did:iden3:readonly:tTNsD7orsf2f5So34v3RMpektAZerLmHhaLZYddhZ',
role: {
name: 'undefined',
value: 0,
},
org_id: '3a798290-caf1-496a-a7e5-4db32551b13d',
created_at: '2021-08-12T12:00:00Z',
updated_at: '2021-08-12T13:00:00Z',
},
},
}
]

export const loadOrgs = async (query: OrgsRequestQueryParams) => {
const { data } = await api.get<Organization[]>('/v1/orgs', {
Expand Down
16 changes: 14 additions & 2 deletions src/api/modules/orgs/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import {
OrgGroup,
OrgGroupRequestFilters,
OrgGroupRequestIncludes,
OrgGroupRequestPublishingStatuses,
OrgGroupRequestStatuses,
} from '@/api'

export type CredentialRequest = {
credential_schema: string
credential_subject: Record<string, string>
credential_subject: Record<string, string> & { metadata_id: string }
type: string
expiration: string
mt_proof: boolean
Expand Down Expand Up @@ -57,7 +58,7 @@ export type OrgGroupCreatedRequest = {

export type OrgGroupRequestFiltersMap = {
[OrgGroupRequestFilters.UserDid]: string
[OrgGroupRequestFilters.Status]: OrgGroupRequestStatuses
[OrgGroupRequestFilters.Status]: OrgGroupRequestStatuses[]
}

export type OrgGroupRequestQueryParams = {
Expand Down Expand Up @@ -155,3 +156,14 @@ export type VCSchema = {
}
}
}

export type OrgGroupRequestPublishing = {
id: string
type: 'claims'
claim_id: string
request_id: string
created_at: string
updated_at: string
schema_url: string
status: OrgGroupRequestPublishingStatuses
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Stack, StackProps, Typography } from '@mui/material'
import { Stack, StackProps } from '@mui/material'
import { useCallback, useState } from 'react'

import { loadAndParseRequestCredentialSchemas, OrgGroupRequest, rejectOrgGroupRequest } from '@/api'
import { OrgGroupRequest, rejectOrgGroupRequest } from '@/api'
import { ErrorHandler } from '@/helpers'
import { useLoading } from '@/hooks'
import { UiBasicModal, UiButton } from '@/ui'

import CredentialsMetadataBuilder from './CredentialsMetadataBuilder'
Expand All @@ -23,15 +22,6 @@ export default function ApproveRequestForm({
}: Props) {
const [isModalShown, setIsModalShown] = useState(false)

const { data: vcFields } = useLoading(
[],
() => loadAndParseRequestCredentialSchemas(orgGroupRequest),
{
loadOnMount: true,
loadArgs: [orgGroupRequest],
},
)

const rejectRequest = useCallback(async () => {
try {
await rejectOrgGroupRequest({
Expand All @@ -48,21 +38,10 @@ export default function ApproveRequestForm({

return (
<Stack {...rest} flex={1} p={5}>
<Stack>
{vcFields.map((el, idx) => (
<Stack key={idx}>
<Typography>{el.key}</Typography>
<Typography>{el.value}</Typography>
</Stack>
))}
</Stack>

<Stack mt='auto' spacing={2}>
<UiButton onClick={() => setIsModalShown(true)}>Create Credential</UiButton>
<UiButton onClick={rejectRequest} color='error'>
Reject
</UiButton>
</Stack>
<UiButton onClick={() => setIsModalShown(true)}>Create Credential</UiButton>
<UiButton onClick={rejectRequest} color='error'>
Reject
</UiButton>

<UiBasicModal open={isModalShown} onClose={() => setIsModalShown(false)}>
<CredentialsMetadataBuilder
Expand Down
Loading

0 comments on commit 3b93749

Please sign in to comment.