Skip to content

Commit

Permalink
fix(web): digests form ux
Browse files Browse the repository at this point in the history
  • Loading branch information
waltergalvao committed Jan 30, 2025
1 parent 43fea47 commit 2b1e0b0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import {
Stack,
Title,
Switch,
TextInput,
Divider,
Select,
Box,
InputLabel,
Chip,
Group,
Input,
Text,
} from "@mantine/core";
import { DigestFrequency } from "@sweetr/graphql-types/api";
import { IconBrandSlack, IconClock, IconWorld } from "@tabler/icons-react";
import { IconClock, IconInfoCircle, IconWorld } from "@tabler/icons-react";
import { BoxSetting } from "../../../../../../../components/box-setting";
import { SelectHour } from "../../../../../../../components/select-hour";
import { SelectTimezone } from "../../../../../../../components/select-timezone/select-timezone";
Expand Down Expand Up @@ -51,14 +52,34 @@ export const DigestBaseFields = ({ form }: DigestBaseFieldsProps) => {
</BoxSetting>

{isEnabled && (
<TextInput
ref={channelRef}
label="Channel"
leftSection={<IconBrandSlack stroke={1} />}
placeholder="#team"
{...form.getInputProps("channel")}
/>
<>
<Input.Wrapper>
<Input.Label required>Channel</Input.Label>
<Group align="top">
<Stack gap="5px" flex="1">
<Input
ref={channelRef}
leftSection={<>#</>}
flex="1"
{...form.getInputProps("channel")}
/>
{form.getInputProps("channel").error && (
<Input.Error>
{form.getInputProps("channel").error}
</Input.Error>
)}
</Stack>
</Group>
</Input.Wrapper>
</>
)}
<Group gap={5}>
<IconInfoCircle size={16} stroke={1.5} />
<Text c="dimmed" size="xs">
Tip: Sweetr is only able to auto join public channels. You must
manually invite @Sweetr to private channels.
</Text>
</Group>
</Stack>

{isEnabled && (
Expand All @@ -69,7 +90,8 @@ export const DigestBaseFields = ({ form }: DigestBaseFieldsProps) => {
<Title order={5}>Schedule</Title>

<Select
label="DigestFrequency"
required
label="Frequency"
data={[
{ value: DigestFrequency.WEEKLY, label: "Every week" },
{
Expand All @@ -93,7 +115,7 @@ export const DigestBaseFields = ({ form }: DigestBaseFieldsProps) => {
}}
/>
<Box>
<InputLabel>Day of the week</InputLabel>
<InputLabel required>Day of the week</InputLabel>
<Chip.Group
value={form.values.dayOfTheWeek}
onChange={(value) => {
Expand Down Expand Up @@ -134,11 +156,13 @@ export const DigestBaseFields = ({ form }: DigestBaseFieldsProps) => {
</Box>
<Group grow>
<SelectHour
required
{...form.getInputProps("timeOfDay")}
label="Time"
leftSection={<IconClock size={16} stroke={1.5} />}
/>
<SelectTimezone
required
{...form.getInputProps("timezone", { type: "input" })}
label="Timezone"
leftSection={<IconWorld size={16} stroke={1.5} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const TeamMetricsDigestPage = () => {
}, [digestQuery.isFetched]);

// eslint-disable-next-line react-hooks/exhaustive-deps
const isFormValid = useMemo(() => form.isValid(), [form.values]);
const isFormValid = useMemo(() => !form.validate().hasErrors, [form.values]);

const handleSave: FormEventHandler = async (event) => {
event.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const TeamWipDigestPage = () => {
}, [digestQuery.isFetched]);

// eslint-disable-next-line react-hooks/exhaustive-deps
const isFormValid = useMemo(() => form.isValid(), [form.values]);
const isFormValid = useMemo(() => !form.validate().hasErrors, [form.values]);

const handleSave: FormEventHandler = async (event) => {
event.preventDefault();
Expand Down
7 changes: 6 additions & 1 deletion apps/web/src/app/teams/[id]/digests/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { z } from "zod";

export const FormDigest = z.object({
enabled: z.boolean(),
channel: z.string().min(1),
channel: z
.string()
.min(1, "Field is required")
.refine((val) => !val.startsWith("#"), {
message: "Channel should not start with #",
}),
frequency: z.nativeEnum(DigestFrequency),
dayOfTheWeek: z.array(z.nativeEnum(DayOfTheWeek)).min(1),
timeOfDay: z.string().min(1),
Expand Down

0 comments on commit 2b1e0b0

Please sign in to comment.