diff --git a/examples/react-graphql/client/src/components/Credential/Credential.tsx b/examples/react-graphql/client/src/components/Credential/Credential.tsx index 5f13d364f..849cd3678 100644 --- a/examples/react-graphql/client/src/components/Credential/Credential.tsx +++ b/examples/react-graphql/client/src/components/Credential/Credential.tsx @@ -27,7 +27,7 @@ const Component: React.FC = ({ onClick, detailMode, fields, jwt, iss, sub {iss.shortId} - {sub.shortId} + {sub?.shortId} diff --git a/examples/react-graphql/client/src/components/MessageItem/MessageItem.tsx b/examples/react-graphql/client/src/components/MessageItem/MessageItem.tsx index 462b86dec..a875ca2e5 100644 --- a/examples/react-graphql/client/src/components/MessageItem/MessageItem.tsx +++ b/examples/react-graphql/client/src/components/MessageItem/MessageItem.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { Box, Heading, Text, Icon, Avatar } from 'rimble-ui' +import { Box, Heading, Text, Icon, Avatar, Button } from 'rimble-ui' import * as Types from '../../types' import './MessageItem.css' @@ -10,6 +10,11 @@ interface Props { */ activity?: string + /** + * The type of message + */ + type: string + /** * The issuer of this message item */ @@ -18,22 +23,48 @@ interface Props { /** * The subject */ + showRequest: () => void receiver: Types.Identity attachments: any renderAttachments?: (attachmentItem: any, itemIndex: number) => React.ReactNode } -const Component: React.FC = ({ attachments, renderAttachments, sender, receiver }) => { +const Component: React.FC = ({ + attachments, + renderAttachments, + sender, + receiver, + type, + showRequest, +}) => { return ( - - {sender.shortId} sent a message to {receiver ? receiver.shortId : 'You'} - + {type == 'sdr' ? ( + + {sender.shortId} requested information from you + + ) : type == 'w3c.vc' ? ( + + {sender.did === receiver?.did ? 'You' : sender.shortId} issued a credential to + {receiver ? receiver.shortId : 'yourself'} + + ) : ( + + You shared credentials with {receiver ? receiver.shortId : 'yourself'} + + )} + {type == 'sdr' && ( + + + + )} {attachments && attachments.length > 0 && renderAttachments && ( {attachments.map((item: any, itemIndex: number) => { diff --git a/examples/react-graphql/client/src/components/Request/Request.tsx b/examples/react-graphql/client/src/components/Request/Request.tsx new file mode 100644 index 000000000..e237ed5c7 --- /dev/null +++ b/examples/react-graphql/client/src/components/Request/Request.tsx @@ -0,0 +1,17 @@ +import React from 'react' +import { Box, Heading } from 'rimble-ui' +import * as Types from '../../types' + +interface Props { + sender: Types.Identity + receiver: Types.Identity + sdr: any +} + +const Component: React.FC = ({ sdr }) => { + console.log(sdr) + + return Show contents from query. Results are logged in console.. +} + +export default Component diff --git a/examples/react-graphql/client/src/gql/mutations.ts b/examples/react-graphql/client/src/gql/mutations.ts new file mode 100644 index 000000000..d7d71dea8 --- /dev/null +++ b/examples/react-graphql/client/src/gql/mutations.ts @@ -0,0 +1,32 @@ +import { gql } from 'apollo-boost' + +export const deleteIdentity = gql` + mutation deleteIdentity($type: String, $did: String) { + deleteIdentity(type: $type, did: $did) + } +` + +export const actionSignVc = gql` + mutation actionSignVc($did: String!, $data: VerifiableCredentialInput!) { + actionSignVc(did: $did, data: $data) + } +` + +export const actionSignSDR = gql` + mutation signSDR($did: String!, $data: SDRInput!) { + actionSignSDR(did: $did, data: $data) + } +` +export const actionSendJwt = gql` + mutation actionSendJwt($from: String!, $to: String!, $jwt: String!) { + actionSendJwt(from: $from, to: $to, jwt: $jwt) + } +` + +export const createIdentity = gql` + mutation createIdentity($type: String) { + createIdentity(type: $type) { + did + } + } +` diff --git a/examples/react-graphql/client/src/gql/queries.ts b/examples/react-graphql/client/src/gql/queries.ts new file mode 100644 index 000000000..f7b4f0064 --- /dev/null +++ b/examples/react-graphql/client/src/gql/queries.ts @@ -0,0 +1,177 @@ +import { gql } from 'apollo-boost' + +export const credential = gql` + query credential($id: ID!) { + credential(id: $id) { + hash + rowId + iss { + did + shortId + } + sub { + did + shortId + } + jwt + nbf + iat + fields { + isObj + type + value + } + } + } +` + +export const identity = gql` + query identity($did: ID!) { + identity(did: $did) { + did + type + shortId + } + } +` + +export const managedIdentities = gql` + query managedIdentities { + managedIdentityTypes + managedIdentities { + did + type + shortId + } + } +` + +export const queryMessage = gql` + query message($id: ID!, $defaultDid: ID!) { + message(id: $id) { + id + threadId + type + timestamp + sdr(sub: $defaultDid) { + iss { + did { + did + shortId + } + url + } + claimType + reason + essential + vc { + hash + rowId + iss { + did + shortId + profileImage + } + sub { + did + shortId + profileImage + } + jwt + fields { + type + value + isObj + } + } + } + sender { + did + shortId + profileImage + } + } + } +` + +export const allMessages = gql` + query allMessages($activeDid: ID!) { + identity(did: $activeDid) { + did + messagesAll { + id + raw + data + threadId + type + timestamp + sender { + did + shortId + profileImage + } + sdr(sub: $activeDid) { + iss { + did { + did + shortId + } + url + } + claimType + reason + essential + vc { + hash + rowId + iss { + did + shortId + profileImage + } + sub { + did + shortId + profileImage + } + jwt + fields { + type + value + isObj + } + } + } + receiver { + did + shortId + profileImage + } + vc { + rowId + hash + iss { + did + shortId + profileImage + } + sub { + did + shortId + profileImage + } + fields { + type + value + isObj + } + } + metaData { + type + id + data + } + } + } + } +` diff --git a/examples/react-graphql/client/src/layout/Layout.tsx b/examples/react-graphql/client/src/layout/Layout.tsx index c3469c0b3..065a3caab 100644 --- a/examples/react-graphql/client/src/layout/Layout.tsx +++ b/examples/react-graphql/client/src/layout/Layout.tsx @@ -13,9 +13,11 @@ import Issue from '../views/Issue/Issue' import Sidebar from './Sidebar' import SidePanel from './SidePanel' import NavigationLeft from './NavigationLeft' + import Credential from '../components/Credential/Credential' +import RequestDetail from '../components/Request/Request' -import * as queries from '../queries' +import * as queries from '../gql/queries' interface DashboardProps {} @@ -23,6 +25,10 @@ const renderCredentialQuery = (props: any) => { return } +const renderSDRQuery = (props: any) => { + return +} + const Dashboard: React.FC = () => { return ( @@ -76,6 +82,14 @@ const Dashboard: React.FC = () => { renderQuery={renderCredentialQuery} > + + + diff --git a/examples/react-graphql/client/src/layout/SidePanel.tsx b/examples/react-graphql/client/src/layout/SidePanel.tsx index e29856795..5be5e5c97 100644 --- a/examples/react-graphql/client/src/layout/SidePanel.tsx +++ b/examples/react-graphql/client/src/layout/SidePanel.tsx @@ -1,7 +1,8 @@ -import React, { useEffect } from 'react' +import React, { useEffect, useContext } from 'react' import { Box, Heading, Icon } from 'rimble-ui' import { useHistory, useParams } from 'react-router-dom' import { useQuery, useLazyQuery } from '@apollo/react-hooks' +import { AppContext } from '../context/AppProvider' interface Props { title: string @@ -11,11 +12,12 @@ interface Props { } const Component: React.FC = ({ title, closeUrl, query, children, renderQuery }) => { - let history = useHistory() + const [appState] = useContext(AppContext) + const history = useHistory() const { id } = useParams() const [getQuery, { loading, data }] = useLazyQuery(query, { - variables: { id }, + variables: { id, defaultDid: appState.defaultDid }, }) useEffect(() => { diff --git a/examples/react-graphql/client/src/views/Activity/Activity.tsx b/examples/react-graphql/client/src/views/Activity/Activity.tsx index 2bc734acd..9912a0dc0 100644 --- a/examples/react-graphql/client/src/views/Activity/Activity.tsx +++ b/examples/react-graphql/client/src/views/Activity/Activity.tsx @@ -3,7 +3,7 @@ import { Flex } from 'rimble-ui' import MessageItem from '../../components/MessageItem/MessageItem' import Page from '../../layout/Page' import Credential from '../../components/Credential/Credential' -import * as queries from '../../queries' +import * as queries from '../../gql/queries' import { AppContext } from '../../context/AppProvider' import { useQuery } from '@apollo/react-hooks' import { useHistory, useRouteMatch } from 'react-router-dom' @@ -21,15 +21,15 @@ const Activity: React.FC = () => { variables: { activeDid: appState.defaultDid }, }) - console.log(messagesData) - return ( {messagesData?.identity?.messagesAll?.map((msg: any) => ( history.push(`${url}/sdr/${msg.id}`)} attachments={msg.vc} renderAttachments={(attachment: any) => (