Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sc-11626: minor fixes & clean up #925

Merged
merged 5 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function AddNewVaspModal() {
closeModal();
},
onError: (error) => {
console.log('[mutate] error', error.response?.data.error);
// console.log('[mutate] error', error.response?.data.error);
toast({
title: error.response?.data?.error || error.message,
status: 'error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { UpdateCollaboratorMutation } from 'components/Collaborators/EditCo
export function useUpdateCollaborator(): UpdateCollaboratorMutation {
const mutation = useMutation(['update-Collaborator'], updateCollaboratorService, {
onError: (error: any) => {
console.log('update-Collaborator-error', error);
console.log('update-Collaborator-error-response', error?.response.data?.error);
console.log(error);
},
});
return {
Expand Down
2 changes: 1 addition & 1 deletion web/gds-user-ui/src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const useAuth = () => {
const currentTime = new Date().getTime() / 1000;

if (currentTime > +getExpiryTime) {
console.log('token expired');
// console.log('token expired');
clearCookies();
logoutUser();
return false;
Expand Down
14 changes: 11 additions & 3 deletions web/gds-user-ui/src/hooks/useQuery.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/* eslint-disable @typescript-eslint/no-shadow */
import React from 'react';
import { useLocation } from 'react-router-dom';
function useQuery() {
const { search } = useLocation();

return React.useMemo(() => new URLSearchParams(search), [search]);
function useQuery<QueryParams>() {
const { search } = useLocation();
return React.useMemo(() => {
const params = new URLSearchParams(search);
const result: any = {} as QueryParams;
params.forEach((value, key) => {
result[key] = value as unknown;
});
return result;
}, [search]);
}

export default useQuery;
2 changes: 1 addition & 1 deletion web/gds-user-ui/src/modules/auth/login/user.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const getAuth0User: any = createAsyncThunk(
try {
// then login with auth0
const getUserInfo: any = hasToken && (await auth0Hash());
console.log('[getUserInfo]', getUserInfo);
// console.log('[getUserInfo]', getUserInfo);

if (getUserInfo && getUserInfo?.idTokenPayload?.email_verified) {
const getUser = await logUserInBff();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ const Certificate: React.FC = () => {

async function handleNextStepClick() {
if (hasErroredField()) {
console.log('has errored field');
// i think we should not use alert here , but we need to find a way to display the error message
// eslint-disable-next-line no-alert
if (window.confirm('Some elements required for registration are missing; continue anyway?')) {
Expand Down Expand Up @@ -148,7 +147,6 @@ const Certificate: React.FC = () => {
values: methods.getValues()
});
if (isDirty) {
console.log('[isDirty at previous action]', getCurrentFormValue());
await postRegistrationValue({
...methods.getValues(),
state: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const createCollaborator = async (data: any): Promise<any> => {
const response: any = await axiosInstance.post(`/collaborators`, {
...data
});
console.log('response', response);
return response;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { APP_PATH, APP_STATUS_CODE } from 'utils/constants';
const SwitchOrganization: React.FC = () => {
const toast = useToast();
const { id } = useParams<{ id: string }>();
const query = useQuery();
const vaspName = query.get('vaspName');
const { vaspName } = useQuery<{ vaspName: string }>();
const dispatch = useDispatch();
const navigate = useNavigate();
const isCalled = useRef(false);
Expand Down Expand Up @@ -46,8 +45,6 @@ const SwitchOrganization: React.FC = () => {
duration: 9000,
isClosable: true
});
} finally {
setIsLoading(false);
}
};

Expand Down Expand Up @@ -75,7 +72,7 @@ const SwitchOrganization: React.FC = () => {
);
};

return <>{isLoading && <TransparentLoader title={renderTitle()} opacity="full" />}</>;
return <>{isLoading && !isError && <TransparentLoader title={renderTitle()} opacity="full" />}</>;
};

export default SwitchOrganization;
5 changes: 1 addition & 4 deletions web/gds-user-ui/src/modules/verify/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import useAuth from 'hooks/useAuth';
import { useNavigate } from 'react-router-dom';
import TransparentLoader from 'components/Loader/TransparentLoader';
const VerifyPage: React.FC = () => {
const query = useQuery();
const { vaspID, token, registered_directory } = useQuery();
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<any>();
const [result, setResult] = useState<any>(null);
const [isRedirected, setIsRedirected] = useState<boolean>(false);
const vaspID = query.get('vaspID');
const token = query.get('token');
const registered_directory = query.get('registered_directory');
const { isLoggedIn } = useAuth();
const navigate = useNavigate();

Expand Down
10 changes: 4 additions & 6 deletions web/gds-user-ui/src/utils/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@ export const getUserPermissionFromStore = () => {

export const hasPermission = (permission: TUserPermission | TUserPermission[]) => {
const userPermission = getUserPermissionFromStore();
console.log('userPermission', userPermission);
if (isArray(permission)) {
// all permission element should be in userPermission
return permission.every((p) => userPermission.includes(p));
}

return userPermission?.includes(permission);
};

export const canCreateOrganization = () => {
return hasPermission(USER_PERMISSION.CREATE_ORGANIZATIONS);
};

/** hasRole function
* @params role: string | string[]
Expand All @@ -34,7 +29,6 @@ export const canCreateOrganization = () => {
export const hasRole = (role: TUserRole | TUserRole[]) => {
const userRole = Store.getState()?.user?.user?.role;
if (isArray(role)) {
// all role element should be in userRole
return role.every((r) => userRole.includes(r));
}

Expand All @@ -45,3 +39,7 @@ export const hasRole = (role: TUserRole | TUserRole[]) => {
export const canInviteCollaborator = () => {
return hasPermission(USER_PERMISSION.UPDATE_COLLABORATOR);
};

export const canCreateOrganization = () => {
return hasPermission(USER_PERMISSION.CREATE_ORGANIZATIONS);
};