source: frontend/src/components/ConsultationRow.tsx

main
Last change on this file was 700e2f9, checked in by 186079 <matej.milevski@…>, 5 days ago

Init

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[700e2f9]1import { type Component, Show } from "solid-js";
2import { type Consultation, isConsultationPaid } from "@/api/consultation";
3import { formatDate } from "@/utils";
4
5interface ConsultationRowProps {
6 consultation: Consultation;
7 onEdit: (consultation: Consultation) => void;
8 onDelete: (id: number) => void;
9 onTogglePayment: (consultation: Consultation) => void;
10 readOnly?: boolean;
11}
12
13const formatCurrency = (amount: number) =>
14 new Intl.NumberFormat("mk-MK", {
15 style: "currency",
16 currency: "EUR",
17 }).format(amount);
18
19const ConsultationRow: Component<ConsultationRowProps> = (props) => (
20 <tr class="hover:bg-gray-50">
21 <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
22 {formatDate(props.consultation.date)}
23 </td>
24 <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
25 {props.readOnly
26 ? props.consultation.therapistName
27 : props.consultation.patientName}
28 </td>
29 <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
30 {formatCurrency(props.consultation.price)}
31 </td>
32 <td class="px-6 py-4 whitespace-nowrap">
33 <Show
34 when={!props.readOnly}
35 fallback={
36 <span
37 class={`px-3 py-1 rounded-full text-xs font-semibold ${
38 isConsultationPaid(props.consultation)
39 ? "bg-green-100 text-green-800"
40 : "bg-red-100 text-red-800"
41 }`}
42 >
43 {isConsultationPaid(props.consultation)
44 ? `Paid (${formatDate(props.consultation.dateOfPayment!)})`
45 : "Unpaid"}
46 </span>
47 }
48 >
49 <button
50 onClick={() => props.onTogglePayment(props.consultation)}
51 class={`px-3 py-1 rounded-full text-xs font-semibold cursor-pointer ${
52 isConsultationPaid(props.consultation)
53 ? "bg-green-100 text-green-800 hover:bg-green-200"
54 : "bg-red-100 text-red-800 hover:bg-red-200"
55 }`}
56 >
57 {isConsultationPaid(props.consultation)
58 ? `Paid (${formatDate(props.consultation.dateOfPayment!)})`
59 : "Unpaid"}
60 </button>
61 </Show>
62 </td>
63 <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
64 <Show
65 when={!props.readOnly}
66 fallback={
67 <button
68 onClick={() => props.onEdit(props.consultation)}
69 class="text-blue-600 hover:text-blue-900 cursor-pointer"
70 >
71 View Details
72 </button>
73 }
74 >
75 <button
76 onClick={() => props.onEdit(props.consultation)}
77 class="text-blue-600 hover:text-blue-900 mr-4 cursor-pointer"
78 >
79 Edit
80 </button>
81 <button
82 onClick={() => props.onDelete(props.consultation.idConsultation)}
83 class="text-red-600 hover:text-red-900 cursor-pointer"
84 >
85 Delete
86 </button>
87 </Show>
88 </td>
89 </tr>
90);
91
92export default ConsultationRow;
Note: See TracBrowser for help on using the repository browser.