Skip to content

Commit

Permalink
chore: address review
Browse files Browse the repository at this point in the history
  • Loading branch information
waltergalvao committed Sep 22, 2024
1 parent 5cddce9 commit 0a5957e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export const FormPrSizeLabelerSettings = ({

{form.values.enabled &&
(
Object.keys(form.values.settings) as Array<
keyof typeof form.values.settings
Object.keys(form.values.settings.labels) as Array<
keyof typeof form.values.settings.labels
>
).map((size) => (
<BoxSetting
Expand All @@ -41,15 +41,15 @@ export const FormPrSizeLabelerSettings = ({
<Input
maw={140}
placeholder={size}
{...form.getInputProps(`settings.${size}.label`)}
{...form.getInputProps(`settings.labels.${size}.label`)}
maxLength={100}
></Input>
<ColorInput
placeholder="#F0F0F0"
error={false}
swatches={colorPickerSwatches}
swatchesPerRow={7}
{...form.getInputProps(`settings.${size}.color`)}
{...form.getInputProps(`settings.labels.${size}.color`)}
maw={120}
withEyeDropper={false}
/>
Expand Down
54 changes: 27 additions & 27 deletions apps/web/src/app/automations/settings/pr-size-labeler/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import { useForm, zodResolver } from "@mantine/form";
import { useEffect, useMemo, FormEventHandler } from "react";
import { useDrawerPage } from "../../../../providers/drawer-page.provider";
import { FormPrSizeLabeler } from "./types";
import { useNavigate } from "react-router-dom";

export const AutomationPrSizeLabelerPage = () => {
const navigate = useNavigate();
const { automation, automationSettings, query, mutation, mutate } =
useAutomationSettings(AutomationType.PR_SIZE_LABELER);

Expand All @@ -26,29 +24,35 @@ export const AutomationPrSizeLabelerPage = () => {
});

useEffect(() => {
const settings = automationSettings?.settings as any;
const settings = automationSettings?.settings as
| FormPrSizeLabeler["settings"]
| undefined
| null;

form.setValues({
enabled: automationSettings?.enabled || false,
settings: {
tiny: {
label: settings?.labels?.tiny?.label || "tiny",
color: settings?.labels?.tiny?.color || "#69db7c",
},
small: {
label: settings?.labels?.small?.label || "small",
color: settings?.labels?.small?.color || "#69db7c",
},
medium: {
label: settings?.labels?.medium?.label || "medium",
color: settings?.labels?.medium?.color || "#a6a7ab",
},
large: {
label: settings?.labels?.large?.label || "large",
color: settings?.labels?.large?.color || "#ff8787",
},
huge: {
label: settings?.labels?.huge?.label || "huge",
color: settings?.labels?.huge?.color || "#ff8787",
labels: {
tiny: {
label: settings?.labels?.tiny?.label || "tiny",
color: settings?.labels?.tiny?.color || "#69db7c",
},
small: {
label: settings?.labels?.small?.label || "small",
color: settings?.labels?.small?.color || "#69db7c",
},
medium: {
label: settings?.labels?.medium?.label || "medium",
color: settings?.labels?.medium?.color || "#a6a7ab",
},
large: {
label: settings?.labels?.large?.label || "large",
color: settings?.labels?.large?.color || "#ff8787",
},
huge: {
label: settings?.labels?.huge?.label || "huge",
color: settings?.labels?.huge?.color || "#ff8787",
},
},
},
});
Expand All @@ -67,8 +71,6 @@ export const AutomationPrSizeLabelerPage = () => {
settings: form.values.settings,
enabled: form.values.enabled,
});

navigate("/automations");
};

return (
Expand All @@ -86,9 +88,7 @@ export const AutomationPrSizeLabelerPage = () => {
</Title>
</Group>
}
toolbar={
<>{automation.docsUrl && <ButtonDocs href={automation.docsUrl} />}</>
}
toolbar={automation.docsUrl && <ButtonDocs href={automation.docsUrl} />}
actions={
<Button
type="submit"
Expand Down
40 changes: 21 additions & 19 deletions apps/web/src/app/automations/settings/pr-size-labeler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@ import { mustBeHexadecimal } from "../../../../providers/zod-rules.provider";
export const FormPrSizeLabeler = z.object({
enabled: z.boolean(),
settings: z.object({
tiny: z.object({
label: z.string().min(1),
color: mustBeHexadecimal,
}),
small: z.object({
label: z.string().min(1),
color: mustBeHexadecimal,
}),
medium: z.object({
label: z.string().min(1),
color: mustBeHexadecimal,
}),
large: z.object({
label: z.string().min(1),
color: mustBeHexadecimal,
}),
huge: z.object({
label: z.string().min(1),
color: mustBeHexadecimal,
labels: z.object({
tiny: z.object({
label: z.string().min(1),
color: mustBeHexadecimal,
}),
small: z.object({
label: z.string().min(1),
color: mustBeHexadecimal,
}),
medium: z.object({
label: z.string().min(1),
color: mustBeHexadecimal,
}),
large: z.object({
label: z.string().min(1),
color: mustBeHexadecimal,
}),
huge: z.object({
label: z.string().min(1),
color: mustBeHexadecimal,
}),
}),
}),
});
Expand Down
17 changes: 8 additions & 9 deletions apps/web/src/app/automations/settings/pr-title-check/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import { ButtonDocs } from "../../../../components/button-docs";
import { useForm, zodResolver } from "@mantine/form";
import { FormEventHandler, useEffect, useMemo } from "react";
import { FormPrTitleCheck } from "./types";
import { useNavigate } from "react-router-dom";
import { HeaderAutomation } from "../components/header-automation";

export const AutomationPrTitleCheckPage = () => {
const navigate = useNavigate();
const { automation, automationSettings, query, mutation, mutate } =
useAutomationSettings(AutomationType.PR_TITLE_CHECK);

Expand All @@ -26,11 +24,16 @@ export const AutomationPrTitleCheckPage = () => {
});

useEffect(() => {
const settings = automationSettings?.settings as
| FormPrTitleCheck["settings"]
| undefined
| null;

form.setValues({
enabled: automationSettings?.enabled || false,
settings: {
regex: (automationSettings?.settings as any)?.regex || "",
regexExample: (automationSettings?.settings as any)?.regexExample || "",
regex: settings?.regex || "",
regexExample: settings?.regexExample || "",
},
});
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -48,8 +51,6 @@ export const AutomationPrTitleCheckPage = () => {
settings: form.values.settings,
enabled: form.values.enabled,
});

navigate("/automations");
};

return (
Expand All @@ -67,9 +68,7 @@ export const AutomationPrTitleCheckPage = () => {
</Title>
</Group>
}
toolbar={
<>{automation.docsUrl && <ButtonDocs href={automation.docsUrl} />}</>
}
toolbar={automation.docsUrl && <ButtonDocs href={automation.docsUrl} />}
actions={
<Button
type="submit"
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/app/automations/settings/use-automation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
showErrorNotification,
} from "../../../providers/notification.provider";
import { useAutomationCards } from "../use-automation-cards";
import { useNavigate } from "react-router-dom";

export const useAutomationSettings = (type: AutomationType) => {
const navigate = useNavigate();
const { workspace } = useWorkspace();
const { automationCards } = useAutomationCards();
const automation = automationCards[type];
Expand All @@ -22,6 +24,8 @@ export const useAutomationSettings = (type: AutomationType) => {
showSuccessNotification({
message: `Automation settings updated.`,
});

navigate("/automations");
},
onError: () => {
showErrorNotification({
Expand Down
15 changes: 0 additions & 15 deletions apps/web/src/app/settings/integrations/slack/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,6 @@ export const IntegrationSlackPage = () => {
</Title>
</Group>
}
toolbar={
<Anchor
underline="never"
target="_blank"
href="https://docs.sweetr.dev"
>
<Button
variant="subtle"
color="dark.1"
leftSection={<IconBook2 stroke={1.5} size={20} />}
>
Docs
</Button>
</Anchor>
}
actions={
<>
{integration && !integration?.isEnabled && integration.installUrl && (
Expand Down

0 comments on commit 0a5957e

Please sign in to comment.