Skip to content

Commit

Permalink
feat: 도서관리 - 기부자 수정 항목 부분 추가(#516-도서-수정항목-추가)
Browse files Browse the repository at this point in the history
백엔드에 book/donator로 기부자 수정 url이 있어서 해당 url로 테스트.
-> 백엔드에서도 수정해야 할 부분 있음.
도서 수정시 요청을 두 개로 나누어서 보내야 하고, 추후 변경예정인 부분이 있어 보류
  • Loading branch information
mink97 committed Oct 30, 2023
1 parent 1b5c241 commit a64ceb2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
24 changes: 2 additions & 22 deletions src/api/books/useGetBooksSearch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useEffect } from "react";
import { useApi } from "../../hook/useApi";
import { useSearch } from "../../hook/useSearch";
import { compareExpect } from "../../util/typeCheck";
import { Book } from "../../type";

export const useGetBooksSearch = ({ limit }: { limit: number }) => {
Expand All @@ -14,28 +13,9 @@ export const useGetBooksSearch = ({ limit }: { limit: number }) => {
limit,
});

const expectedItem = [
{ key: "bookId", type: "number", isNullable: false },
{ key: "bookInfoId", type: "number", isNullable: false },
{ key: "status", type: "number", isNullable: false },
{ key: "title", type: "string", isNullable: false },
{ key: "author", type: "string", isNullable: false },
{ key: "category", type: "string", isNullable: false },
{ key: "categoryId", type: "number", isNullable: false },
{ key: "isbn", type: "string", isNullable: true },
{ key: "publisher", type: "string", isNullable: false },
{ key: "publishedAt", type: "string", isNullable: true },
{ key: "callSign", type: "string", isNullable: false },
{ key: "image", type: "string", isNullable: true },
{ key: "isLendable", type: "bool", isNullable: false },
];

const refineResponse = (response: any) => {
const book = compareExpect(
"books/search",
response.data.items,
expectedItem,
);
const book = response.data.items;

const { totalPages } = response.data.meta;
setSearchResult({
list: book,
Expand Down
2 changes: 1 addition & 1 deletion src/api/books/usePatchBooksUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Props = {
export const usePatchBooksUpdate = ({ bookTitle, closeModal }: Props) => {
const [change, setChange] = useState<Partial<Book>>();

const { request } = useApi("patch", "books/update", {
const { request } = useApi("patch", "books/donator", {
...change,
categoryId: change?.categoryId ? change.categoryId + 1 : undefined, // DB에는 1부터 저장되어 있으므로 +1
});
Expand Down
10 changes: 10 additions & 0 deletions src/component/bookManagement/BookManagementModalDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const BookManagementModalDetail = ({ book, closeModal }: Props) => {
const callSignRef = useRef<HTMLInputElement>(null);
const statusRef = useRef<HTMLSelectElement>(null);
const categoryRef = useRef<HTMLSelectElement>(null);
const donatorRef = useRef<HTMLInputElement>(null);

const { setChange } = usePatchBooksUpdate({
bookTitle: book.title,
Expand Down Expand Up @@ -57,6 +58,7 @@ const BookManagementModalDetail = ({ book, closeModal }: Props) => {
modifyFromRef("callSign", callSignRef);
modifyFromRef("categoryId", categoryRef);
modifyFromRef("status", statusRef);
modifyFromRef("donator", donatorRef);
change.categoryId = Number(change.categoryId);
change.category = category[change.categoryId].name;
return change;
Expand All @@ -68,6 +70,7 @@ const BookManagementModalDetail = ({ book, closeModal }: Props) => {
const callSignRegex = /^[A-Za-z][0-9]{1,3}\.[0-9]{2}\.v[1-9]\.c[1-9]$/;
const isbnRegex = /^\d{13}$/;

console.dir(change);
const categoryToChange = change.callSign[0];
const isValidDate =
change.publishedAt && dateRegex.test(change.publishedAt);
Expand Down Expand Up @@ -195,6 +198,13 @@ const BookManagementModalDetail = ({ book, closeModal }: Props) => {
optionList={bookStatus.map(status => status.string)}
initialSelectedIndex={book.status}
/>
<InputWithLabel
labelText="도서 기증자"
disabled={!editMode}
ref={donatorRef}
resetDependency={reset}
inputInitialValue={book.donator}
/>
</div>
</div>
{message ? (
Expand Down

0 comments on commit a64ceb2

Please sign in to comment.