Skip to content
Open
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
6 changes: 3 additions & 3 deletions src/actions/userManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
};

const buildBackendPayload = (userDetails, action) => {
console.log('Building backend payload with:', { userDetails, action });

Check warning on line 206 in src/actions/userManagement.js

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
switch (action){
case UserStatusOperations.ACTIVATE:
return {
Expand Down Expand Up @@ -365,15 +365,15 @@
* fetching all user profiles basic info
* Added `source` parameter to identify the calling component.
*/
export const getUserProfileBasicInfo = ({ userId, source }) => {
export const getUserProfileBasicInfo = ({ userId, source } = {}) => {
// API request to fetch basic user profile information
let userProfileBasicInfoPromise;
if (userId)
userProfileBasicInfoPromise = axios.get(`${ENDPOINTS.USER_PROFILE_BASIC_INFO}?userId=${userId}`);
userProfileBasicInfoPromise = axios.get(ENDPOINTS.USER_PROFILE(userId));
else if (source)
userProfileBasicInfoPromise = axios.get(ENDPOINTS.USER_PROFILE_BASIC_INFO(source));
else
userProfileBasicInfoPromise = axios.get(ENDPOINTS.USER_PROFILE_BASIC_INFO);
userProfileBasicInfoPromise = axios.get(ENDPOINTS.USER_PROFILES);

return async dispatch => {
// Dispatch action indicating the start of the fetch process
Expand Down
120 changes: 78 additions & 42 deletions src/components/BMDashboard/Team/CreateNewTeam/CreateNewTeam.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { boxStyle } from '../../../../styles';
import styles from './CreateNewTeam.module.css';
import { getUserProfileBasicInfo } from '../../../../actions/userManagement';
import { toast } from 'react-toastify';

const initialFormState = {
teamName: '',
Expand All @@ -23,8 +24,8 @@
const [selectedMember, setSelectedMember] = useState('');
const [selectedTask, setSelectedTask] = useState('');
const [members, setMembers] = useState([]);
// const [tasks, setTasks] = useState([]);
const [tasks] = useState([]);
const [tasks, setTasks] = useState([]);
//const [tasks] = useState([]);

Check warning on line 28 in src/components/BMDashboard/Team/CreateNewTeam/CreateNewTeam.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this commented out code.

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ2ir5I1T-ov-1vK8nsi&open=AZ2ir5I1T-ov-1vK8nsi&pullRequest=4813
const [assignedMembers, setAssignedMembers] = useState([]);
const [assignedTasks, setAssignedTasks] = useState([]);
const [errorMessage, setErrorMessage] = useState('');
Expand All @@ -36,13 +37,26 @@
additionalInformation: false,
});

const user = useSelector(state => state.auth.user);

Check warning on line 40 in src/components/BMDashboard/Team/CreateNewTeam/CreateNewTeam.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the declaration of the unused 'user' variable.

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ2ir5I2T-ov-1vK8nsj&open=AZ2ir5I2T-ov-1vK8nsj&pullRequest=4813

Check warning on line 40 in src/components/BMDashboard/Team/CreateNewTeam/CreateNewTeam.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this useless assignment to variable "user".

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ2ir5I2T-ov-1vK8nsk&open=AZ2ir5I2T-ov-1vK8nsk&pullRequest=4813

const dummyTasks = ['Task 1', 'Task 2', 'Task 3', 'Task 4', 'Task 5'];

const [loadingMembers, setLoadingMembers] = useState(false);
useEffect(() => {
dispatch(getUserProfileBasicInfo());
setLoadingMembers(true);
const result = dispatch(getUserProfileBasicInfo());
// If the action returns a promise (thunk), handle it
if (result && typeof result.then === 'function') {
result.finally(() => setLoadingMembers(false));
} else {
setLoadingMembers(false);
}
tasks.length === 0 && setTasks(dummyTasks);
}, [dispatch]);

useEffect(() => {
setMembers(userProfilesBasicInfo);
}, []);
setMembers(userProfilesBasicInfo || []);
}, [userProfilesBasicInfo]);

const validationObj = {
additionalInformation: Joi.string()
Expand All @@ -63,7 +77,7 @@
errorMessages[detail.path[0]] = detail.message;
});
}
if (assignedMembers.length === 0) {
if ((!data.teamMembers || data.teamMembers.length === 0) && assignedMembers.length === 0) {
errorMessages.assignedMembers = 'You must assign at least one member.';
} else {
// Clear the assignedMembers error if members have been added
Expand Down Expand Up @@ -118,6 +132,8 @@
// eslint-disable-next-line no-console
console.log('Form Submitted:', updatedFormData);

toast.success('Team created successfully!');

setSelectedMember('');
setAssignedMembers([]);
setSelectedTask('');
Expand All @@ -138,6 +154,7 @@
setAssignedTasks([]);
setFormData(initialFormState);
setErrors({});
setErrorMessage('');
setTouchedFields({
teamName: false,
assignedMembers: false,
Expand Down Expand Up @@ -202,6 +219,7 @@
if (selectedTask && !assignedTasks.includes(selectedTask)) {
setAssignedTasks([...assignedTasks, selectedTask]);
setSelectedTask('');
setTaskErrorMessage('');
}
};

Expand All @@ -218,7 +236,7 @@
</header>

<Form className={`${styles.addTeamForm} container`} onSubmit={handleSubmit}>
<FormGroup>
<FormGroup style={{ marginTop: '1.5rem', marginBottom: 0 }}>
<Label for="teamName">
Team Name<span className={`${styles.fieldRequired}`}>*</span>
</Label>
Expand All @@ -237,26 +255,36 @@
</Label>
)}
</FormGroup>
<FormGroup>
<FormGroup style={{ marginTop: '1.5rem', marginBottom: 0 }}>
<Label for="member-select">
Add Members<span className={`${styles.fieldRequired}`}>*</span>
</Label>
<div className={`${styles.selectContainer}`}>
<Input
id="members-select"
type="select"
value={selectedMember}
onChange={handleMemberChange}
className={`${styles.memberDropdown}`}
>
<option value="">Select a Member</option>
{members.map((user, index) => (
// eslint-disable-next-line react/no-array-index-key
<option key={index} value={user.id}>
{user.firstName} {user.lastName}
</option>
))}
</Input>
{loadingMembers ? (
<div style={{ padding: '0.5rem' }}>Loading members...</div>
) : (
<Input
id="members-select"
type="select"
value={selectedMember}
onChange={handleMemberChange}
className={`${styles.memberDropdown}`}
>
{Array.isArray(members) && members.length > 0 ? (
<>
<option value="">Select a Member</option>
{members.map((user, index) => (
// eslint-disable-next-line react/no-array-index-key
<option key={index} value={user.id}>
{user.firstName} {user.lastName}
</option>
))}
</>
) : (
<option value="">No members available</option>
)}
</Input>
)}
<Button
onClick={handleAddMember}
// disabled={!selectedMember || isMemberAssigned}
Expand All @@ -278,7 +306,9 @@
</FormGroup>
<div>
{assignedMembers.length > 0 && (
<p className={styles.label}>Currently Assigned Members:</p>
<label htmlFor="assigned-members" className={styles.label}>
Currently Assigned Members:
</label>
)}
<div className={`${styles.badgeContainer}`}>
{assignedMembers.map((member, index) => {
Expand All @@ -302,17 +332,23 @@
})}
</div>
</div>
<FormGroup>
<FormGroup style={{ marginTop: '1.5rem', marginBottom: 0 }}>
<Label for="task-select">Add Main Tasks</Label>
<div className={`${styles.selectContainer}`}>
<Input id="tasks-select" type="select" value={selectedTask} onChange={handleTaskChange}>
<option value="">Select a Task</option>
{tasks.map((task, index) => (
// eslint-disable-next-line react/no-array-index-key
<option key={index} value={task.id}>
{task}
</option>
))}
{Array.isArray(tasks) && tasks.length > 0 ? (
<>
<option value="">Select a Task</option>
{tasks.map((task, index) => (
// eslint-disable-next-line react/no-array-index-key
<option key={index} value={task.id}>
{task}
</option>
))}
</>
) : (
<option value="">No tasks available</option>
)}
</Input>
<Button
onClick={handleAddTask}
Expand All @@ -322,7 +358,7 @@
Add
</Button>
</div>
{errorMessage && (
{taskErrorMessage && (
<Label className={`${styles.teamFormError}`} style={{ color: 'red' }}>
{taskErrorMessage}
</Label>
Expand All @@ -331,7 +367,9 @@

<div>
{assignedTasks.length > 0 && (
<label htmlFor="assigned-tasks">Currently Assigned Tasks:</label>
<label htmlFor="assigned-tasks" className={styles.label}>
Currently Assigned Tasks:
</label>
)}
<div className={`${styles.badgeContainer}`}>
{assignedTasks.map((task, index) => {
Expand All @@ -342,11 +380,9 @@
<span
role="button"
tabIndex={0}
onClick={() => handleRemoveMember(member)}
onKeyDown={e =>
(e.key === 'Enter' || e.key === ' ') && handleRemoveMember(member)
}
aria-label={`Remove member ${member}`}
onClick={() => handleRemoveTask(task)}
onKeyDown={e => (e.key === 'Enter' || e.key === ' ') && handleRemoveTask(task)}
aria-label={`Remove task ${task}`}
>
X
</span>
Expand All @@ -355,7 +391,7 @@
})}
</div>
</div>
<FormGroup>
<FormGroup style={{ marginTop: '1.5rem', marginBottom: 0 }}>
<Label for="additional-information-label">Additional Information</Label>
<Input
type="textarea"
Expand All @@ -373,10 +409,10 @@
)}
</FormGroup>
<div className={`${styles.addTeamButtons}`}>
<Button id="cancel-button" outline style={boxStyle} onClick={handleCancelClick}>
<Button id="cancel-button" style={boxStyle} onClick={handleCancelClick}>
Cancel
</Button>
<Button id="submit-button" style={boxStyle}>
<Button id="submit-button" style={boxStyle} onClick={handleSubmit}>
Submit
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@
border-color: #e53935;
}

.teamFormError {
.addTeamForm .teamFormError {
font-weight: 500;
font-size: 11px !important;
color: red;
color: red !important;
display: flex;
justify-content: flex-start;
padding-left: 0;
}

.fieldRequired{
color: red;
.addTeamForm .fieldRequired{
color: red !important;
}

.addTeamContainer{
Expand Down
Loading