frontend: instead of create a care action, create simply a medicine regimen
The user can "take" the medicine later on the new screen
Parents:
d7eb7251 file(s) changed
- frontend/app/care-actions/medicine-new.tsx +9 -15
frontend/app/care-actions/medicine-new.tsx
1 1
import {
2 2
View,
3 3
Text,
4 4
StyleSheet,
5 5
KeyboardAvoidingView,
▸ 7 unchanged lines
13 13
import { Input } from "@/components/ui/Input";
14 14
import { Button } from "@/components/ui/Button";
15 15
import { Section, SectionHeader } from "@/components/ui/Sections";
16 16
import { Spacing, Typography, Colors, BorderRadius, Shadows } from "@/constants/theme";
17 17
import { TimePicker } from "@/components/ui/TimePicker";
18 -
import { useCreateCareAction } from "@/hooks";
18 +
import { useCreateMedicineRegimen } from "@/hooks";
19 19
import { MedicinePeriodicity } from "@/lib/api";
20 20
21 21
const PERIODICITY_OPTIONS: { label: string; value: MedicinePeriodicity }[] = [
22 22
{ label: 'Uma vez', value: 'ONCE' },
23 23
{ label: 'Diário', value: 'DAILY' },
▸ 8 unchanged lines
32 32
switch (p) {
33 33
case 'ONCE': return 0;
34 34
case 'DAILY': return 1;
35 35
case 'TWICE_DAILY': return 2;
36 36
case 'THREE_TIMES_DAILY': return 3;
37 -
case 'WEEKLY':
38 -
case 'BIWEEKLY':
39 -
case 'MONTHLY': return 1;
37 +
default: return 1;
40 38
}
41 39
}
42 40
43 41
export default function MedicineNewCareAction() {
44 42
const [medicineName, setMedicineName] = useState('');
45 43
const [medicineDosage, setMedicineDosage] = useState('');
46 44
const [medicinePeriodicity, setMedicinePeriodicity] = useState<MedicinePeriodicity>('ONCE');
47 45
const [scheduledTimes, setScheduledTimes] = useState<Date[]>([]);
48 46
49 -
const createCareAction = useCreateCareAction();
47 +
const createRegimen = useCreateMedicineRegimen();
50 48
51 49
const handleSave = async () => {
52 50
const count = getTimePickerCount(medicinePeriodicity);
53 51
const scheduledAt = scheduledTimes.slice(0, count).map(
54 52
d => `${d.getHours().toString().padStart(2,'0')}:${d.getMinutes().toString().padStart(2,'0')}`
55 53
);
56 54
57 -
await createCareAction.mutateAsync({
58 -
type: 'MEDICINE',
59 -
moment: new Date(),
60 -
medicine: {
61 -
name: medicineName,
62 -
dosage: medicineDosage,
63 -
periodicity: medicinePeriodicity,
64 -
scheduledAt,
65 -
},
55 +
await createRegimen.mutateAsync({
56 +
name: medicineName,
57 +
dosage: medicineDosage,
58 +
periodicity: medicinePeriodicity,
59 +
scheduledAt,
66 60
});
67 61
router.replace('/(tabs)/actions');
68 62
};
69 63
70 64
return (
▸ 78 unchanged lines
149 143
)}
150 144
151 145
<Button
152 146
title="Salvar"
153 147
onPress={handleSave}
154 -
loading={createCareAction.isPending}
148 +
loading={createRegimen.isPending}
155 149
disabled={!medicineName || !medicineDosage}
156 150
/>
157 151
</View>
158 152
</ScrollView>
159 153
</KeyboardAvoidingView>
▸ 45 unchanged lines
205 199
periodicityChipLabelActive: {
206 200
fontWeight: '600',
207 201
color: Colors.light.text,
208 202
},
209 203
});