source: frontend/src/components/TherapistCard.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: 8.7 KB
RevLine 
[700e2f9]1import { type Component, For, Show, createSignal } from "solid-js";
2import type { TherapistInfo } from "@/api/therapist";
3import { patientApi } from "@/api/patient";
4import { formatDateWithWeekday } from "@/utils";
5
6interface TherapistCardProps {
7 therapist: TherapistInfo;
8 isCurrentTherapist?: boolean;
9 onTherapistChange?: () => void;
10}
11
12const TherapistCard: Component<TherapistCardProps> = (props) => {
13 const [isLoading, setIsLoading] = createSignal(false);
14 const [error, setError] = createSignal("");
15
16 const handleSetTherapist = async () => {
17 setIsLoading(true);
18 setError("");
19
20 try {
21 if (props.isCurrentTherapist) {
22 await patientApi.removeTherapist();
23 } else {
24 await patientApi.setTherapist(props.therapist.idUser);
25 }
26 props.onTherapistChange?.();
27 } catch (err) {
28 setError(
29 err instanceof Error ? err.message : "Failed to update therapist",
30 );
31 } finally {
32 setIsLoading(false);
33 }
34 };
35
36 return (
37 <div class="bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg transition-shadow relative flex flex-col h-full">
38 <Show when={props.isCurrentTherapist}>
39 <div class="absolute top-4 right-4 z-10">
40 <div class="bg-green-500 text-white px-3 py-1 rounded-full text-xs font-semibold flex items-center gap-1 shadow-lg">
41 <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
42 <path
43 fill-rule="evenodd"
44 d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
45 clip-rule="evenodd"
46 />
47 </svg>
48 My Therapist
49 </div>
50 </div>
51 </Show>
52
53 <div class="bg-linear-to-r from-blue-500 to-blue-600 p-6 text-white">
54 <h2 class="text-2xl font-bold mb-1">
55 {props.therapist.name} {props.therapist.surname}
56 </h2>
57 <p class="text-blue-100 text-sm">{props.therapist.degree}</p>
58 </div>
59
60 <div class="p-6 flex flex-col grow">
61 <div class="space-y-3 mb-4">
62 <div class="flex items-start">
63 <svg
64 class="w-5 h-5 text-gray-400 mt-0.5 mr-2 shrink-0"
65 fill="none"
66 stroke="currentColor"
67 viewBox="0 0 24 24"
68 >
69 <path
70 stroke-linecap="round"
71 stroke-linejoin="round"
72 stroke-width="2"
73 d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"
74 />
75 <path
76 stroke-linecap="round"
77 stroke-linejoin="round"
78 stroke-width="2"
79 d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"
80 />
81 </svg>
82 <span class="text-gray-700">{props.therapist.officeLocation}</span>
83 </div>
84
85 <div class="flex items-center">
86 <svg
87 class="w-5 h-5 text-gray-400 mr-2 shrink-0"
88 fill="none"
89 stroke="currentColor"
90 viewBox="0 0 24 24"
91 >
92 <path
93 stroke-linecap="round"
94 stroke-linejoin="round"
95 stroke-width="2"
96 d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"
97 />
98 </svg>
99 <span class="text-gray-700 text-sm">{props.therapist.email}</span>
100 </div>
101
102 <div class="flex items-center">
103 <svg
104 class="w-5 h-5 text-gray-400 mr-2 shrink-0"
105 fill="none"
106 stroke="currentColor"
107 viewBox="0 0 24 24"
108 >
109 <path
110 stroke-linecap="round"
111 stroke-linejoin="round"
112 stroke-width="2"
113 d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"
114 />
115 </svg>
116 <span class="text-gray-700 text-sm">
117 {props.therapist.phoneNumber}
118 </span>
119 </div>
120
121 <div class="flex items-center">
122 <svg
123 class="w-5 h-5 text-gray-400 mr-2 shrink-0"
124 fill="none"
125 stroke="currentColor"
126 viewBox="0 0 24 24"
127 >
128 <path
129 stroke-linecap="round"
130 stroke-linejoin="round"
131 stroke-width="2"
132 d="M9 12l2 2 4-4M7.835 4.697a3.42 3.42 0 001.946-.806 3.42 3.42 0 014.438 0 3.42 3.42 0 001.946.806 3.42 3.42 0 013.138 3.138 3.42 3.42 0 00.806 1.946 3.42 3.42 0 010 4.438 3.42 3.42 0 00-.806 1.946 3.42 3.42 0 01-3.138 3.138 3.42 3.42 0 00-1.946.806 3.42 3.42 0 01-4.438 0 3.42 3.42 0 00-1.946-.806 3.42 3.42 0 01-3.138-3.138 3.42 3.42 0 00-.806-1.946 3.42 3.42 0 010-4.438 3.42 3.42 0 00.806-1.946 3.42 3.42 0 013.138-3.138z"
133 />
134 </svg>
135 <span class="text-gray-700">
136 {props.therapist.yearsExp} years experience
137 </span>
138 </div>
139 </div>
140
141 <div class="border-t py-4 grow">
142 <h3 class="font-semibold text-gray-900 mb-3 flex items-center">
143 <svg
144 class="w-5 h-5 text-green-500 mr-2"
145 fill="none"
146 stroke="currentColor"
147 viewBox="0 0 24 24"
148 >
149 <path
150 stroke-linecap="round"
151 stroke-linejoin="round"
152 stroke-width="2"
153 d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
154 />
155 </svg>
156 Available Consultations (
157 {props.therapist.freeConsultationSlots.length || "None"})
158 </h3>
159 <Show
160 when={
161 props.therapist.freeConsultationSlots &&
162 props.therapist.freeConsultationSlots.length > 0
163 }
164 fallback={
165 <p class="text-gray-500 text-sm italic">
166 No available slots at the moment
167 </p>
168 }
169 >
170 <div class="space-y-2 max-h-48 overflow-y-auto">
171 <For each={props.therapist.freeConsultationSlots}>
172 {(slot) => (
173 <div class="bg-green-50 border border-green-200 rounded px-3 py-2 text-sm text-green-800">
174 {formatDateWithWeekday(slot)}
175 </div>
176 )}
177 </For>
178 </div>
179 </Show>
180 </div>
181
182 <div class="border-t pt-4 mt-auto">
183 <Show when={error()}>
184 <div class="mb-3 text-sm text-red-600 bg-red-50 p-2 rounded">
185 {error()}
186 </div>
187 </Show>
188
189 <Show
190 when={!isLoading()}
191 fallback={
192 <div class="animate-spin rounded-full h-4 w-4 border-b-2 border-current" />
193 }
194 >
195 <button
196 onClick={handleSetTherapist}
197 class={`w-full py-2 px-4 rounded-lg font-medium transition-colors flex items-center justify-center gap-2 cursor-pointer ${
198 props.isCurrentTherapist
199 ? "bg-red-50 text-red-700 border border-red-200 hover:bg-red-100"
200 : "bg-blue-600 text-white hover:bg-blue-700"
201 } disabled:opacity-50 disabled:cursor-not-allowed`}
202 >
203 <Show
204 when={props.isCurrentTherapist}
205 fallback={
206 <>
207 <svg
208 class="w-5 h-5"
209 fill="none"
210 stroke="currentColor"
211 viewBox="0 0 24 24"
212 >
213 <path
214 stroke-linecap="round"
215 stroke-linejoin="round"
216 stroke-width="2"
217 d="M12 4v16m8-8H4"
218 />
219 </svg>
220 Set as My Therapist
221 </>
222 }
223 >
224 <svg
225 class="w-5 h-5"
226 fill="none"
227 stroke="currentColor"
228 viewBox="0 0 24 24"
229 >
230 <path
231 stroke-linecap="round"
232 stroke-linejoin="round"
233 stroke-width="2"
234 d="M6 18L18 6M6 6l12 12"
235 />
236 </svg>
237 Remove as My Therapist
238 </Show>
239 </button>
240 </Show>
241 </div>
242 </div>
243 </div>
244 );
245};
246
247export default TherapistCard;
Note: See TracBrowser for help on using the repository browser.