Skip to content

Commit

Permalink
Merge pull request #1547 from HDRUK/release
Browse files Browse the repository at this point in the history
GAT-1887: Testing Release from release/UAT to preprod
  • Loading branch information
reubensamuel authored Feb 13, 2023
2 parents 1db027d + 508c632 commit b22e3ce
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions src/pages/dashboard/Team/AddEditTeamsPage.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useCallback, useState, useEffect } from 'react';
import { useCallback, useState } from 'react';
import { Row, Col, Form, Dropdown, DropdownButton } from 'react-bootstrap';
import { Typeahead } from 'react-bootstrap-typeahead';
import { AsyncTypeahead } from 'react-bootstrap-typeahead';
import axios from 'axios';
import * as Yup from 'yup';
import { useFormik } from 'formik';
import NotificationManager from 'react-notifications';
import { Box } from 'hdruk-react-core';

import { LayoutContent, Switch } from 'components';
import { publishersService } from 'services';
import { publishersService, usersService } from 'services';

import '../Dashboard.scss';
import Loading from '../../commonComponents/Loading';
Expand All @@ -29,8 +29,9 @@ const AddEditTeamsPage = ({
// state
const [questionBank, setQuestionBank] = useState(questionBankEnabled);
const [dataUseWidget, setDataUseWidget] = useState(dataUseWidgetEnabled);
const [isLoading, setLoading] = useState(false);
const [combinedTeamManagers, setCombinedTeamManagers] = useState({});
const [isLoading, setIsLoading] = useState(false);
const [isAsyncLoading, setIsAsyncLoading] = useState(false);
const [combinedTeamManagers, setCombinedTeamManagers] = useState([]);

const memberOfSelect = ['ALLIANCE', 'HUB', 'OTHER', 'NCS'];

Expand All @@ -45,21 +46,13 @@ const AddEditTeamsPage = ({
formik.setFieldValue('memberOf', key);
};

const getTeamManagerData = () => {
axios
.get(`${baseURL}/api/v1/users`)
.then(res => {
const userArray = [];
res.data.data.map(user => {
userArray.push({ id: user.id, name: user.name });
});
setCombinedTeamManagers(userArray);
})
.catch(err => {
console.error(err.message);
alert('Failed to fetch users');
});
const handleSearch = async searchValue => {
setIsAsyncLoading(true);
const users = await usersService.searchUsers(encodeURI(searchValue));
setCombinedTeamManagers(users.data.data);
setIsAsyncLoading(false);
};

// Pass the useFormik() hook initial form values and a submit function that will
// be called when the form is submitted
const formik = useFormik({
Expand All @@ -78,7 +71,7 @@ const AddEditTeamsPage = ({
}),

onSubmit: async values => {
setLoading(true);
setIsLoading(true);

let publisherId = editViewID;
let alertText;
Expand Down Expand Up @@ -111,7 +104,7 @@ const AddEditTeamsPage = ({
},
});

setLoading(false);
setIsLoading(false);
setAlertFunction(alertText);

cancelAddEdit();
Expand All @@ -126,11 +119,6 @@ const AddEditTeamsPage = ({
setDataUseWidget(checked);
}, []);

// lifecycle hook
useEffect(() => {
getTeamManagerData();
}, []);

if (isLoading) {
return (
<LayoutContent>
Expand Down Expand Up @@ -262,9 +250,13 @@ const AddEditTeamsPage = ({
<Row>
<Col sm={12} lg={12}>
<Form.Group className='pb-2'>
<Typeahead
<AsyncTypeahead
id='teamManagers'
isLoading={isAsyncLoading}
filterBy={() => true}
minLength={3}
name='teamManagers'
placeholder='Enter 3 characters to search'
labelKey={
editTeamsView
? combinedTeamManagers => `${combinedTeamManagers}`
Expand All @@ -288,6 +280,7 @@ const AddEditTeamsPage = ({
formik.values.teamManagers = tempSelected;
formik.setFieldTouched('teamManagers', true);
}}
onSearch={handleSearch}
/>
{formik.touched.teamManagers && formik.errors.teamManagers ? (
<div className='errorMessages'>{formik.errors.teamManagers}</div>
Expand Down

0 comments on commit b22e3ce

Please sign in to comment.