Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conflicting types in BookForm #18

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions frontend/src/components/bookForm/BookForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Book, NewBook} from "../../types/types.ts";
import {ChangeEvent, FormEvent} from "react";
import {BookWithoutId} from "../../types/types.ts";
import {ChangeEvent, Dispatch, FormEvent, SetStateAction} from "react";
import "./BookForm.css";

type BookFormProps = {
book: Book | NewBook,
setBook: (book: Book | NewBook) => void,
book: BookWithoutId,
setBook: Dispatch<SetStateAction<BookWithoutId>>,
handleSubmit: (event: FormEvent<HTMLFormElement>) => void,
action: string,
editable: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import "./ConfirmationModal.css";
import DeleteIcon from "../../assets/delete-svgrepo-com.svg";
import {Book} from "../../types/types.ts";
import {BookWithoutId} from "../../types/types.ts";

type ModalProps = {
handleClose: () => void,
handleDeleteConfirm: (id: string) => void,
bookToBeDeleted: Book
handleDeleteConfirm: () => void,
bookToBeDeleted: BookWithoutId
}

export default function ConfirmationModal ({handleClose, handleDeleteConfirm, bookToBeDeleted}: ModalProps) {
Expand All @@ -21,7 +21,7 @@ export default function ConfirmationModal ({handleClose, handleDeleteConfirm, bo
</div>
<div className={"modal-buttons"}>
<button className={"close-btn"} onClick={handleClose}>No, cancel</button>
<button className={"delete-btn"} onClick={() => handleDeleteConfirm(bookToBeDeleted.id)}>Yes, delete!</button>
<button className={"delete-btn"} onClick={handleDeleteConfirm}>Yes, delete!</button>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import "./BookDetailsPage.css";
import {Book} from "../../../types/types.ts";
import {Link, useNavigate, useParams} from "react-router-dom";
import axios from "axios";
import {FormEvent, useEffect, useState} from "react";
import BookForm from "../../../components/bookForm/BookForm.tsx";
import ConfirmationModal from "../../../components/confirmationModal/ConfirmationModal.tsx";
import {BookWithoutId} from "../../../types/types.ts";


type DeleteProps = {
deleteBook: (id: string) => void;
}

export default function BookDetailsPage({deleteBook}: Readonly<DeleteProps>) {
const [book, setBook] = useState<Book>({
const [book, setBook] = useState<BookWithoutId>({
title: "",
author: "",
id: "",
description: "",
genre: "",
isbn: "",
Expand Down Expand Up @@ -47,10 +46,12 @@ export default function BookDetailsPage({deleteBook}: Readonly<DeleteProps>) {
setShowDeleteModal(false)
}

const handleDeleteConfirm = (id: string) => {
deleteBook(id);
navigate("/books");
setShowDeleteModal(false);
const handleDeleteConfirm = () => {
if (id) {
deleteBook(id);
navigate("/books");
setShowDeleteModal(false);
}
}

const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FormEvent, useState} from "react";
import {NewBook} from "../../../../types/types.ts";
import {BookWithoutId} from "../../../../types/types.ts";
import axios from "axios";
import {useNavigate} from "react-router-dom";
import "./AddBookForm.css";
Expand All @@ -10,7 +10,7 @@ type FetchProps = {
}

export default function AddBookForm({fetchBooks}: Readonly<FetchProps>) {
const [book, setBook] = useState<NewBook>({
const [book, setBook] = useState<BookWithoutId>({
title: "",
author: "",
description: "",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type Book = {
publicationDate: string
}

export type NewBook = {
export type BookWithoutId = {
title: string,
author: string,
description: string,
Expand Down
Loading