Skip to content

Commit

Permalink
fix: solving bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Katiene Souza committed Oct 25, 2023
1 parent 4571777 commit 837c296
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 19 deletions.
4 changes: 0 additions & 4 deletions src/components/Filter/Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ const Filter = () => {
}
}
});

filtersDispatch(actions.addMinWage(String(minSalary)));
filtersDispatch(actions.addMaxWage(String(maxSalary)));

queryDispatch(queryActions.setQuery(buildQueryString(filters)));
}
}, [filters.technologies, visibleTechCount, isLoaded]);
Expand Down
1 change: 1 addition & 0 deletions src/components/RecentVacancies/RecentVacancies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const RecentVacancies = () => {
location={data.location}
technologies={data.technologies}
vacancyRole={data.vacancyRole}
id={data.id}
/>
))}
</div>
Expand Down
14 changes: 9 additions & 5 deletions src/components/VacancyCard/VacancyCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { render, screen } from '@testing-library/react';
import { expect } from '@jest/globals';
import { BrowserRouter } from 'react-router-dom';
import VacancyCard from './VacancyCard';

describe('VancancyCard component', () => {
let container: HTMLElement;

beforeEach(() => {
container = render(
<VacancyCard
location={'Betim-MG'}
technologies={[]}
vacancyRole={'Desenvolvedor de sistemas pleno'}
/>,
<BrowserRouter>
<VacancyCard
location={'Betim-MG'}
technologies={[]}
vacancyRole={'Desenvolvedor de sistemas pleno'}
id={''}
/>
</BrowserRouter>,
).container;
});

Expand Down
18 changes: 16 additions & 2 deletions src/components/VacancyCard/VacancyCard.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import BaseCard from '@components/BaseCard';
import Text from '@components/Text';
import useFilters from '@hooks/useFilters';

import * as S from './styles';
import * as I from '@assets/db.icons';
import useUser from '@hooks/useUser';
import { actions } from '@contexts/filters';

type props = {
location: string;
technologies: Technology[];
vacancyRole: string;
id: string;
};

const VacancyCard = ({ location, technologies, vacancyRole }: props) => {
const VacancyCard = ({ location, technologies, vacancyRole, id }: props) => {
const { user } = useUser();
const { filtersDispatch } = useFilters();

const technologyElements = technologies
.map((technology, index) => <b key={index}>{technology.techName}</b>)
.slice(0, 1);

const handleFilter = () => {
filtersDispatch(actions.addId(id));
filtersDispatch(actions.addLocation(location));
filtersDispatch(actions.addTechnology(technologies[0].techName));
};

return (
<BaseCard>
<S.Card data-cy="vancacy-card">
Expand All @@ -43,7 +53,11 @@ const VacancyCard = ({ location, technologies, vacancyRole }: props) => {
fontColor="dark-gray"
/>
</div>
<S.Link href={user ? '/vacancies' : '/register'} data-cy="link">
<S.Link
onClick={user ? handleFilter : () => {}}
to={user ? '/vacancies' : '/register'}
data-cy="link"
>
<Text
label="Ver mais detalhes"
fontWeight="bold"
Expand Down
4 changes: 2 additions & 2 deletions src/components/VacancyCard/VecancyCard.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('', () => {
cy.mount(
<>
<GlobalStyle />
<VacacyCard location={''} technologies={[]} vacancyRole={''} />
<VacacyCard location={''} technologies={[]} vacancyRole={''} id={''} />
</>,
);

Expand All @@ -17,7 +17,7 @@ describe('', () => {
cy.mount(
<>
<GlobalStyle />
<VacacyCard location={''} technologies={[]} vacancyRole={''} />
<VacacyCard location={''} technologies={[]} vacancyRole={''} id={''} />
</>,
);

Expand Down
3 changes: 2 additions & 1 deletion src/components/VacancyCard/styles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from 'styled-components';
import { Link as RouterLink } from 'react-router-dom';

export const Card = styled.div`
display: flex;
Expand All @@ -25,7 +26,7 @@ export const Container = styled.div`
}
`;

export const Link = styled.a`
export const Link = styled(RouterLink)`
display: flex;
text-decoration: none;
`;
14 changes: 14 additions & 0 deletions src/contexts/filters/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,17 @@ export const resetFilters = () => {
payload: '',
};
};

export const addId = (id: string) => {
return {
type: 'ADD_ID',
payload: id,
};
};

export const removeId = () => {
return {
type: 'REMOVE_ID',
payload: '',
};
};
12 changes: 12 additions & 0 deletions src/contexts/filters/dispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Action } from './actions';

export type Filters = {
id: string;
location: string;
technologies: string[];
vacancyTypes: string[];
Expand All @@ -14,6 +15,7 @@ export type Filters = {
};

export const initialState: Filters = {
id: '',
location: '',
technologies: [],
vacancyTypes: [],
Expand Down Expand Up @@ -129,6 +131,16 @@ export const filtersDispatcher = (
...state,
description: '',
};
case 'ADD_ID':
return {
...state,
id: action.payload,
};
case 'REMOVE_ID':
return {
...state,
id: action.payload,
};
case 'RESET_FILTERS':
return initialState;
default:
Expand Down
6 changes: 1 addition & 5 deletions src/pages/VacanciesPage/VacanciesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ const VacanciesPage = () => {

const [vacancies, vacancyService, vacanciesCount] = useResource<Vacancy>(url);

const isLoaded = useFetchResource(vacancyService, [
query,
currentPage,
filters.technologies,
]);
const isLoaded = useFetchResource(vacancyService, [query, currentPage]);

useEffect(() => {
setCurrentPage(1);
Expand Down

0 comments on commit 837c296

Please sign in to comment.