Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jennymar committed Jun 29, 2024
1 parent 6c39cf9 commit 9f612d1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 70 deletions.
63 changes: 2 additions & 61 deletions frontend/src/components/EventSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import React, { useState } from "react";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";

import { CreateEventDetailsRequest, EventDetails, deleteEventDetails } from "../api/eventDetails";
import { CreateEventDetailsRequest, EventDetails } from "../api/eventDetails";

import styles from "./EventSidebar.module.css";
import { TextArea } from "./TextArea";
import { TextAreaCharLimit } from "./TextAreaCharLimit";
import { TextFieldCharLimit } from "./TextFieldCharLimit";

import AlertBanner from "@/components/AlertBanner";
import { TextField } from "@/components/TextField";
import { WarningModule } from "@/components/WarningModule";
import { TextArea } from "./TextArea";

type eventSidebarProps = {
eventDetails: null | EventDetails;
Expand Down Expand Up @@ -53,7 +53,6 @@ const EventSidebar = ({
const [isEditing, setIsEditing] = useState<boolean>(!eventDetails);
const [isDeleting, setIsDeleting] = useState<boolean>(false);
const [errors, setErrors] = useState<formErrors>({});
const [warningOpen, setWarningOpen] = useState(false);
const [showAlert, setShowAlert] = useState(false);

const confirmCancel = () => {
Expand All @@ -68,51 +67,10 @@ const EventSidebar = ({
setIsEditing(false);
setIsDeleting(false);
setErrors({});
setWarningOpen(false);
setSidebarOpen(false);
};

const handleCancel = () => {
const defaultDate = new Date();
if (
name !== (eventDetails ? eventDetails.name : "") ||
description !== (eventDetails ? eventDetails.description : "") ||
description_short !== (eventDetails ? eventDetails.description_short : "") ||
date !== (eventDetails ? new Date(eventDetails.date) : defaultDate) ||
startTime !== (eventDetails ? eventDetails.startTime : "") ||
endTime !== (eventDetails ? eventDetails.endTime : "") ||
location !== (eventDetails ? eventDetails.location : "") ||
guidelines !== (eventDetails ? eventDetails.guidelines : "")
) {
setWarningOpen(true);
} else {
confirmCancel();
}
};

const handleCloseSidebar = () => {
const defaultDate = new Date();
if (
name !== (eventDetails ? eventDetails.name : "") ||
description !== (eventDetails ? eventDetails.description : "") ||
description_short !== (eventDetails ? eventDetails.description_short : "") ||
date !== (eventDetails ? new Date(eventDetails.date) : defaultDate) ||
startTime !== (eventDetails ? eventDetails.startTime : "") ||
endTime !== (eventDetails ? eventDetails.endTime : "") ||
location !== (eventDetails ? eventDetails.location : "") ||
guidelines !== (eventDetails ? eventDetails.guidelines : "")
) {
setWarningOpen(true);
} else {
confirmCancel();
setSidebarOpen(false);
}
};

const handleSave = async () => {
setWarningOpen(false);
console.log("handleSave");

if (
name === "" ||
description === "" ||
Expand Down Expand Up @@ -178,23 +136,6 @@ const EventSidebar = ({
setIsDeleting(true);
};

const confirmDelete = () => {
if (eventDetails) {
deleteEventDetails(eventDetails._id)
.then((result) => {
if (result.success) {
window.location.reload();
} else {
console.error("ERROR:", result.error);
}
})
.catch((error) => {
alert(error);
});
setSidebarOpen(false);
}
};

const alertContent = {
text: "Event Saved!",
};
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/NewsletterSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { CreateNewsletterRequest, Newsletter, deleteNewsletter } from "../api/ne

import AlertBanner from "./AlertBanner";
import styles from "./NewsletterSidebar.module.css";
import { TextArea } from "./TextArea";
import { TextField } from "./TextField";
import { WarningModule } from "./WarningModule";
import SimpleImageDropzone from "./admin/storage/SimpleImageDropzone";

import { deleteFile } from "@/app/admin/util/pageeditUtil";
import { TextArea } from "./TextArea";

type newsletterSidebarProps = {
newsletter: null | Newsletter;
Expand Down Expand Up @@ -93,22 +93,22 @@ const NewsletterSidebar = ({
};

// handle changing url on newsletter to "" if user deletes image
const onImageDelete = () => {
const onImageDelete = async () => {
setImage("");
// immediately update newsletter, can't undo image delete
if (newsletter) {
updateNewsletter({
await updateNewsletter({
...newsletter,
image: "",
});
}
};

// handle updating image on image dropzone upload
const onImageUpload = (url: string) => {
const onImageUpload = async (url: string) => {
// can't undo image upload, save immediately
if (newsletter) {
updateNewsletter({
await updateNewsletter({
...newsletter,
image: url,
});
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/TextAreaCharLimit.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from "react";

import { CharacterCount } from "@/components/CharacterCount";
import { TextArea } from "./TextArea";

import { CharacterCount } from "@/components/CharacterCount";

export type TextAreaCharLimitProps = {
label: string;
id: string;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/WarningModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type WarningModuleProps = {
cancelText: string;
actionText: string;
cancel?: () => void;
action: () => void;
action: () => unknown;
children: ReactNode;
};

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/admin/storage/SimpleImageDropzone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type ImageDropProps = {
folder: string;
url: string;
setUrl: (url: string) => void;
onDelete?: () => void;
onUpload?: (url: string) => void;
onDelete?: () => unknown;
onUpload?: (url: string) => unknown;
};

export default function SimpleImageDropzone({
Expand Down

0 comments on commit 9f612d1

Please sign in to comment.