Skip to content

Commit 2b9c43b

Browse files
authored
Merge pull request #199 from openscript-ch/10-implement-entries-that-recure-in-weekly-periods
10 implement entries that recure in weekly periods
2 parents 76379f8 + 514bcf1 commit 2b9c43b

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

.changeset/wet-forks-nail.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@quassel/frontend": patch
3+
"@quassel/ui": patch
4+
---
5+
6+
Introduce setting weeklyRecurring for entries

apps/frontend/src/components/questionnaire/calendar/EntryForm.tsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Button, Group, Stack, TimeInput, NumberInput, ActionIcon, IconMinus, isInRange, isNotEmpty, useForm } from "@quassel/ui";
1+
import { Button, Group, Stack, TimeInput, NumberInput, ActionIcon, IconMinus, isInRange, isNotEmpty, useForm, Switch } from "@quassel/ui";
22
import { i18n } from "../../../stores/i18n";
33
import { useStore } from "@nanostores/react";
4-
import { useEffect } from "react";
4+
import { useEffect, useState } from "react";
55
import { CarerSelect } from "../../CarerSelect";
66
import { LanguageSelect } from "../../LanguageSelect";
77
import { components } from "../../../api.gen";
@@ -13,15 +13,20 @@ export type EntryFormValues = {
1313
ratio: number;
1414
language?: number;
1515
}[];
16+
weeklyRecurring?: number;
1617
startedAt: string;
1718
endedAt: string;
1819
};
1920

2021
const messages = i18n("entityForm", {
21-
actionAddDialect: "Add dialect",
22+
actionAddLanguage: "Add language",
23+
actionAddRecurringRule: "Add recurring rule",
2224
actionDelete: "Delete",
25+
2326
labelCarer: "Carer",
2427
labelLanguage: "Language",
28+
labelRecurringRulePrefix: "Recurs every",
29+
labelRecurringRuleSuffix: "weeks.",
2530
validationRatio: "Ratio must be between 1 and 100.",
2631
validationTotalRatio: "Total Ratio must always be 100%.",
2732
validationNotEmpty: "Field must not be empty.",
@@ -67,10 +72,16 @@ export function EntityForm({ onSave, onDelete, onAddCarer, onAddLanguage, action
6772
},
6873
});
6974

75+
const [showRecurringRule, setShowRecurringRule] = useState(false);
76+
7077
useEffect(() => {
7178
if (entry) {
7279
f.setValues(entry);
7380
f.resetDirty();
81+
82+
if (entry.weeklyRecurring && entry.weeklyRecurring > 1) {
83+
setShowRecurringRule(true);
84+
}
7485
}
7586
}, [entry]);
7687

@@ -132,14 +143,30 @@ export function EntityForm({ onSave, onDelete, onAddCarer, onAddLanguage, action
132143
}}
133144
variant="light"
134145
>
135-
{t.actionAddDialect}
146+
{t.actionAddLanguage}
136147
</Button>
137148
<Group>
138149
<TimeInput flex={1} {...f.getInputProps("startedAt")} />
139150
-
140151
<TimeInput flex={1} {...f.getInputProps("endedAt")} />
141152
</Group>
142153

154+
<Switch
155+
checked={showRecurringRule}
156+
onClick={() => {
157+
f.setValues({ weeklyRecurring: showRecurringRule ? 1 : 2 });
158+
setShowRecurringRule(!showRecurringRule);
159+
}}
160+
label={t.actionAddRecurringRule}
161+
></Switch>
162+
{showRecurringRule && (
163+
<Group>
164+
{t.labelRecurringRulePrefix}
165+
<NumberInput {...f.getInputProps("weeklyRecurring")} min={2} w={60} />
166+
{t.labelRecurringRuleSuffix}
167+
</Group>
168+
)}
169+
143170
<Group justify="flex-end">
144171
{onDelete && (
145172
<Button onClick={onDelete} variant="outline" color="uzhOrange">

apps/frontend/src/routes/_auth/questionnaire/_questionnaire/$id/entries.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,15 @@ function QuestionnaireEntries() {
169169
open();
170170
}}
171171
eventClick={(args) => {
172-
const { carer, entryLanguages, id } = questionnaire.entries?.find((entry) => entry.id.toString() === args.event.id) ?? {};
172+
const { carer, entryLanguages, id, weeklyRecurring } =
173+
questionnaire.entries?.find((entry) => entry.id.toString() === args.event.id) ?? {};
173174

174175
setEntryDraft({
175176
carer: carer?.id,
176177
startedAt: getTime(args.event.start!),
177178
endedAt: getTime(args.event.end!),
178179
entryLanguages: entryLanguages?.map(({ language, ...rest }) => ({ ...rest, language: language.id })),
180+
weeklyRecurring,
179181
});
180182
setEntryUpdadingId(id);
181183
open();

libs/ui/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export {
6565
Select,
6666
type SelectProps,
6767
Stack,
68+
Switch,
6869
Table,
6970
Text,
7071
Textarea,

0 commit comments

Comments
 (0)