ilnaz 3b4f5a8486
Some checks failed
it-academy/dry-wash-pl/pipeline/pr-main There was a failure building this commit
feat: separation of imports (#40)
2024-11-24 14:57:36 +03:00

71 lines
1.6 KiB
TypeScript

import React, { useState } from 'react';
import { Td, Tr, Link, Select } from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
import dayjs from 'dayjs';
import { getTimeSlot } from '../../lib/date-helpers';
const statuses = [
'pending' as const,
'progress' as const,
'working' as const,
'canceled' as const,
'complete' as const,
];
type GetArrItemType<ArrType> =
ArrType extends Array<infer ItemType> ? ItemType : never;
export type OrderProps = {
carNumber?: string;
startWashTime?: string;
endWashTime?: string;
orderDate?: string;
status?: GetArrItemType<typeof statuses>;
phone?: string;
location?: string;
};
const OrderItem = ({
carNumber,
startWashTime,
endWashTime,
orderDate,
status,
phone,
location,
}: OrderProps) => {
const { t } = useTranslation('~', {
keyPrefix: 'dry-wash.arm.order',
});
const [statusSelect, setStatus] = useState(status);
return (
<Tr>
<Td>{carNumber}</Td>
<Td>{getTimeSlot(startWashTime, endWashTime)}</Td>
<Td>{dayjs(orderDate).format('DD.MM.YYYY')}</Td>
<Td>
<Select
value={statusSelect}
onChange={(e) => setStatus(e.target.value as OrderProps['status'])}
placeholder={t(`status.placeholder`)}
>
{statuses.map((status) => (
<option key={status} value={status}>
{t(`status.${status}`)}
</option>
))}
</Select>
</Td>
<Td>
<Link href='tel:'>{phone}</Link>
</Td>
<Td>{location}</Td>
</Tr>
);
};
export default OrderItem;