export const getSinglePostRequest = (slug: string) => (
dispatch: Dispatch
): void => {
dispatch(changeLoadingSinglePost(true));
const post = new ServicesApi();
post.getRequestSingleArticle(slug).then((data) => {
dispatch(addSinglePost(data.article));
dispatch(changeLoadingSinglePost(false));
});
};
useEffect(() => {
dispatch(getSinglePostRequest(slugId));
}, [dispatch, slugId]);
export default ({ tickets, isLoading }) => {
const createTicketsList = tickets.map(({ price, carrier, segments }) => {
return (
<TicketsListItem
price={price}
carrier={carrier}
segment={segments}
key={uniqueid('ticket_')}
/>
);
});
const createList = (
<ul className={style['tickets-list']}>{createTicketsList}</ul>
);
const content = isLoading ? <Spinner /> : createList;
return content;
};
function increaseSalary() {
return new Promise((resolve, reject) => {
let minSalaryEmployee = api.getEmployees().then((employeeData) => {
const minSalary = Math.min(...employeeData.map(({ salary }) => salary));
minSalaryEmployee = employeeData.filter(({ salary }) => {
return salary === minSalary;
});
const [id, oldSalary] = [
minSalaryEmployee[0].id,
minSalaryEmployee[0].salary,
];
const newSalary = oldSalary + (oldSalary / 100) * 20;
return { id: id, salary: newSalary };
})
minSalaryEmployee.then((data) => {
let newSalary = api.setEmployeeSalary(data.id, data.salary);
newSalary
.then((newData) => {
const { name, id, salary } = newData;
const notifyEmployee = api.notifyEmployee(
id,
`Hello, ${name}! Congratulations, your new salary is ${salary}!`
);
resolve(notifyEmployee);
})
.catch((e) => {
reject(api.notifyAdmin(e));
})
}).catch(reject)
})
}