Skip to content

Commit

Permalink
Fixed the error while loading the origanization data (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanhaiya04 authored Nov 28, 2023
1 parent d8e6a7d commit e9f28c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/UserUpdate/UserUpdate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('Testing User Update', () => {
const props = {
key: '123',
id: '1',
toggleStateValue: jest.fn(),
};

const formData = {
Expand Down
13 changes: 9 additions & 4 deletions src/components/UserUpdate/UserUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import Loader from 'components/Loader/Loader';

interface InterfaceUserUpdateProps {
id: string;
toggleStateValue: () => void;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
id,
toggleStateValue,
}): JSX.Element => {
const location = useLocation<InterfaceUserUpdateProps>();
const currentUrl = location.state?.id || localStorage.getItem('id') || id;
Expand Down Expand Up @@ -104,10 +106,13 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
applangcode: '',
file: '',
});
localStorage.setItem('FirstName', firstName);
localStorage.setItem('LastName', lastName);
localStorage.setItem('Email', email);
localStorage.setItem('UserImage', file);
toast.success('Successful updated');
setTimeout(() => {
window.location.reload();
}, 500);

toggleStateValue();
}
} catch (error: any) {
/* istanbul ignore next */
Expand All @@ -117,7 +122,7 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({

/* istanbul ignore next */
const cancelUpdate = (): void => {
window.location.reload();
toggleStateValue();
};

return (
Expand Down
10 changes: 9 additions & 1 deletion src/screens/MemberDetail/MemberDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ const MemberDetail: React.FC<MemberDetailProps> = ({ id }): JSX.Element => {
data: userData,
loading: loading,
error: error,
refetch: refetch,
} = useQuery(USER_DETAILS, {
variables: { id: currentUrl }, // For testing we are sending the id as a prop
});

/* istanbul ignore next */
const toggleStateValue = (): void => {
if (state === 1) setState(2);
else setState(1);
refetch();
};

if (loading) {
return <Loader />;
}
Expand Down Expand Up @@ -286,7 +294,7 @@ const MemberDetail: React.FC<MemberDetailProps> = ({ id }): JSX.Element => {
</section>
</div>
) : (
<UserUpdate id={currentUrl} />
<UserUpdate id={currentUrl} toggleStateValue={toggleStateValue} />
)}
</Col>
</Row>
Expand Down

0 comments on commit e9f28c7

Please sign in to comment.