Skip to content

Commit

Permalink
Merge pull request #246 from fdhhhdjd/bao_fe
Browse files Browse the repository at this point in the history
Bao fe
  • Loading branch information
fdhhhdjd authored Mar 30, 2023
2 parents fe9a984 + 4088230 commit 2a76a02
Show file tree
Hide file tree
Showing 14 changed files with 724 additions and 19 deletions.
8 changes: 8 additions & 0 deletions frontend-manager-cms/src/api/api_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const API_ADMIN = {
CREATE_BOOK_CMS: '/manager/v1/admin/private/book/create',
DELETE_BOOK_CMS: '/manager/v1/admin/private/book/delete',

//! borrow book api
GET_ALL_BORROW_CMS: '/manager/v1/admin/private/borrow_book/all',
GET_DETAIL_BORROW_CMS: '/manager/v1/admin/private/borrow_book/detail',
// CREATE_BORROW_CMS: '/manager/v1/admin/private/book/create',
// DELETE_BORROW_CMS: '/manager/v1/admin/private/book/delete',
EDIT_BORROW_CMS: '/manager/v1/admin/private/borrow_book/update',

//! author api
GET_ALL_AUTHOR_CMS: '/manager/v1/admin/private/author/all',
GET_DETAIL_AUTHOR_CMS: '/manager/v1/admin/private/author/detail',
Expand All @@ -19,6 +26,7 @@ const API_ADMIN = {
//! student api
GET_ALL_ACCOUNT_CMS: '/manager/v1/admin/private/student/all',
GET_DETAIL_ACCOUNT_CMS: '/manager/v1/admin/private/student/detail',
EDIT_ACCOUNT_CMS: '/manager/v1/admin/private/student/update',
CREATE_ACCOUNT_CMS: '/manager/v1/admin/private/student/create',
DELETE_ACCOUNT_CMS: '/manager/v1/admin/private/student/delete',
};
Expand Down
19 changes: 17 additions & 2 deletions frontend-manager-cms/src/pages/Account/EditUser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useDispatch, useSelector } from 'react-redux';
import SelectBox from 'components/SelectBox';
import Calendar from 'react-calendar';
import { useParams } from 'react-router-dom';
import { Get_Detail_Account_Cms_Initial } from 'redux/managers/student_slice/student_thunk';
import { Edit_Account_Cms_Initial, Get_Detail_Account_Cms_Initial } from 'redux/managers/student_slice/student_thunk';
import { classOption, genderOption } from 'utils/dummy';
import HELPERS from 'utils/helper';

Expand Down Expand Up @@ -38,7 +38,17 @@ const EditUser = () => {
console.log({
...data,
dob: moment(dob || detail?.dob).format('YYYYMMDD'),
gender: gender || detail?.gender,
class_room: classroom || detail?.class,
});
dispatch(
Edit_Account_Cms_Initial({
...data,
dob: moment(dob || detail?.dob).format('YYYYMMDD'),
gender: gender || detail?.gender,
class_room: classroom || detail?.class,
}),
);
};

useEffect(() => {
Expand Down Expand Up @@ -97,7 +107,12 @@ const EditUser = () => {
<label className="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" htmlFor="gender">
Giới tính
</label>
{detail?.gender && (
{console.log({
value: detail?.gender,
label: HELPERS.getGenderLabel(detail?.gender),
})}

{detail?.gender >= 0 && (
<SelectBox
optionData={genderOption}
defaultValue={{
Expand Down
3 changes: 1 addition & 2 deletions frontend-manager-cms/src/pages/Author/EditAuthor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ const EditAuthor = () => {
setGender={setGender}
setNation={setNation}
setDob={setDob}
dob={dob}
defaultDob={new Date(moment(detail?.dob).format())}
dob={new Date(moment(detail?.dob).format())}
/>
)}
</>
Expand Down
27 changes: 17 additions & 10 deletions frontend-manager-cms/src/pages/Author/components/AuthorForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const AuthorForm = (props) => {
id="name"
type="text"
placeholder="Gia Bảo..."
defaultValue={props.defaultData.name}
defaultValue={props.defaultData?.name}
{...register('name', {
required: true,
})}
Expand All @@ -68,12 +68,12 @@ const AuthorForm = (props) => {
<label className="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" htmlFor="gender">
Giới tính
</label>
{props.defaultData.gender >= 0 ? (
{props.defaultData?.gender >= 0 ? (
<SelectBox
optionData={genderOption}
defaultValue={{
value: props.defaultData.gender,
label: HELPERS.getGenderLabel(props.defaultData.gender),
value: props.defaultData?.gender,
label: HELPERS.getGenderLabel(props.defaultData?.gender),
}}
setData={props.setGender}
/>
Expand All @@ -85,12 +85,12 @@ const AuthorForm = (props) => {
<label className="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" htmlFor="nation">
Quốc gia
</label>
{props.defaultData.nation ? (
{props.defaultData?.nation ? (
<SelectBox
optionData={nationOption}
defaultValue={{
value: props.defaultData.nation,
label: props.defaultData.nation,
value: props.defaultData?.nation,
label: props.defaultData?.nation,
}}
setData={props.setNation}
/>
Expand All @@ -105,8 +105,8 @@ const AuthorForm = (props) => {
Ngày sinh
</label>
<div className="date-picker">
{props.defaultData.dob ? (
<Calendar defaultValue={props.defaultData.defaultDob} onChange={props.setDob} value={props.dob} />
{props.defaultData?.dob ? (
<Calendar defaultValue={props.defaultData?.dob} onChange={props.setDob} value={props.dob} />
) : (
<Calendar onChange={props.setDob} value={props.dob} />
)}
Expand All @@ -131,7 +131,14 @@ const AuthorForm = (props) => {
<div className="w-full px-3">
<div className="profile__info__image">
<div className="profile__info__image__preview">
{loading_media ? <Loading /> : <img src={result_upload?.result?.url || defaultImageAuthor} alt="" />}
{loading_media ? (
<Loading />
) : (
<img
src={result_upload?.result?.url || props.defaultData?.avatar_uri || defaultImageAuthor}
alt=""
/>
)}
</div>
{!props.readOnly && (
<>
Expand Down
8 changes: 4 additions & 4 deletions frontend-manager-cms/src/pages/Book/EditBook.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ const EditBook = () => {

console.log('re render');

useEffect(() => {
dispatch(Get_Detail_Book_Cms_Initial({ book_id: id }));
}, [dispatch, id]);

useEffect(() => {
setPreview(detailBook?.image_uri);
}, [detailBook]);
Expand All @@ -44,6 +40,10 @@ const EditBook = () => {
return () => URL.revokeObjectURL(objectUrl);
}, [selectedFile, detailBook?.image_uri]);

useEffect(() => {
dispatch(Get_Detail_Book_Cms_Initial({ book_id: id }));
}, [dispatch, id]);

useEffect(() => {
setDetai(detailBook);
}, [detailBook]);
Expand Down
219 changes: 219 additions & 0 deletions frontend-manager-cms/src/pages/BorrowBook/AllBorrowBook.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
//! LIBRARY
import moment from 'moment';
import React, { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Link } from 'react-router-dom';

//! REDUX THUNK
import { Delete_Book_Cms_Initial, Get_All_Book_Cms_Initial } from 'redux/managers/book_slice/book_thunk';
import { Get_All_Borrow_Cms_Initial } from 'redux/managers/borrow_slice/borrow_thunk';
import HELPERS from 'utils/helper';

const AllBorrowBook = () => {
const dispatch = useDispatch();
const borrowList = useSelector((state) => state.borrow.all_borrow_list?.element?.result);
const [allBook, setAllBook] = useState(null);

const handleDelete = (book_id) => {
dispatch(Delete_Book_Cms_Initial({ book_id })).then(() => {
dispatch(Get_All_Book_Cms_Initial());
});
};

useEffect(() => {
dispatch(Get_All_Borrow_Cms_Initial());
}, [dispatch]);

useEffect(() => {
setAllBook(borrowList);
}, [borrowList]);

return (
<div className="container mt-20">
<form>
<div className="flex">
<label htmlFor="search-dropdown" className="mb-2 text-sm font-medium text-gray-900 sr-only">
Your Email
</label>
<button
id="dropdown-button"
data-dropdown-toggle="dropdown"
className="flex-shrink-0 z-10 inline-flex items-center py-2.5 px-4 text-sm font-medium text-center text-gray-900 bg-gray-100 border border-gray-300 rounded-l-lg hover:bg-gray-200"
type="button"
>
All categories
<svg
aria-hidden="true"
className="w-4 h-4 ml-1"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
clipRule="evenodd"
></path>
</svg>
</button>
<div
id="dropdown"
className="z-10 hidden bg-white divide-y divide-gray-100 rounded-lg shadow w-44 dark:bg-gray-700"
>
<ul className="py-2 text-sm text-gray-700 dark:text-gray-200" aria-labelledby="dropdown-button">
<li>
<a href="#" className="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
Shopping
</a>
</li>
<li>
<a href="#" className="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
Images
</a>
</li>
<li>
<a href="#" className="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
News
</a>
</li>
<li>
<a href="#" className="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
Finance
</a>
</li>
</ul>
</div>
<div className="relative w-full">
<input
type="search"
id="search-dropdown"
className="block p-2.5 w-full z-20 text-sm text-gray-900 bg-gray-50 rounded-r-lg border-l-gray-100 border-l-2 border border-gray-300 focus:ring-blue-500 focus:border-blue-500"
placeholder="Search"
/>
<button
type="submit"
className="absolute top-0 right-0 p-2.5 text-sm font-medium text-white bg-blue-700 rounded-r-lg border border-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
>
<svg
aria-hidden="true"
className="w-5 h-5"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
></path>
</svg>
</button>
</div>
</div>
</form>
<div className="flex flex-col">
<div className="overflow-x-auto">
<div className="py-3 pl-2 flex justify-between">
<div className="relative max-w-xs">
<label htmlFor="hs-table-search" className="sr-only">
Search
</label>
<input
type="text"
name="hs-table-search"
id="hs-table-search"
className="block w-full p-3 pl-10 text-sm border-2 border-gray-400 rounded-md focus:border-blue-500 focus:ring-blue-500 dark:bg-white dark:border-gray-700 dark:text-gray-400"
placeholder="Search..."
/>
<div className="absolute inset-y-0 left-0 flex items-center pl-4 pointer-events-none">
<svg
className="h-3.5 w-3.5 text-gray-400"
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="currentColor"
viewBox="0 0 16 16"
>
<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z" />
</svg>
</div>
</div>
<Link to="/book/add">
<button className="bg-transparent hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded">
Thêm sách
</button>
</Link>
</div>

<div className="p-1.5 w-full inline-block align-middle">
<div className="overflow-hidden border rounded-lg">
<table className="min-w-full divide-y divide-gray-200">
<thead className="bg-gray-50">
<tr>
<th scope="col" className="px-6 py-3 text-xs font-bold text-left text-gray-500 uppercase ">
ID
</th>
<th scope="col" className="px-6 py-3 text-xs font-bold text-left text-gray-500 uppercase ">
Tên
</th>
<th scope="col" className="px-6 py-3 text-xs font-bold text-left text-gray-500 uppercase ">
Tác giả
</th>
<th scope="col" className="px-6 py-3 text-xs font-bold text-left text-gray-500 uppercase ">
Sinh viên
</th>
<th scope="col" className="px-6 py-3 text-xs font-bold text-left text-gray-500 uppercase ">
Tình trạng
</th>
<th scope="col" className="px-6 py-3 text-xs font-bold text-right text-gray-500 uppercase ">
Chỉnh sửa
</th>
<th scope="col" className="px-6 py-3 text-xs font-bold text-right text-gray-500 uppercase ">
Xóa
</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200">
{allBook &&
allBook?.map((book, idx) => (
<tr key={idx}>
<td className="px-6 py-4 text-sm font-medium text-gray-800 whitespace-nowrap">
{book?.borrowed_book_id}
</td>
<td className="px-6 py-4 text-sm text-gray-800 whitespace-nowrap">{book?.name}</td>
<td className="px-6 py-4 text-sm text-gray-800 whitespace-nowrap">{book?.name_author}</td>
<td className="px-6 py-4 text-sm text-gray-800 whitespace-nowrap">{book?.user_id}</td>
<td className="px-6 py-4 text-sm text-gray-800 whitespace-nowrap">
{HELPERS.getStatusBorrow(book?.status)}
</td>
<td className="px-6 py-4 text-sm font-medium text-right whitespace-nowrap">
<Link
to={`/borrow/edit/${book?.borrowed_book_id}`}
className="text-green-500 hover:text-green-700"
>
Chỉnh sửa
</Link>
</td>
<td className="px-6 py-4 text-sm font-medium text-right whitespace-nowrap">
<button
className="text-red-500 hover:text-red-700"
onClick={() => handleDelete(book?.book_id)}
>
Xóa
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
);
};

export default AllBorrowBook;
Loading

0 comments on commit 2a76a02

Please sign in to comment.