Removed cron functionality completely

This commit is contained in:
Daniel Hougaard
2023-11-28 13:28:00 +04:00
parent d5c5495475
commit f187cc2c26
4 changed files with 45 additions and 31 deletions

View File

@@ -3,8 +3,6 @@ import { useForm } from "react-hook-form";
import { faClock } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { zodResolver } from "@hookform/resolvers/zod";
import { isValidCron } from "cron-validator";
import cronstrue from "cronstrue";
import { z } from "zod";
import { Button, FormControl, Input, Modal, ModalContent, TextArea } from "@app/components/v2";
@@ -14,8 +12,7 @@ const ReminderFormSchema = z.object({
days: z
.number()
.min(1, { message: "Must be at least 1 day" })
.max(365, { message: "Must be less than 365 days" }),
cron: z.string().refine(isValidCron, { message: "Invalid cron expression" })
.max(365, { message: "Must be less than 365 days" })
});
export type TReminderFormSchema = z.infer<typeof ReminderFormSchema>;
@@ -37,20 +34,11 @@ export const CreateReminderForm = ({ isOpen, onOpenChange }: ReminderFormProps)
});
const daysWatch = watch("days");
const cronWatch = watch("cron");
const handleFormSubmit = async (data: TReminderFormSchema) => {
onOpenChange(false, data);
};
useEffect(() => {
if (!daysWatch) {
setValue("cron", "");
} else {
setValue("cron", `0 0 */${daysWatch} * *`);
}
}, [daysWatch]);
useEffect(() => {
if (isOpen) {
reset();
@@ -65,8 +53,8 @@ export const CreateReminderForm = ({ isOpen, onOpenChange }: ReminderFormProps)
// ? Or should we be call it something more generic?
subTitle={
<div>
Set up a reminder for when this secret should be rotated. Everyone in the workspace will
be notified when the reminder is triggered.
Set up a reminder for when this secret should be rotated. Everyone with access to this
project will be notified when the reminder is triggered.
</div>
}
>
@@ -85,8 +73,10 @@ export const CreateReminderForm = ({ isOpen, onOpenChange }: ReminderFormProps)
placeholder="every 5 days"
/>
</FormControl>
{!!daysWatch && cronWatch && isValidCron(cronWatch) && (
<div className="mt-2 ml-1 text-xs opacity-60">{cronstrue.toString(cronWatch)}</div>
{!!daysWatch && (
<div className="mt-2 ml-1 text-xs opacity-60">
Every {daysWatch > 1 ? `${daysWatch} days` : "day"}
</div>
)}
</div>

View File

@@ -113,7 +113,7 @@ export const SecretItem = memo(
const overrideAction = watch("overrideAction");
const hasComment = Boolean(watch("comment"));
const hasReminder = Boolean(watch("reminderCron"));
const hasReminder = Boolean(watch("reminderRepeatDays"));
const selectedTags = watch("tags", []);
const selectedTagsGroupById = selectedTags.reduce<Record<string, boolean>>(
@@ -152,7 +152,9 @@ export const SecretItem = memo(
}
);
setValue("valueOverride", secret?.valueOverride, { shouldDirty: !isUnsavedOverride });
setValue("reminderCron", secret?.reminderCron, { shouldDirty: !isUnsavedOverride });
setValue("reminderRepeatDays", secret?.reminderRepeatDays, {
shouldDirty: !isUnsavedOverride
});
setValue("reminderNote", secret?.reminderNote, { shouldDirty: !isUnsavedOverride });
} else {
reset();
@@ -194,7 +196,7 @@ export const SecretItem = memo(
setCreateReminderFormOpen.toggle();
if (data) {
setValue("reminderCron", data.cron, { shouldDirty: true });
setValue("reminderRepeatDays", data.days, { shouldDirty: true });
setValue("reminderNote", data.note, { shouldDirty: true });
}
}}
@@ -390,7 +392,7 @@ export const SecretItem = memo(
if (!hasReminder) {
setCreateReminderFormOpen.on();
} else {
setValue("reminderCron", null, { shouldDirty: true });
setValue("reminderRepeatDays", null, { shouldDirty: true });
setValue("reminderNote", null, { shouldDirty: true });
}
}}

View File

@@ -122,7 +122,7 @@ export const SecretListView = ({
{
value,
comment,
reminderCron,
reminderRepeatDays,
reminderNote,
tags,
skipMultilineEncoding,
@@ -131,7 +131,7 @@ export const SecretListView = ({
}: Partial<{
value: string;
comment: string;
reminderCron: string | null;
reminderRepeatDays: number | null;
reminderNote: string | null;
tags: string[];
skipMultilineEncoding: boolean;
@@ -163,7 +163,7 @@ export const SecretListView = ({
latestFileKey: decryptFileKey,
tags,
secretComment: comment,
secretReminderCron: reminderCron,
secretReminderRepeatDays: reminderRepeatDays,
secretReminderNote: reminderNote,
skipMultilineEncoding,
newSecretName: newKey
@@ -194,16 +194,33 @@ export const SecretListView = ({
cb?: () => void
) => {
const { key: oldKey } = orgSecret;
const { key, value, overrideAction, idOverride, valueOverride, tags, comment, reminderCron, reminderNote } = modSecret;
const {
key,
value,
overrideAction,
idOverride,
valueOverride,
tags,
comment,
reminderRepeatDays,
reminderNote
} = modSecret;
const hasKeyChanged = oldKey !== key;
const tagIds = tags.map(({ _id }) => _id);
const oldTagIds = orgSecret.tags.map(({ _id }) => _id);
const isSameTags = JSON.stringify(tagIds) === JSON.stringify(oldTagIds);
const isSharedSecUnchanged =
(["key", "value", "comment", "skipMultilineEncoding", "reminderCron", "reminderNote"] as const).every(
(el) => orgSecret[el] === modSecret[el]
) && isSameTags;
(
[
"key",
"value",
"comment",
"skipMultilineEncoding",
"reminderRepeatDays",
"reminderNote"
] as const
).every((el) => orgSecret[el] === modSecret[el]) && isSameTags;
try {
// personal secret change
@@ -228,7 +245,7 @@ export const SecretListView = ({
value,
tags: tagIds,
comment,
reminderCron,
reminderRepeatDays,
reminderNote,
secretId: orgSecret._id,
newKey: hasKeyChanged ? key : undefined,
@@ -313,7 +330,7 @@ export const SecretListView = ({
<div className="flex flex-col" key={`${namespace}-${groupedSecrets.length}`}>
<div
className={twMerge(
"bg-bunker-600 capitalize text-md h-0 transition-all",
"text-md h-0 bg-bunker-600 capitalize transition-all",
Boolean(namespace) && Boolean(filteredSecrets.length) && "h-11 py-3 pl-4 "
)}
key={namespace}

View File

@@ -21,7 +21,12 @@ export const formSchema = z.object({
comment: z.string().trim().optional(),
skipMultilineEncoding: z.boolean().optional(),
reminderCron: z.string().trim().nullable().optional(),
reminderRepeatDays: z
.number()
.min(1, { message: "Days must be between 1 and 365" })
.max(365, { message: "Days must be between 1 and 365" })
.nullable()
.optional(),
reminderNote: z.string().trim().nullable().optional(),
tags: z