From fedc8271cc13b22622105a81e772f66cb7220d7b Mon Sep 17 00:00:00 2001 From: Atul Patil <67235572+0xatulpatil@users.noreply.github.com> Date: Sat, 9 Sep 2023 20:46:16 +0530 Subject: [PATCH 1/3] Comment out crypto section from navbar (#552) * Comment out crypto section from navbar * remove commented code --- src/constants/AppConstants.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/constants/AppConstants.js b/src/constants/AppConstants.js index 653498e8..4d0c9351 100644 --- a/src/constants/AppConstants.js +++ b/src/constants/AppConstants.js @@ -35,11 +35,6 @@ const NAVMENU = [ name: 'Members', path: 'https://members.realdevsquad.com/', }, - { - id: '5', - name: 'Crypto', - path: 'https://crypto.realdevsquad.com/', - }, { id: '6', name: 'Status', From 492cd93d8a76b46879def426f9fb8be867364f33 Mon Sep 17 00:00:00 2001 From: vinayak-trivedi <90315175+vinayak-trivedi@users.noreply.github.com> Date: Sun, 10 Sep 2023 17:35:20 +0530 Subject: [PATCH 2/3] fix for failing tests in member profile page (#554) --- jest.config.js | 1 + src/store/keyboard/context.js | 6 +- .../components/member-profile/index.test.js | 63 ++++++++++++++----- 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/jest.config.js b/jest.config.js index aad1cc9d..cc4721ae 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,5 +8,6 @@ module.exports = { '^@store(.*)$': '/src/store$1', '^@helper-functions(.*)$': '/src/helper-functions$1', '^@constants(.*)$': '/src/constants$1', + '^@custom-hooks(.*)$': '/src/custom-hooks$1', }, }; diff --git a/src/store/keyboard/context.js b/src/store/keyboard/context.js index 63361209..22aa4626 100644 --- a/src/store/keyboard/context.js +++ b/src/store/keyboard/context.js @@ -2,16 +2,16 @@ import { createContext, useContext, useState } from 'react'; const KeyboardContext = createContext(); -export const KeyboardProvider = ({ children }) => { +export const KeyboardProvider = ({ children, initialValue }) => { const [isOptionKeyPressed, setIsOptionKeyPressed] = useState(false); - const initialValue = { + const value = { isOptionKeyPressed, setIsOptionKeyPressed, }; return ( - + {children} ); diff --git a/src/test/unit/components/member-profile/index.test.js b/src/test/unit/components/member-profile/index.test.js index 5c53a91a..d3244232 100644 --- a/src/test/unit/components/member-profile/index.test.js +++ b/src/test/unit/components/member-profile/index.test.js @@ -2,6 +2,7 @@ import { render, screen } from '@testing-library/react'; import Profile from '@components/member-profile'; import { TaskContextProvider } from '@store/tasks/tasks-context'; import { UserContextProvider } from '@store/user/user-context'; +import { KeyboardProvider } from '@store/keyboard/context'; const notaMember = { roles: { @@ -20,24 +21,49 @@ const initialUserContext = { isSuperUser: true, }; +jest.mock('next/router', () => { + return { + useRouter: jest.fn().mockReturnValue({ + query: { + dev: true, + }, + }), + }; +}); + describe('Members Profile', () => { it('Should render member status properly', () => { render( - - - - - + + + + + + + ); let memberStatus = screen.getByText('User is not a Member'); expect(memberStatus).toBeInTheDocument(); + render( - - - - - + + + + + + + ); memberStatus = screen.getByText('User is a Member'); @@ -46,11 +72,18 @@ describe('Members Profile', () => { it('Should render the info icon correctly', () => { render( - - - - - + + + + + + + ); const icon = screen.getByAltText('info icon'); From 5e8e05381658f9d0809b1637ceb8e360ca3fd534 Mon Sep 17 00:00:00 2001 From: GAURAV SINHA Date: Sun, 17 Sep 2023 04:25:24 +0530 Subject: [PATCH 3/3] added reason text box in archiving process (#557) * added reason text box in archiving process * refactor * removed unwanted comments * removed unwanted comments * removed unwanted comments * Delete .env.development * revert deleted .env dev * remove unchanged file .env.dev * revert to original changes --- src/components/member-profile/index.js | 2 +- src/components/member-role-update/index.js | 96 ++++++++++++++++--- .../member-role-update.module.scss | 23 +++++ src/helper-functions/action-handlers.js | 4 +- src/styles/constants/_colors.scss | 2 + .../components/member-profile/index.test.js | 81 ++++++++++++++++ 6 files changed, 191 insertions(+), 17 deletions(-) diff --git a/src/components/member-profile/index.js b/src/components/member-profile/index.js index 6048d9ce..1dd99ccc 100644 --- a/src/components/member-profile/index.js +++ b/src/components/member-profile/index.js @@ -377,7 +377,7 @@ const Profile = (props) => { )} {isSuperUser && ( -
+
{showMemberRoleUpdateModal && }
)} diff --git a/src/components/member-role-update/index.js b/src/components/member-role-update/index.js index 1b9ae427..00c33a98 100644 --- a/src/components/member-role-update/index.js +++ b/src/components/member-role-update/index.js @@ -6,10 +6,14 @@ import Spinner from '@components/UI/spinner'; import MemberTagAssign from '@components/member-tag-assign'; import { BASE_API_URL } from '@constants/AppConstants'; import useFetch from '@custom-hooks/useFetch'; +import { useRouter } from 'next/router'; import classNames from './member-role-update.module.scss'; import { memberRoleUpdate } from '../../helper-functions/action-handlers'; const MemberRoleUpdate = () => { + const { query } = useRouter() || { query: { dev: false } }; + const { dev } = query; + const isDev = Boolean(dev); // convert string to boolean const { showMemberRoleUpdateModal, setShowMemberRoleUpdateModal, @@ -18,7 +22,8 @@ const MemberRoleUpdate = () => { const [isUpdating, setIsUpdating] = useState(false); const [updateStatus, setUpdateStatus] = useState(''); - + const [validateError, setvalidateError] = useState(''); + const [reasonText, setReasonText] = useState(''); const { data: userData } = useFetch( `${BASE_API_URL}/users/${selectedMember}` ); @@ -51,22 +56,28 @@ const MemberRoleUpdate = () => { } }; - const archiveUnArchiveTheMember = async (id) => { - let archiveRole = null; + const archiveUnArchiveTheMember = async (id, reason) => { setIsUpdating(true); + let body = {}; if (archived) { - archiveRole = false; + body = { + archived: false, + }; + } else if (!reason && !archived) { + body = { + archived: true, + }; } else { - archiveRole = true; + body = { + archived: true, + reason, + }; } - const role = { - archived: archiveRole, - }; try { - const { status } = await memberRoleUpdate(id, role); + const { status } = await memberRoleUpdate(id, body); setIsUpdating(false); if (status === 200) { - setUpdateStatus('user archived!'); + setUpdateStatus(archived ? 'User unarchived!' : 'User archived!'); } } catch (error) { setUpdateStatus('Some error occured, please contact admin'); @@ -75,6 +86,7 @@ const MemberRoleUpdate = () => { const memberRoleUpdateButton = ( ); - + const handleValidReason = (id, reason) => { + const isEmptyReason = !reason.length; + const isReasonEmptyOrWhitespace = /^\s*$/.test(reason); // check for empty or multiple whitespaces + const isMoreThan99Words = reason.split(' ').length > 99; + const isMoreThan50Characters = reason.length <= 25; + switch (!archived) { + case isEmptyReason: + setvalidateError('Reason cannot be empty!'); + break; + case isReasonEmptyOrWhitespace: + setvalidateError('Reason cannot be empty or multiple whitespaces!'); + break; + case isMoreThan99Words: + setvalidateError('Reason cannot be more than 99 words!'); + break; + case isMoreThan50Characters: + setvalidateError('Reason should have more than 25 characters!'); + break; + default: + setvalidateError(''); + } + const isValid = + !isEmptyReason && + !isReasonEmptyOrWhitespace && + !isMoreThan99Words && + !isMoreThan50Characters; + if (isValid || archived) { + archiveUnArchiveTheMember(id, reason); + } + }; const memeberArchiveUnArchiveButton = ( ); + const archiveReasonTextBox = ( +
+

{validateError}

+