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
7 changes: 4 additions & 3 deletions src/components/Chat/ChatList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { addTestsLabel } from '../../lib/helper.js';
import ChatListItem from './ChatListItem.jsx';
import { AUDITOR, CUSTOMER } from '../../redux/actions/types.js';
import { searchAuditor } from '../../redux/actions/auditorAction.js';
import { searchCustomers } from '../../redux/actions/customerAction.js';
import { searchAuditorV2 } from '../../redux/actions/auditorAction.js';
import { searchCustomersV2 } from '../../redux/actions/customerAction.js';

const ChatList = ({ chatList, chatListIsOpen, setChatListIsOpen }) => {
const dispatch = useDispatch();
Expand All @@ -31,8 +32,8 @@ const ChatList = ({ chatList, chatListIsOpen, setChatListIsOpen }) => {
useEffect(() => {
startTransition(() => {
if (search.trim()) {
dispatch(searchAuditor({ search, perPage: 20 }, false));
dispatch(searchCustomers({ search, perPage: 20 }));
dispatch(searchAuditorV2({ search, perPage: 20 }, false));
dispatch(searchCustomersV2({ search, perPage: 20 }));
}
});
}, [search]);
Expand Down
49 changes: 35 additions & 14 deletions src/components/forms/filter/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,29 @@ const Filter = ({ target, submit, initial }) => {
</LocalizationProvider>
</Box>
</Box>
{target === 'auditor' && (
<Box sx={[{ '& .slider-info': { display: 'none' } }]}>
<Field
name="rating"
value={values.rating}
label="Rating"
component={SliderRange}
sx={priceSlider(target)}
valueLabelDisplay="auto"
min={0}
max={100}
onChange={(e, newValue) => {
const value = Array.isArray(newValue)
? newValue
: [newValue, newValue];
setFieldValue('rating.from', value[0]);
setFieldValue('rating.to', value[1]);
}}
/>
</Box>
)}
<Box sx={sortWrapper}>
<FormGroup>
{/* <FormGroup>
<FormControlLabel
control={
<Checkbox
Expand All @@ -183,7 +204,7 @@ const Filter = ({ target, submit, initial }) => {
}
label="Ready to wait"
/>
</FormGroup>
</FormGroup> */}
</Box>
{target === 'auditor' && (
<Box sx={sortWrapper}>
Expand All @@ -203,12 +224,12 @@ const Filter = ({ target, submit, initial }) => {
}}
onClick={e => {
if (values.sort_by === 'price') {
if (values.sort === '1') {
setFieldValue('sort', '-1');
setUpToDown({ ...upToDown, sort: '-1' });
if (values.sort === 'price_asc') {
setFieldValue('sort', 'price_desc');
setUpToDown({ ...upToDown, sort: 'price_desc' });
} else {
setFieldValue('sort', '1');
setUpToDown({ ...upToDown, sort: '1' });
setFieldValue('sort', 'price_asc');
setUpToDown({ ...upToDown, sort: 'price_asc' });
}
} else {
setFieldValue('sort_by', 'price');
Expand Down Expand Up @@ -257,7 +278,7 @@ const Filter = ({ target, submit, initial }) => {
Price
</Typography>
{upToDown.sort_by === 'price' &&
(upToDown.sort === '1' ? (
(upToDown.sort === 'price_asc' ? (
<ArrowUpwardIcon
sx={{
color: 'black',
Expand Down Expand Up @@ -290,12 +311,12 @@ const Filter = ({ target, submit, initial }) => {
}}
onClick={e => {
if (values.sort_by === 'rating') {
if (values.sort === '1') {
setFieldValue('sort', '-1');
setUpToDown({ ...upToDown, sort: '-1' });
if (values.sort === 'rating_asc') {
setFieldValue('sort', 'rating_desc');
setUpToDown({ ...upToDown, sort: 'rating_desc' });
} else {
setFieldValue('sort', '1');
setUpToDown({ ...upToDown, sort: '1' });
setFieldValue('sort', 'rating_asc');
setUpToDown({ ...upToDown, sort: 'rating_asc' });
}
} else {
setFieldValue('sort_by', 'rating');
Expand Down Expand Up @@ -344,7 +365,7 @@ const Filter = ({ target, submit, initial }) => {
Rating
</Typography>
{upToDown.sort_by === 'rating' &&
(upToDown.sort === '1' ? (
(upToDown.sort === 'rating_asc' ? (
<ArrowUpwardIcon
sx={{
color: 'black',
Expand Down
5 changes: 3 additions & 2 deletions src/components/forms/salary-slider/slider-range.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box, Slider, Typography } from '@mui/material';
import React from 'react';

export const SliderRange = ({ min, max, value, onChange, label, sx }) => {
export const SliderRange = ({ min, max, value, onChange, label, sx, valueLabelDisplay }) => {
return (
<Box>
<Typography variant={'body2'} sx={formLabelSx}>
Expand All @@ -13,13 +13,14 @@ export const SliderRange = ({ min, max, value, onChange, label, sx }) => {
min={min}
max={max}
value={[value?.from, value?.to]}
valueLabelDisplay={valueLabelDisplay}
onChange={onChange}
sx={{
...sliderSx,
...sx,
}}
/>
<Box sx={infoWrapper}>
<Box sx={infoWrapper} className={'slider-info'}>
{value.from}-{value.to} $
</Box>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import SearchIcon from '@mui/icons-material/Search';
import AuditorCard from './AuditorCard';
import theme from '../../../styles/themes';
import { getAuditors } from '../../../redux/actions/auditorAction.js';
import { getAuditors, searchAuditorV2 } from '../../../redux/actions/auditorAction.js';
import { addTestsLabel } from '../../../lib/helper.js';
import { sliceCards } from './AuditorsProjectsSection.jsx';
import { Link } from 'react-router-dom';
Expand All @@ -30,9 +30,9 @@ const AuditorSection = () => {

useEffect(() => {
if (searchInput) {
dispatch(getAuditors(searchInput, 4));
dispatch(searchAuditorV2({search: searchInput}, true, 4));
} else {
dispatch(getAuditors('', 4));
dispatch(searchAuditorV2({search: searchInput}, true, 4));
}
}, [searchInput]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getAllProjects } from '../../../redux/actions/projectAction.js';
import { clearMessage } from '../../../redux/actions/auditAction.js';
import { addTestsLabel } from '../../../lib/helper.js';
import { sliceCards } from './AuditorsProjectsSection.jsx';
import { getAllProjectsV2 } from '../../../redux/actions/projectAction.js';

const ProjectSection = () => {
const dispatch = useDispatch();
Expand All @@ -29,9 +30,9 @@ const ProjectSection = () => {

useEffect(() => {
if (searchInput) {
dispatch(getAllProjects(searchInput, 4));
dispatch(getAllProjectsV2({search: searchInput}, 4));
} else {
dispatch(getAllProjects('', 4));
dispatch(getAllProjectsV2({search: searchInput}, 4));
}
}, [searchInput]);

Expand Down
57 changes: 57 additions & 0 deletions src/lib/createSearchValuesV2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import dayjs from 'dayjs';

const createSearchValuesV2 = (values, kind) => {
const searchValues = {
query: values?.search || '',
tags: values?.tags || [],
ready_to_wait: values?.ready_to_wait || '',
dateFrom:
+new Date() + 60000 < +new Date(values?.dateFrom)
? dayjs().valueOf(values?.dateFrom)
: '',
dateTo:
+new Date() + 60000 < +new Date(values?.dateTo)
? dayjs().valueOf(values?.dateTo)
: '',
priceFrom: parseInt(values?.price?.from) || '',
priceTo: parseInt(values?.price?.to) || '',
ratingFrom: parseInt(values?.rating?.from) || '',
ratingTo: parseInt(values?.rating?.to) || '',
sort: values?.sort || 1,
page: values?.page || 1,
perPage: values?.perPage ?? 10,
};

const queryParams = [
searchValues.query ? `text=${searchValues.query}` : '',
searchValues.tags.length > 0 ? `tags=${searchValues.tags?.join(' ')}` : '',
searchValues.ratingFrom ? `rating_from=${searchValues.ratingFrom}` : '',
searchValues.ratingTo ? `rating_to=${searchValues.ratingTo}` : '',
`sort_order=${searchValues.sort}`,
`page=${searchValues.page}`,
`sort_by=${values?.sort_by || 'relevance'}`,
`per_page=${searchValues.perPage}`,
`partial_match=true`,
`kind=${kind}`,
];

if (searchValues.ready_to_wait) {
queryParams.push(`ready_to_wait=${searchValues.ready_to_wait}`);
}
if (searchValues.priceFrom) {
queryParams.push(`price_from=${searchValues.priceFrom}`);
}
if (searchValues.priceTo) {
queryParams.push(`price_to=${searchValues.priceTo}`);
}
if (searchValues.dateFrom) {
queryParams.push(`date_from=${searchValues.dateFrom}`);
}
if (searchValues.dateTo) {
queryParams.push(`date_to=${searchValues.dateTo}`);
}

return queryParams.filter(Boolean).join('&');
};

export default createSearchValuesV2;
12 changes: 9 additions & 3 deletions src/pages/AuditorsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Filter from '../components/forms/filter/index.jsx';
import { useDispatch, useSelector } from 'react-redux';
import { useNavigate, useSearchParams } from 'react-router-dom/dist';
import AuditorListCard from '../components/AuditorListCard.jsx';
import { searchAuditor } from '../redux/actions/auditorAction.js';
import { searchAuditor, searchAuditorV2 } from '../redux/actions/auditorAction.js';
import theme from '../styles/themes.js';
import CustomPagination from '../components/custom/CustomPagination.jsx';
import { addTestsLabel } from '../lib/helper.js';
Expand Down Expand Up @@ -46,7 +46,8 @@ const AuditorsPage = () => {
readyToWait: filter.readyToWait || '',
};
});
dispatch(searchAuditor(filter));
// dispatch(searchAuditor(filter));
dispatch(searchAuditorV2(filter));
};

const initialFilter = {
Expand All @@ -62,6 +63,10 @@ const AuditorsPage = () => {
from: searchParams.get('from') || 0,
to: searchParams.get('to') || 0,
},
rating: {
from: searchParams.get('from') || 0,
to: searchParams.get('to') || 0,
},
};

const getNumberOfPages = () => {
Expand All @@ -83,7 +88,8 @@ const AuditorsPage = () => {
}, [query]);

useEffect(() => {
dispatch(searchAuditor(initialFilter));
// dispatch(searchAuditor(initialFilter));
dispatch(searchAuditorV2(initialFilter));
}, [searchParams.toString()]);

useEffect(() => {
Expand Down
5 changes: 3 additions & 2 deletions src/pages/Project-page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Filter from '../components/forms/filter/index.jsx';
import ProjectListCard from '../components/Project-list-card.jsx';
import { PROJECTS } from '../redux/actions/types.js';
import { searchProjects } from '../redux/actions/projectAction.js';
import { searchProjectsV2 } from '../redux/actions/projectAction.js';
import { clearMessage } from '../redux/actions/auditAction.js';
import CustomPagination from '../components/custom/CustomPagination.jsx';
import { addTestsLabel } from '../lib/helper.js';
Expand Down Expand Up @@ -45,7 +46,7 @@ const ProjectPage = () => {
readyToWait: filter.readyToWait || '',
};
});
dispatch(searchProjects(filter));
dispatch(searchProjectsV2(filter));
};

const initialFilter = {
Expand Down Expand Up @@ -85,7 +86,7 @@ const ProjectPage = () => {
}, [query]);

useEffect(() => {
dispatch(searchProjects(initialFilter));
dispatch(searchProjectsV2(initialFilter));
}, [searchParams.toString()]);

useEffect(() => {
Expand Down
20 changes: 20 additions & 0 deletions src/redux/actions/auditorAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from './types.js';
import { history } from '../../services/history.js';
import createSearchValues from '../../lib/createSearchValues.js';
import createSearchValuesV2 from '../../lib/createSearchValuesV2.js';
import { isAuth } from '../../lib/helper.js';

const API_URL = import.meta.env.VITE_API_BASE_URL;
Expand Down Expand Up @@ -201,6 +202,25 @@ export const searchAuditor = (values, badges = true) => {
};
};

export const searchAuditorV2 = (values, badges = true, perPage = 10) => {
const kind = badges ? 'auditor,badge' : 'auditor';
const queryString = createSearchValuesV2({...values, perPage}, kind);
return dispatch => {
const token = Cookies.get('token');
axios
.get(
`${API_URL}/v2/search?${queryString}`,
isAuth() ? { headers: { Authorization: `Bearer ${token}` } } : {},
)
.then(({ data }) => {
dispatch({ type: GET_AUDITORS, payload: data });
})
.catch(({ response }) => {
console.error(response, 'res');
})
};
};

export const deleteBadgeProfile = id => {
return dispatch => {
axios
Expand Down
20 changes: 20 additions & 0 deletions src/redux/actions/customerAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from './types.js';
import { history } from '../../services/history.js';
import createSearchValues from '../../lib/createSearchValues.js';
import createSearchValuesV2 from '../../lib/createSearchValuesV2.js';
import { isAuth } from '../../lib/helper.js';

const API_URL = import.meta.env.VITE_API_BASE_URL;
Expand Down Expand Up @@ -152,3 +153,22 @@ export const searchCustomers = values => {
});
};
};

export const searchCustomersV2 = (values) => {
const queryString = createSearchValuesV2(values, 'customer');

return dispatch => {
const token = Cookies.get('token');
axios
.get(
`${API_URL}/v2/search?${queryString}`,
isAuth() ? { headers: { Authorization: `Bearer ${token}` } } : {},
)
.then(({ data }) => {
dispatch({ type: GET_CUSTOMERS, payload: data });
})
.catch(({ response }) => {
console.error(response, 'res');
})
};
};
Loading