/
astafievk
/
source_code
Обзор
Документация
Войти
/
astafievk
/
source_code
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
App/src/components/Modals/ModalPriceList/PriceRow.tsx
40 строк
2 KB
astafievK
source code
21 июн 2024, 21:02
21 июн 2024, 21:02
37a1d03
Код
Авторство
О чём код?
import {FC} from "react"; import { useGetServiceByIdQuery } from '../../../api/methods/serviceApi.ts'; import { useGetUserByEmployeeIdQuery } from '../../../api/methods/userApi.ts'; import { useAppDispatch } from '../../../store/hooks/redux.ts'; import { setIdEmployee, setIdService, setNameEmployee, setNameService } from '../../../api/slices/timeFormSlice.ts'; import { useNavigate } from 'react-router-dom'; import { setPriceListIsOpen } from '../../../api/slices/priceListModalSlice.ts'; interface PriceRowProps{ idEmployee: number idService: number name: string surname: string price: number } export const PriceRow: FC<PriceRowProps> = (props) => { const dispatch = useAppDispatch() const navigate = useNavigate(); const { data: serviceData } = useGetServiceByIdQuery({idService: props.idService}) const {data: employeeData} = useGetUserByEmployeeIdQuery({idEmployee: props.idEmployee}) const handleClick = () => { if(serviceData && employeeData){ dispatch(setIdService(serviceData.idService)) dispatch(setIdEmployee(employeeData.idEmployee)) dispatch(setNameService(serviceData.title)) dispatch(setNameEmployee(`${employeeData.surname} ${employeeData.name} ${employeeData.patronymic}`)) dispatch(setPriceListIsOpen(false)) navigate('/time') } } return ( <button className="row" onClick={handleClick}> <span className="name">{props.surname} {props.name}</span> <span className="price">{props.price} руб.</span> </button> ) }