Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 8db475a

Browse files
committed
feat: repo settings for schedule and frequency
1 parent 0868a27 commit 8db475a

File tree

3 files changed

+107
-18
lines changed

3 files changed

+107
-18
lines changed

src/app/account/repo/settings/[id]/form.js

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,87 @@
33
import { useFormState } from "react-dom";
44
import { useFlags } from "flagsmith/react";
55

6-
import config from "@/config/app.json";
76
import { saveSettings } from "./action";
87
import { SubmitButton } from "@/components/forms/SubmitButton";
98
import Input from "@/components/forms/Input";
109
import Checkbox from "@/components/forms/Checkbox";
10+
import Select from "@/components/forms/Select";
1111

1212
const initialState = {
13-
data: undefined,
13+
ignore: undefined,
1414
success: undefined,
1515
errors: undefined,
1616
};
1717

18-
export default function Form({ id, data, disabled = false }) {
18+
export default function Form({ id, ignore, schedule, disabled = false }) {
1919
let { optionalchecks } = useFlags(["optionalchecks"]);
2020
optionalchecks = JSON.parse(optionalchecks.value);
2121
const [state, formAction] = useFormState(saveSettings, initialState);
2222

2323
return (
2424
<form action={formAction}>
2525
<Input type="hidden" id="id" name="id" value={id} />
26-
<div className="space-y-12">
27-
<div className="border-b border-gray-900/10 pb-12">
26+
27+
<div className="border-b border-gray-700 pb-12 pt-4">
28+
<div className="border-b border-gray-900/10">
2829
<p className="mt-1 text-sm leading-6 text-gray-300">
29-
Hide any checks you wish to ignore.
30+
What checks do you wish to ignore from your report?
3031
</p>
3132
</div>
33+
34+
<fieldset>
35+
<legend className="text-sm font-semibold leading-6">
36+
Hide these checks
37+
</legend>
38+
{optionalchecks?.map((option) => (
39+
<div className="mt-2" key={option.id}>
40+
<Checkbox
41+
id={option.id}
42+
name={option.id}
43+
text={option.name}
44+
value={true}
45+
disabled={disabled}
46+
defaultChecked={ignore.includes(option.id)}
47+
/>
48+
</div>
49+
))}
50+
</fieldset>
3251
</div>
3352

34-
<fieldset>
35-
<legend className="text-sm font-semibold leading-6">Checks</legend>
36-
{optionalchecks?.map((option) => (
37-
<div className="mt-6 space-y-6" key={option.id}>
53+
<div className="border-b border-gray-700 pb-12 pt-4">
54+
<fieldset className="mb-6">
55+
<legend className="text-sm font-semibold leading-6">Automate</legend>
56+
<div className="mt-2">
3857
<Checkbox
39-
id={option.id}
40-
name={option.id}
41-
text={option.name}
58+
id="schedule"
59+
name="schedule"
60+
text="Schedule"
4261
value={true}
43-
disabled={disabled}
44-
defaultChecked={data.includes(option.id)}
62+
disabled={true}
63+
defaultChecked={true}
4564
/>
4665
</div>
47-
))}
48-
</fieldset>
66+
</fieldset>
67+
<fieldset>
68+
<legend className="text-sm font-semibold leading-6">Frequency</legend>
69+
<div className="mt-2">
70+
<Select
71+
id="schedule"
72+
name="schedule"
73+
text="How often to perform these checks? (days)"
74+
options={[
75+
{ text: "1 day", value: 1 },
76+
{ text: "7 days", value: 7 },
77+
{ text: "30 days", value: 30 },
78+
]}
79+
value={7}
80+
disabled={true}
81+
// defaultChecked={schedule}
82+
classNameSelect="max-w-32"
83+
/>
84+
</div>
85+
</fieldset>
86+
</div>
4987

5088
<div className="mt-6 flex items-center justify-end gap-x-6">
5189
<SubmitButton text="SAVE" />

src/app/account/repo/settings/[id]/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default async function Page({ params }) {
3030
Repo Check List
3131
</Button>
3232
</Title>
33-
<Form id={id} data={repository.ignoreChecks} />
33+
<Form id={id} ignore={repository.ignoreChecks} />
3434
</>
3535
);
3636
}

src/components/forms/Select.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import classNames from "@/utils/classNames";
2+
import { useFormStatus } from "react-dom";
3+
4+
export default function Select({
5+
id,
6+
name,
7+
text,
8+
options,
9+
value,
10+
disabled,
11+
defaultValue,
12+
classNameSelect,
13+
}) {
14+
const { pending } = useFormStatus();
15+
16+
if (!name) {
17+
name = id;
18+
}
19+
20+
if (!text) {
21+
text = name;
22+
}
23+
24+
return (
25+
<div>
26+
<label htmlFor={name} className="block text-sm font-medium leading-6">
27+
{text}
28+
</label>
29+
<select
30+
id={id}
31+
name={name}
32+
defaultValue={defaultValue}
33+
disabled={disabled}
34+
className={classNames(
35+
"mt-2 block w-full rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6 disabled:bg-gray-600",
36+
classNameSelect,
37+
)}
38+
>
39+
{options?.map((option) => (
40+
<option
41+
value={option.value}
42+
key={option.value}
43+
selected={option.value === value}
44+
>
45+
{option.text}
46+
</option>
47+
))}
48+
</select>
49+
</div>
50+
);
51+
}

0 commit comments

Comments
 (0)