Skip to content

Commit

Permalink
fix/add finish
Browse files Browse the repository at this point in the history
  • Loading branch information
k0t1k777 committed Aug 23, 2024
1 parent ff4c481 commit 9ae82ee
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/components/Filter/Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function Filter({ droppedCards }: FilterProps) {
useAppSelector(selectMembers);
const modalRef = useRef<HTMLDivElement>(null);
const dispatch = useAppDispatch();
const { department, position, citie } = useAppSelector(selectFilter);
const { department, position, city } = useAppSelector(selectFilter);
const [currentPageFilter, setCurrentPageFilter] = useState(1);

const currentPageRef = useRef(currentPageFilter);
Expand All @@ -39,7 +39,7 @@ export default function Filter({ droppedCards }: FilterProps) {
setCurrentPageFilter(1);
currentPageRef.current = 1;
await dispatch(
fetchGetMembers({ page: 1, search: value, position, department, citie })
fetchGetMembers({ page: 1, search: value, position, department, city })
);
};

Expand All @@ -58,7 +58,7 @@ export default function Filter({ droppedCards }: FilterProps) {
search: search ? search : '',
position,
department,
citie,
city,
})
);
}
Expand Down Expand Up @@ -87,10 +87,10 @@ export default function Filter({ droppedCards }: FilterProps) {
search: search ? search : '',
position,
department,
citie,
city,
})
);
}, [dispatch, currentPageFilter, search, position, department, citie]);
}, [dispatch, currentPageFilter, search, position, department, city]);

useEffect(() => {
if (modalRef.current) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function Header({ droppedCards }: HeaderProps) {
search: value,
position: '',
department: '',
citie: '',
city: '',
})
);
navigate('/employees');
Expand Down
10 changes: 5 additions & 5 deletions src/pages/Employees/Employees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function Employees() {
const { members, membersAmount, currentPage, search } =
useAppSelector(selectMembers);
const { isProfileOpen } = useAppSelector(selectUsers);
const { department, position, citie } = useAppSelector(selectFilter);
const { department, position, city } = useAppSelector(selectFilter);
const cx = cn.bind(styles);
const dispatch = useAppDispatch();

Expand All @@ -31,7 +31,7 @@ export default function Employees() {
function nextPage() {
if (currentPage < maxPages) {
dispatch(
fetchGetMembers({ page: currentPage + 1, search, position, department, citie })
fetchGetMembers({ page: currentPage + 1, search, position, department, city })
);
dispatch(setCurrentPage(currentPage + 1));
}
Expand All @@ -40,17 +40,17 @@ export default function Employees() {
function previousPage() {
if (currentPage > 1) {
dispatch(
fetchGetMembers({ page: currentPage - 1, search, position, department, citie })
fetchGetMembers({ page: currentPage - 1, search, position, department, city })
);
dispatch(setCurrentPage(currentPage - 1));
}
}

useEffect(() => {
dispatch(
fetchGetMembers({ page: currentPage, search, position, department, citie })
fetchGetMembers({ page: currentPage, search, position, department, city })
);
}, [dispatch, currentPage, search, position, department, citie]);
}, [dispatch, currentPage, search, position, department, city]);

return (
<section
Expand Down
4 changes: 2 additions & 2 deletions src/store/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ export const getMembersData = (
search: string,
position: string,
department: string,
citie: string,
city: string,
) => {
return fetch(
`${BASE_URL}/api/v1/members/?${buildQueryString({
page,
search,
position,
department,
citie,
city,
})}`,
{
method: 'GET',
Expand Down
10 changes: 5 additions & 5 deletions src/store/features/slice/filterSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface StateType {
error: string | null | unknown;
position: string,
department: string,
citie: string,
city: string,
}

const initialState: StateType = {
Expand All @@ -20,7 +20,7 @@ const initialState: StateType = {
},
position: '',
department: '',
citie: '',
city: '',
isLoading: false,
error: null,
};
Expand All @@ -43,8 +43,8 @@ const filterSlice = createSlice({
setDepartment(state, action) {
state.department = action.payload;
},
setCitie(state, action) {
state.citie = action.payload;
setCity(state, action) {
state.city = action.payload;
},
},
extraReducers: (builder) => {
Expand All @@ -66,6 +66,6 @@ const filterSlice = createSlice({
},
});

export const {setPosition, setDepartment, setCitie} = filterSlice.actions;
export const {setPosition, setDepartment, setCity} = filterSlice.actions;
export const filterReducer = filterSlice.reducer;
export const selectFilter = (state: RootStore) => state.filter;
10 changes: 5 additions & 5 deletions src/store/features/slice/membersSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface StateType {
search: string;
position: string;
department: string;
citie: string;
city: string;
}

const initialState: StateType = {
Expand All @@ -32,7 +32,7 @@ const initialState: StateType = {
search: '',
position: '',
department: '',
citie: '',
city: '',
};

export const fetchGetMembers = createAsyncThunk(
Expand All @@ -42,15 +42,15 @@ export const fetchGetMembers = createAsyncThunk(
search,
position,
department,
citie,
city,
}: {
page: number;
search: string;
position: string;
department: string;
citie: string;
city: string;
}) => {
const response = await getMembersData(page, search, position, department, citie);
const response = await getMembersData(page, search, position, department, city);
return response;
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/EmployeesList/EmployeesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function EmployeesList() {
dispatch(setSearch(value));
dispatch(setCurrentPage(1));
await dispatch(
fetchGetMembers({ page: 1, search: value, position, department, citie: '' })
fetchGetMembers({ page: 1, search: value, position, department, city: '' })
);
};

Expand Down
17 changes: 8 additions & 9 deletions src/ui/FilterList/FilterList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@ import { setCurrentPage } from 'src/store/features/slice/membersSlice';
import {
fetchSelects,
selectFilter,
setCitie,
setCity,
setDepartment,
setPosition,
} from 'src/store/features/slice/filterSlice';
import { useEffect } from 'react';
import Select from 'src/ui/Select/Select';

export default function FilterList() {
const { selects, department, position, citie } = useAppSelector(selectFilter);
const { selects, department, position, city } = useAppSelector(selectFilter);

const dispatch = useAppDispatch();

const handleSelectChange = (
value: string,
type: 'position' | 'department' | 'citie'
type: 'position' | 'department' | 'city'
) => {
if (type === 'position') {
dispatch(setPosition(value));
} else if (type === 'department') {
dispatch(setDepartment(value));
} else if (type === 'citie') {
console.log(value)
dispatch(setCitie(value));
} else if (type === 'city') {
dispatch(setCity(value));
}
dispatch(setCurrentPage(1));
};
Expand All @@ -35,7 +34,7 @@ export default function FilterList() {
return () => {
dispatch(setPosition(''));
dispatch(setDepartment(''));
dispatch(setCitie(''));
dispatch(setCity(''));
dispatch(setCurrentPage(1));
};
}, [location.pathname, dispatch]);
Expand Down Expand Up @@ -66,8 +65,8 @@ export default function FilterList() {
<Select
text='Город'
options={selects.cities}
value={citie}
setValue={(value) => handleSelectChange(value, 'citie')}
value={city}
setValue={(value) => handleSelectChange(value, 'city')}
/>
</li>
</ul>
Expand Down

0 comments on commit 9ae82ee

Please sign in to comment.