Skip to content

Commit

Permalink
Merge pull request #199 from openscript-ch/10-implement-entries-that-…
Browse files Browse the repository at this point in the history
…recure-in-weekly-periods

10 implement entries that recure in weekly periods
  • Loading branch information
openscript authored Dec 17, 2024
2 parents 76379f8 + 514bcf1 commit 2b9c43b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/wet-forks-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@quassel/frontend": patch
"@quassel/ui": patch
---

Introduce setting weeklyRecurring for entries
35 changes: 31 additions & 4 deletions apps/frontend/src/components/questionnaire/calendar/EntryForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Group, Stack, TimeInput, NumberInput, ActionIcon, IconMinus, isInRange, isNotEmpty, useForm } from "@quassel/ui";
import { Button, Group, Stack, TimeInput, NumberInput, ActionIcon, IconMinus, isInRange, isNotEmpty, useForm, Switch } from "@quassel/ui";
import { i18n } from "../../../stores/i18n";
import { useStore } from "@nanostores/react";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { CarerSelect } from "../../CarerSelect";
import { LanguageSelect } from "../../LanguageSelect";
import { components } from "../../../api.gen";
Expand All @@ -13,15 +13,20 @@ export type EntryFormValues = {
ratio: number;
language?: number;
}[];
weeklyRecurring?: number;
startedAt: string;
endedAt: string;
};

const messages = i18n("entityForm", {
actionAddDialect: "Add dialect",
actionAddLanguage: "Add language",
actionAddRecurringRule: "Add recurring rule",
actionDelete: "Delete",

labelCarer: "Carer",
labelLanguage: "Language",
labelRecurringRulePrefix: "Recurs every",
labelRecurringRuleSuffix: "weeks.",
validationRatio: "Ratio must be between 1 and 100.",
validationTotalRatio: "Total Ratio must always be 100%.",
validationNotEmpty: "Field must not be empty.",
Expand Down Expand Up @@ -67,10 +72,16 @@ export function EntityForm({ onSave, onDelete, onAddCarer, onAddLanguage, action
},
});

const [showRecurringRule, setShowRecurringRule] = useState(false);

useEffect(() => {
if (entry) {
f.setValues(entry);
f.resetDirty();

if (entry.weeklyRecurring && entry.weeklyRecurring > 1) {
setShowRecurringRule(true);
}
}
}, [entry]);

Expand Down Expand Up @@ -132,14 +143,30 @@ export function EntityForm({ onSave, onDelete, onAddCarer, onAddLanguage, action
}}
variant="light"
>
{t.actionAddDialect}
{t.actionAddLanguage}
</Button>
<Group>
<TimeInput flex={1} {...f.getInputProps("startedAt")} />
-
<TimeInput flex={1} {...f.getInputProps("endedAt")} />
</Group>

<Switch
checked={showRecurringRule}
onClick={() => {
f.setValues({ weeklyRecurring: showRecurringRule ? 1 : 2 });
setShowRecurringRule(!showRecurringRule);
}}
label={t.actionAddRecurringRule}
></Switch>
{showRecurringRule && (
<Group>
{t.labelRecurringRulePrefix}
<NumberInput {...f.getInputProps("weeklyRecurring")} min={2} w={60} />
{t.labelRecurringRuleSuffix}
</Group>
)}

<Group justify="flex-end">
{onDelete && (
<Button onClick={onDelete} variant="outline" color="uzhOrange">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,15 @@ function QuestionnaireEntries() {
open();
}}
eventClick={(args) => {
const { carer, entryLanguages, id } = questionnaire.entries?.find((entry) => entry.id.toString() === args.event.id) ?? {};
const { carer, entryLanguages, id, weeklyRecurring } =
questionnaire.entries?.find((entry) => entry.id.toString() === args.event.id) ?? {};

setEntryDraft({
carer: carer?.id,
startedAt: getTime(args.event.start!),
endedAt: getTime(args.event.end!),
entryLanguages: entryLanguages?.map(({ language, ...rest }) => ({ ...rest, language: language.id })),
weeklyRecurring,
});
setEntryUpdadingId(id);
open();
Expand Down
1 change: 1 addition & 0 deletions libs/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export {
Select,
type SelectProps,
Stack,
Switch,
Table,
Text,
Textarea,
Expand Down

0 comments on commit 2b9c43b

Please sign in to comment.