Skip to content

Commit

Permalink
Merge pull request #386 from credebl/fix-prod-issues
Browse files Browse the repository at this point in the history
fix: production issues
  • Loading branch information
nishad-ayanworks authored Oct 27, 2023
2 parents 4e8088e + 22f582d commit db172a6
Show file tree
Hide file tree
Showing 6 changed files with 589 additions and 523 deletions.
87 changes: 55 additions & 32 deletions src/components/Issuance/IssuedCrdentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { dateConversion } from '../../utils/DateConversion';
import { getIssuedCredentials } from '../../api/issuance';
import { pathRoutes } from '../../config/pathRoutes';
import { getFromLocalStorage } from '../../api/Auth';
import { getOrgDetails } from '../../config/ecosystem'

interface IssuedCredential {
metadata: { [x: string]: { schemaId: string } };
Expand All @@ -34,11 +35,15 @@ const CredentialList = () => {
const [error, setError] = useState<string | null>(null);
const [searchText, setSearchText] = useState('');
const [issuedCredList, setIssuedCredList] = useState<TableData[]>([]);
const [walletCreated, setWalletCreated] = useState(false)

const getIssuedCredDefs = async () => {
setLoading(true)
const orgData = await getOrgDetails()
const isWalletCreated = Boolean(orgData.orgDid)
setWalletCreated(isWalletCreated)
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
if (orgId) {
if (orgId && isWalletCreated) {
const response = await getIssuedCredentials();

const { data } = response as AxiosResponse;
Expand Down Expand Up @@ -154,17 +159,20 @@ const CredentialList = () => {
className="p-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
<div className="flex items-center justify-end mb-4">

<RoleViewButton
buttonTitle='Issue'
feature={Features.ISSUENCE}
svgComponent={
<svg className="pr-2" xmlns="http://www.w3.org/2000/svg" width="30" height="25" fill="none" viewBox="0 0 25 18">
<path fill="#fff" d="M.702 10.655a.703.703 0 1 0-.001-1.406.703.703 0 0 0 .001 1.406Z" />
<path fill="#fff" d="m24.494 5.965-5.8-5.8a.562.562 0 0 0-.795 0l-2.06 2.06H8.884c-1.602 0-3.128.73-4.137 1.966H3.652V3.35a.562.562 0 0 0-.562-.562H.562a.562.562 0 0 0 0 1.123h1.966v7.866H.562a.562.562 0 0 0 0 1.124H3.09c.31 0 .562-.252.562-.562v-1.404h1.096A5.358 5.358 0 0 0 8.885 12.9h.653l4.01 4.01a.56.56 0 0 0 .795 0l10.15-10.15a.562.562 0 0 0 0-.795ZM5.478 10.04a.562.562 0 0 0-.455-.231h-1.37V5.315h1.37c.18 0 .349-.086.455-.23a4.23 4.23 0 0 1 3.407-1.736h5.83L11.38 6.682a5.675 5.675 0 0 1-1.238-1.243.562.562 0 0 0-.908.66 6.74 6.74 0 0 0 4.429 2.71.633.633 0 0 1-.197 1.25 8 8 0 0 1-4.14-1.974.562.562 0 0 0-.755.833c.1.091.204.18.308.266l-1.132 1.131a.562.562 0 0 0 0 .795l.637.636a4.235 4.235 0 0 1-2.907-1.705Zm8.468 5.677L8.94 10.713l.86-.86a9.16 9.16 0 0 0 3.492 1.316 1.759 1.759 0 0 0 2.008-1.46 1.758 1.758 0 0 0-1.461-2.01 5.69 5.69 0 0 1-1.454-.432l5.911-5.91 5.006 5.005-9.356 9.356Z" />
</svg>
}
onClickEvent={schemeSelection}
/>
{
walletCreated &&
<RoleViewButton
buttonTitle='Issue'
feature={Features.ISSUENCE}
svgComponent={
<svg className="pr-2" xmlns="http://www.w3.org/2000/svg" width="30" height="25" fill="none" viewBox="0 0 25 18">
<path fill="#fff" d="M.702 10.655a.703.703 0 1 0-.001-1.406.703.703 0 0 0 .001 1.406Z" />
<path fill="#fff" d="m24.494 5.965-5.8-5.8a.562.562 0 0 0-.795 0l-2.06 2.06H8.884c-1.602 0-3.128.73-4.137 1.966H3.652V3.35a.562.562 0 0 0-.562-.562H.562a.562.562 0 0 0 0 1.123h1.966v7.866H.562a.562.562 0 0 0 0 1.124H3.09c.31 0 .562-.252.562-.562v-1.404h1.096A5.358 5.358 0 0 0 8.885 12.9h.653l4.01 4.01a.56.56 0 0 0 .795 0l10.15-10.15a.562.562 0 0 0 0-.795ZM5.478 10.04a.562.562 0 0 0-.455-.231h-1.37V5.315h1.37c.18 0 .349-.086.455-.23a4.23 4.23 0 0 1 3.407-1.736h5.83L11.38 6.682a5.675 5.675 0 0 1-1.238-1.243.562.562 0 0 0-.908.66 6.74 6.74 0 0 0 4.429 2.71.633.633 0 0 1-.197 1.25 8 8 0 0 1-4.14-1.974.562.562 0 0 0-.755.833c.1.091.204.18.308.266l-1.132 1.131a.562.562 0 0 0 0 .795l.637.636a4.235 4.235 0 0 1-2.907-1.705Zm8.468 5.677L8.94 10.713l.86-.86a9.16 9.16 0 0 0 3.492 1.316 1.759 1.759 0 0 0 2.008-1.46 1.758 1.758 0 0 0-1.461-2.01 5.69 5.69 0 0 1-1.454-.432l5.911-5.91 5.006 5.005-9.356 9.356Z" />
</svg>
}
onClickEvent={schemeSelection}
/>
}

</div>
<AlertComponent
Expand All @@ -174,28 +182,43 @@ const CredentialList = () => {
setError(null)
}}
/>
{loading ? (
<div className="flex items-center justify-center mb-4">
<CustomSpinner />
</div>
) : issuedCredList && issuedCredList.length > 0 ? (
<div
className="Flex-wrap"
style={{ display: 'flex', flexDirection: 'column' }}
>
<div className="">
{issuedCredList && issuedCredList.length > 0 &&
<DataTable header={header} data={issuedCredList} loading={loading}></DataTable>
{
!walletCreated && !loading ?
<div className="flex justify-center items-center">
<EmptyListMessage
message={'No Wallet Details Found'}
description={'The owner is required to create a wallet'}
buttonContent={''}
/>
</div>
:
<div>
{
loading ? (
<div className="flex items-center justify-center mb-4">
<CustomSpinner />
</div>
) : issuedCredList && issuedCredList.length > 0 ? (
<div
className="Flex-wrap"
style={{ display: 'flex', flexDirection: 'column' }}
>
<div className="">
{issuedCredList && issuedCredList.length > 0 &&
<DataTable header={header} data={issuedCredList} loading={loading}></DataTable>
}
</div>
</div>
) : (
<div>
<span className="dark:text-white block text-center p-4 m-8">
There isn't any data available.
</span>
</div>
)
}
</div>
</div>
) : (
<div>
<span className="dark:text-white block text-center p-4 m-8">
There isn't any data available.
</span>
</div>
)}
}
</div>
</div>
</div>
Expand Down
72 changes: 40 additions & 32 deletions src/components/Profile/EditUserProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useEffect, useRef, useState} from "react";
import type { UserProfile } from "./interfaces";
import { setToLocalStorage, updateUserProfile } from "../../api/Auth";
import { IMG_MAX_HEIGHT, IMG_MAX_WIDTH, imageSizeAccepted, storageKeys} from "../../config/CommonConstant";
import { getFromLocalStorage, setToLocalStorage, updateUserProfile } from "../../api/Auth";
import { IMG_MAX_HEIGHT, IMG_MAX_WIDTH, imageSizeAccepted, storageKeys } from "../../config/CommonConstant";
import type { AxiosResponse } from "axios";
import CustomAvatar from '../Avatar'
import { calculateSize, dataURItoBlob } from "../../utils/CompressImage";
import { Alert,Button} from "flowbite-react";
import { Alert, Button } from "flowbite-react";
import { Form, Formik, FormikHelpers } from "formik";
import * as yup from "yup"

Expand All @@ -27,7 +27,7 @@ interface EditUserProfileProps {
updateProfile: (updatedProfile: UserProfile) => void;
}

const EditUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile}: EditUserProfileProps) => {
const EditUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile }: EditUserProfileProps) => {

const [loading, setLoading] = useState<boolean>(false)
const [isImageEmpty, setIsImageEmpty] = useState(true)
Expand All @@ -53,7 +53,7 @@ const EditUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile}: E
if (firstNameInputRef.current) {
firstNameInputRef.current.focus();
}
}, []);
}, []);


useEffect(() => {
Expand Down Expand Up @@ -165,11 +165,19 @@ const EditUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile}: E
}
const resUpdateUserDetails = await updateUserProfile(userData)

const existingUser = await getFromLocalStorage(storageKeys.USER_PROFILE)

const { data } = resUpdateUserDetails as AxiosResponse
setToLocalStorage(storageKeys.USER_PROFILE, userData)

const updatedUser = JSON.parse(existingUser)

const updatedUserData = {
...updatedUser,
...userData
}

updateProfile(userData);
await setToLocalStorage(storageKeys.USER_PROFILE, userData);
await setToLocalStorage(storageKeys.USER_PROFILE, updatedUserData);
window.location.reload();
setLoading(false)
}
Expand Down Expand Up @@ -218,7 +226,7 @@ const EditUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile}: E
values: Values,
{ resetForm }: FormikHelpers<Values>
) => {
await updateUserDetails(values);
await updateUserDetails(values);
toggleEditProfile();
}}

Expand Down Expand Up @@ -340,28 +348,28 @@ const EditUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile}: E
</div>
</div>
<div className="mb-16">
<div className='float-right p-2'>
<Button
type="submit"
isProcessing={loading}
fill="none"
className='text-base font-medium text-center text-white bg-primary-700 rounded-lg hover:!bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800 px-3'
>
<svg className="pr-2" xmlns="http://www.w3.org/2000/svg" width="24" height="22" fill="none" viewBox="0 0 18 18">
<div className='float-right p-2'>
<Button
type="submit"
isProcessing={loading}
fill="none"
className='text-base font-medium text-center text-white bg-primary-700 rounded-lg hover:!bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800 px-3'
>
<svg className="pr-2" xmlns="http://www.w3.org/2000/svg" width="24" height="22" fill="none" viewBox="0 0 18 18">
<path stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 1v12l-4-2-4 2V1h8ZM3 17h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2H3a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2Z" />
</svg>
</svg>
Save
</Button>
</div>
<div className='float-right p-3'>
<Button
type="reset"
color='bg-primary-800'
className='bg-secondary-700 ring-primary-700 bg-white-700 hover:bg-secondary-700 ring-2 text-black font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-3 mr-2 ml-auto dark:text-white'
onClick= {() => toggleEditProfile()}
style={{ height: '2.5rem', width: '7rem', minWidth: '4rem' }}
>
<svg className="h-6 w-6 text-primary-700 mr-1"
</Button>
</div>
<div className='float-right p-3'>
<Button
type="reset"
color='bg-primary-800'
className='bg-secondary-700 ring-primary-700 bg-white-700 hover:bg-secondary-700 ring-2 text-black font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-3 mr-2 ml-auto dark:text-secondary-700 dark:hover:text-primary-700'
onClick={() => toggleEditProfile()}
style={{ height: '2.5rem', width: '7rem', minWidth: '4rem' }}
>
<svg className="h-6 w-6 text-primary-700 mr-1"
width="24"
height="24"
viewBox="0 0 24 24"
Expand All @@ -374,10 +382,10 @@ const EditUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile}: E
<line x1="18" y1="6" x2="6" y2="18" />
<line x1="6" y1="6" x2="18" y2="18" />
</svg>
Cancel
</Button>
</div>

Cancel
</Button>
</div>
</div>
</Form>
)}
Expand Down
16 changes: 12 additions & 4 deletions src/components/Profile/UserProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import { useEffect, useState } from 'react';
import type { AxiosResponse } from 'axios';
import { apiStatusCodes, storageKeys } from '../../config/CommonConstant';
import { getFromLocalStorage, getUserProfile } from '../../api/Auth';
import { getFromLocalStorage, getUserProfile, setToLocalStorage } from '../../api/Auth';
import BreadCrumbs from '../BreadCrumbs';
import type { UserProfile } from './interfaces';
import DisplayUserProfile from './DisplayUserProfile';
import React from 'react';
import AddPasskey from './AddPasskey';
import EditUserProfile from './EditUserProfile';

interface IUserProfile {
firstName: string
lastName: string
email: string
profileImg: string
}

const UserProfile = () => {
const [isEditProfileOpen, setIsEditProfileOpen] = useState(false);
const [prePopulatedUserProfile, setPrePopulatedUserProfile] = useState<UserProfile | null>(null);
const [prePopulatedUserProfile, setPrePopulatedUserProfile] = useState<IUserProfile | null>(null);

const fetchUserProfile = async () => {
try {
Expand All @@ -21,6 +28,8 @@ const UserProfile = () => {

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
setPrePopulatedUserProfile(data?.data);
await setToLocalStorage(storageKeys.USER_PROFILE, data?.data)
await setToLocalStorage(storageKeys.USER_EMAIL, data?.data?.email)
}
} catch (error) {
}
Expand All @@ -37,7 +46,7 @@ const UserProfile = () => {
}, []);


const updatePrePopulatedUserProfile = (updatedProfile: UserProfile) => {
const updatePrePopulatedUserProfile = (updatedProfile: IUserProfile) => {
setPrePopulatedUserProfile(updatedProfile);
};

Expand Down Expand Up @@ -107,7 +116,6 @@ const UserProfile = () => {

</div>
</div>

</div>
);
};
Expand Down
Loading

0 comments on commit db172a6

Please sign in to comment.