Skip to content

Commit

Permalink
#175 user profile and delete cms
Browse files Browse the repository at this point in the history
  • Loading branch information
giabao1511 committed Mar 19, 2023
1 parent d408e2b commit e6c1c07
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 8 deletions.
1 change: 1 addition & 0 deletions frontend-manager-cms/src/api/api_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const API_ADMIN = {
LOGIN_ADMIN_CMS: '/manager/v1/admin/login',
GET_ALL_BOOK_CMS: '/manager/v1/admin/private/book/all',
GET_DETAIL_BOOK_CMS: '/manager/v1/admin/private/book/detail',
DELETE_BOOK_CMS: '/manager/v1/admin/private/book/delete',
GET_ALL_AUTHOR_CMS: '/manager/v1/admin/private/author/all',
GET_DETAIL_AUTHOR_CMS: '/manager/v1/admin/private/author/detail',
RENEW_TOKEN_CMS: '/manager/v1/admin/renew-token',
Expand Down
11 changes: 8 additions & 3 deletions frontend-manager-cms/src/pages/Book/AllBook.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Link } from 'react-router-dom';
import { Get_All_Book_Cms_Initial } from 'redux/managers/book_slice/book_thunk';
import { Delete_Book_Cms_Initial, Get_All_Book_Cms_Initial } from 'redux/managers/book_slice/book_thunk';

const Book = () => {
const dispatch = useDispatch();
const bookList = useSelector((state) => state.book.all_books_list?.element?.result);

const handleDelete = (e) => { };
const handleDelete = (book_id) => {
dispatch(Delete_Book_Cms_Initial({ book_id }));
};

useEffect(() => {
dispatch(Get_All_Book_Cms_Initial());
Expand Down Expand Up @@ -98,7 +100,10 @@ const Book = () => {
</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}>
<button
className="text-red-500 hover:text-red-700"
onClick={() => handleDelete(book?.book_id)}
>
Delete
</button>
</td>
Expand Down
14 changes: 13 additions & 1 deletion frontend-manager-cms/src/redux/managers/book_slice/book_slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { createSlice } from '@reduxjs/toolkit';

//! CALL API REDUX THUNK
import { Get_All_Book_Cms_Initial, Get_Detail_Book_Cms_Initial } from './book_thunk';
import { Delete_Book_Cms_Initial, Get_All_Book_Cms_Initial, Get_Detail_Book_Cms_Initial } from './book_thunk';

const initialState = {
loading: false,
Expand Down Expand Up @@ -41,6 +41,18 @@ const Book = createSlice({
state.loading = false;
state.error = action.payload;
},

//* Delete book CMS
[Delete_Book_Cms_Initial.pending]: (state, action) => {
state.loading = true;
},
[Delete_Book_Cms_Initial.fulfilled]: (state, action) => {
state.loading = false;
},
[Delete_Book_Cms_Initial.rejected]: (state, action) => {
state.loading = false;
state.error = action.payload;
},
},
});
const BookSlice = Book.reducer;
Expand Down
50 changes: 50 additions & 0 deletions frontend-manager-cms/src/redux/managers/book_slice/book_thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import API_ADMIN from 'api/api_user';

//! SHARE
import HELPERS from 'utils/helper';
import NOTIFICATION from 'utils/notification';

/**
* @author Nguyễn Tiến Tài
Expand Down Expand Up @@ -44,6 +45,55 @@ export const Get_All_Book_Cms_Initial = createAsyncThunk('admin/cms/book/all', a
}
});

/**
* @author Châu Gia Bảo
* @created_at 19/03/2023
* @descriptionKey Call api Get All Book admin cms
* @function Get_Detail_Book_Cms_Initial
* @return {Object}
*/
export const Delete_Book_Cms_Initial = createAsyncThunk(
'admin/cms/book/delete',
async ({ book_id }, { rejectWithValue }) => {
try {
//Call Api axios
const response = await axios.get(
`${API_ADMIN.DELETE_BOOK_CMS}`,
{
input: {
book_input: {
book_id,
},
},
},
{
headers: HELPERS.headerBrowser(),
withCredentials: true,
},
);

//Take response Success
const successData = response.data;

//Check data
if (successData) {
// return result data
NOTIFICATION.swalSuccess('Đã xóa thành công', '');

return successData;
}
} catch (error) {
if (error) {
//Take response Error
const errorData = error.response.data;

// return error
return rejectWithValue(errorData);
}
}
},
);

/**
* @author Châu Gia Bảo
* @created_at 09/03/2023
Expand Down
1 change: 1 addition & 0 deletions frontend-manager-cms/src/styles/pages/_author.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

img {
width: 100%;
height: 100%;
}

&__require {
Expand Down
17 changes: 17 additions & 0 deletions frontend-manager-cms/src/utils/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { toast } from 'react-toastify';

//! SHARE
import CONSTANTS from 'configs/constants';
import Swal from 'sweetalert2';

const NOTIFICATION = {
/**
Expand All @@ -21,6 +22,22 @@ const NOTIFICATION = {
});
},

/**
* @author Nguyễn Tiến Tài
* @created_at 02/03/2023
* @descriptionKey success
*/
swalSuccess(title, text) {
Swal.fire({
title,
text,
icon: 'success',
customClass: 'swal-wide',
confirmButtonColor: '#3085d6',
confirmButtonText: 'Xác nhận',
});
},

/**
* @author Nguyễn Tiến Tài
* @created_at 02/03/2023
Expand Down
2 changes: 1 addition & 1 deletion frontend-manager-student/src/components/Section.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const SectionTitle = (props) => {
<div className={`section__title ${props.left ? 'left' : 'center'}`}>
<span>{props.children}</span>
{props.subTitle && (
<Link to="/">
<Link to={props.route}>
{props.subTitle} <i className="bx bx-chevron-right"></i>
</Link>
)}
Expand Down
4 changes: 3 additions & 1 deletion frontend-manager-student/src/pages/Home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ const Home = () => {
</Section>

<Section>
<SectionTitle subTitle={<Link to="/book/all">Xem thêm</Link>}>Tài liệu nổi bật</SectionTitle>
<SectionTitle subTitle={'Xem thêm'} route="/book/all">
Tài liệu nổi bật
</SectionTitle>
<SectionBody>
<SlickSlider {...settings}>
{mockDataBook.map((item, index) => (
Expand Down
8 changes: 6 additions & 2 deletions frontend-manager-student/src/pages/UserProfile/UserInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const UserInfo = () => {
const [preview, setPreview] = useState();

//File custom hook media
// const { handleUpload } = useUploadCloud();
const { handleUpload } = useUploadCloud();

const onSelectFile = (e) => {
if (!e.target.files || e.target.files.length === 0) {
Expand All @@ -39,6 +39,7 @@ const UserInfo = () => {

// get first image
setSelectedFile(e.target.files[0]);
handleUpload(e);
};

console.log(profile_student);
Expand Down Expand Up @@ -83,7 +84,10 @@ const UserInfo = () => {
</div>
</Col>
<Col md={9} className="profile__info__content__input">
<div className="profile__info__content__input-item">{profile_student?.data?.name}</div>
{/* <div className="profile__info__content__input-item">{profile_student?.data?.name}</div> */}
<div className="profile__info__content__input-item">
<input type="text" defaultValue={profile_student?.data?.name} className="input-user" />
</div>
<div className="profile__info__content__input-item">{profile_student?.data?.mssv}</div>
<div className="profile__info__content__input-item">{profile_student?.data?.email}</div>
<div className="profile__info__content__input-item">{profile_student?.data?.phone_hidden}</div>
Expand Down
5 changes: 5 additions & 0 deletions frontend-manager-student/src/styles/pages/_user_profile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@
}

&__input {
margin-top: -3px;
color: $txt-main-color;

.input-user {
padding-left: 1rem;
}

input {
margin-right: 0.5rem;
}
Expand Down

0 comments on commit e6c1c07

Please sign in to comment.