Skip to content

Commit

Permalink
Merge pull request #5 from shiva-beehyv/update-issuer-display-name
Browse files Browse the repository at this point in the history
Update issuer display name
  • Loading branch information
challabeehyv authored Feb 28, 2024
2 parents 7a27a85 + 1d992d8 commit a921d3d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion inji-web/src/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const router = createBrowserRouter([
element: <Home />,
},
{
path: "/issuers/:issuerId/:displayName",
path: "/issuers/:issuerId",
element: <Issuer/>,
},
{
Expand Down
3 changes: 2 additions & 1 deletion inji-web/src/pages/Home/IssuerList.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const getCardsData = (issuersList, navigate) => {
title: issuer.display[0].name,
icon: null,
onClick: () => {
navigate(`/issuers/${issuer.credential_issuer}/${issuer.display[0].name}`)
navigate(`/issuers/${issuer.credential_issuer}`, {state: {issuerDisplayName: issuer.display[0].name, clientId: issuer.client_id}})

},
clickable: true
}
Expand Down
23 changes: 14 additions & 9 deletions inji-web/src/pages/Home/SearchIssuers.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ function SearchIssuers({options, setFilteredIssuerList}) {
setFormatedOptions(response?.data?.response?.issuers.map((option) => {
return {
label: option?.display[0].name ,
value: option?.display[0].name
value: option?.credential_issuer,
clientId: option?.client_id
}
}));
}
Expand All @@ -83,22 +84,25 @@ function SearchIssuers({options, setFilteredIssuerList}) {

}, []);


function getReqValue (value) {
if (value) {
let reqValue = formatedOptions.filter(i => i.label === value);
navigate(`/issuers/${reqValue[0]?.value}`, {state: {issuerDisplayName: value, clientId: reqValue[0]?.clientId}} )
}
}

function setFilterOptions(event) {

let value = event?.target?.value;

console.log(event);
if (event?.type === 'click' ) {
value = event?.target?.outerText
if (value) {
navigate(`/issuers/${value}`)
}
getReqValue(value)
}
if (event.key === "Enter") {
value = event.target.value
if (value) {
navigate(`/issuers/${value}`)
}
getReqValue(value);
}

if (value) {
Expand All @@ -110,7 +114,8 @@ function SearchIssuers({options, setFilteredIssuerList}) {
setFormatedOptions(response?.data?.response?.issuers.map((option) => {
return {
label: option?.display[0].name ,
value: option?.display[0].name
value: option?.credential_issuer,
clientId: option?.client_id
}
}));
}
Expand Down
7 changes: 3 additions & 4 deletions inji-web/src/pages/IssuerPage/Header.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useEffect, useState} from 'react';
import {Grid, IconButton, Typography, Autocomplete, TextField} from "@mui/material";
import {Grid, IconButton, Typography, Autocomplete, TextField, CircularProgress} from "@mui/material";
import styled from "@emotion/styled";
import Box from "@mui/material/Box";
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
Expand Down Expand Up @@ -33,9 +33,8 @@ const IssuerTitle = styled(Typography)`
font-family: Inter;
`;

function Header({credentialsList, updateCredentialsList, defaultList}) {
function Header({issuerDisplayName, loading, credentialsList, updateCredentialsList, defaultList}) {
const navigate = useNavigate();
const { issuerId, displayName} = useParams();
const [defaultOptions, setDefaultOptions] = useState([]);

useEffect(() => {
Expand All @@ -51,7 +50,7 @@ function Header({credentialsList, updateCredentialsList, defaultList}) {
<BackArrow />
</IconButton>
<IssuerTitle>
{displayName}
{loading && !issuerDisplayName ? <CircularProgress/> : issuerDisplayName}
</IssuerTitle>
</Box>
</Grid>
Expand Down
24 changes: 16 additions & 8 deletions inji-web/src/pages/IssuerPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import Header from "./Header";
import CertificateList from "./CertificateList";
import _axios from 'axios';
import {getCredentialsSupportedUrl, getSearchIssuersUrl} from "../../utils/config";
import { useParams } from 'react-router-dom';
import { useParams, useLocation } from 'react-router-dom';
import LoadingScreen from '../../utils/LoadingScreen';

function Issuer() {
const { issuerId, displayName } = useParams();
const [credentialsList, setCredentialsList] = useState([]);
const [defaultList, setDefaultList] = useState([]);
const [issuerClientId, setIssuerClientId] = useState();

const location = useLocation();
const [issuerClientId, setIssuerClientId] = useState(location.state ? location.state['clientId'] : undefined);
const [issuerDisplayName, setIssuerDisplayName] = useState(location.state ? location.state['issuerDisplayName'] : undefined);
const [loading, setLoading] = useState(true);
const [errorMessage, setErrorMessage] = useState();

Expand All @@ -32,26 +35,31 @@ function Issuer() {
}, []);

useEffect(() => {
_axios.get(getSearchIssuersUrl(issuerId))
// make an api call only when the state is not available
if (issuerClientId && issuerDisplayName) return;
_axios.get(getSearchIssuersUrl(issuerDisplayName? issuerDisplayName : issuerId))
.then((response) => {
let issuers = response.data.response.issuers;
if (issuers.length !== 0) {
setIssuerClientId(issuers[0].client_id);
setIssuerDisplayName(issuers[0].display[0].name);
}
})
.catch((error) => {
console.error('Failed to search for the issuer', issuerId, error);
setErrorMessage('Error loading issuer client id');
setErrorMessage('Error loading issuer details!');
})
}, []);

// TODO: show a loader while loading and error message in case of any errors
return (
<PageTemplate>
<Header issuer={displayName} credentialsList={credentialsList} updateCredentialsList={setCredentialsList} defaultList={defaultList}/>
{loading ? <LoadingScreen /> :
<CertificateList credentialList={credentialsList} issuerId={issuerId} clientId={issuerClientId}/>
}
<Header issuerDisplayName={issuerDisplayName ? issuerDisplayName : issuerId} credentialsList={credentialsList}
loading={loading} updateCredentialsList={setCredentialsList} defaultList={defaultList}/>
{loading
? <LoadingScreen />
: <CertificateList credentialList={credentialsList} issuerId={issuerId} clientId={issuerClientId}/>
}
</PageTemplate>
);
}
Expand Down

0 comments on commit a921d3d

Please sign in to comment.