правки на пути к победе (не работает селект)

This commit is contained in:
ekallin 2023-12-25 11:28:23 +04:00
parent 21253e3a1b
commit 07f0536caf
11 changed files with 45 additions and 26 deletions

View File

@ -43,8 +43,9 @@
],
"movies": [
{
"id": 1,
"name": "Терминатор",
"categoryId": "3",
"categoryId": 3,
"duration": "2:27",
"description": "Мальчик и девочка из Омерики спасают мир от нашествия машин под предводительством искусственного интеллекта",
"image": "src/assets/akademy-ambrella.jpeg"

View File

@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"rest": "json-server data.json",
"rest": "json-server data.json --port 8081",
"vite": "vite",
"dev": "npm-run-all --parallel rest vite",
"prod": "npm-run-all lint 'vite build' --parallel rest 'vite preview'"

View File

@ -20,11 +20,27 @@ const LinesTable = ({ children }) => {
<span>Действие</span>
</th>
</tr>
<tbody>
{children}
</tbody >
</thead>
<tbody>
{children}
</tbody >
</table>
// <div className='main__cart cart'>
// <table className='table'>
// <thead className='cart__row_header'>
// <tr className='cart__row_header'>
// <th scope='col' className='cart__column'>Name</th>
// <th scope='col' className='cart__column'>Price</th>
// <th scope='col' className='cart__column'>Amount</th>
// <th scope='col' className='cart__column'>Total</th>
// <th scope='col' className='cart__column'>Actions</th>
// </tr>
// </thead>
// <tbody className='cart__products'>
// {children}
// </tbody >
// </table>
// </div>
);
};

View File

@ -11,12 +11,11 @@ const LinesTableRow = ({
};
return (
<tr>
<th>{1}</th>
{/* <td>1</td> */}
<td>{line.movies.name}</td>
<td>{line.movies.categoryId}</td>
<td>{line.movies.description}</td>
<td>{line.movies.duration}</td>
<th></th>
<td>{line.name}</td>
<td>{line.categoryId}</td>
<td>{line.description}</td>
<td>{line.duration}</td>
<td>
<span className="d-flex justify-content-around align-items-center pt-1">
<a href="#" onClick={(event) => handleAnchorClick(event, onEdit)}><PencilSquare /></a>

View File

@ -14,8 +14,7 @@ const LinesItemForm = ({ item, handleChange }) => {
<img id='image-preview' className='rounded' alt='placeholder'
src={item.image || imgPlaceholder} />
</div>
<Select values={types} name='category' label='Жанр' value={item.categoryId} onChange={handleChange}
required />
<Select values={types} name='category' label='Жанр' value={item.categoryId.toString()} onChange={handleChange} />
<Input name='name' label='Название' value={item.name} onChange={handleChange}
type='text' required />
<Input name='description' label='Описание' value={item.description} onChange={handleChange}

View File

@ -1,7 +1,7 @@
import { useState } from 'react';
import toast from 'react-hot-toast';
import useModal from '../modal/ModalHook.js';
import CategoriesApiService from '../types/service/CategoriesApiService.js';
import MoviesApiService from '../types/service/MoviesApiService.js';
const useLinesDeleteModal = (linesChangeHandle) => {
const { isModalShow, showModal, hideModal } = useModal();
@ -17,7 +17,7 @@ const useLinesDeleteModal = (linesChangeHandle) => {
};
const onDelete = async () => {
await CategoriesApiService.delete(currentId);
await MoviesApiService.delete(currentId);
linesChangeHandle();
toast.success('Элемент успешно удален', { id: 'LinesTable' });
onClose();

View File

@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import CategoriesApiService from '../types/service/CategoriesApiService.js';
import MoviesApiService from '../types/service/MoviesApiService.js';
const useLines = (typeFilter) => {
const [linesRefresh, setLinesRefresh] = useState(false);
@ -11,7 +11,7 @@ const useLines = (typeFilter) => {
if (typeFilter) {
expand = `${expand}&categoryId=${typeFilter}`;
}
const data = await CategoriesApiService.getAll(expand);
const data = await MoviesApiService.getAll(expand);
setLines(data ?? []);
};

View File

@ -1,7 +1,7 @@
import { useState } from 'react';
import toast from 'react-hot-toast';
import getBase64FromFile from '../utils/Base64.js';
import CategoriesApiService from '../types/service/CategoriesApiService.js';
import MoviesApiService from '../types/service/MoviesApiService.js';
import useLinesItem from './LinesItemHook.js';
const useLinesItemForm = (id, linesChangeHandle) => {
@ -20,7 +20,7 @@ const useLinesItemForm = (id, linesChangeHandle) => {
const description = formData.description;
const image = formData.image.startsWith('data:image') ? formData.image : '';
return {
categoryId: categoryId.toString(),
categoryId: categoryId,
name: name.toString(),
duration: duration.toString(),
description: description.toString(),
@ -57,9 +57,9 @@ const useLinesItemForm = (id, linesChangeHandle) => {
const body = getLineObject(item);
if (form.checkValidity()) {
if (id === undefined) {
await CategoriesApiService.create(body);
await MoviesApiService.create(body);
} else {
await CategoriesApiService.update(id, body);
await MoviesApiService.update(id, body);
}
if (linesChangeHandle) linesChangeHandle();
toast.success('Элемент успешно сохранен', { id: 'LinesTable' });

View File

@ -1,6 +1,5 @@
import { useEffect, useState } from 'react';
// import LinesApiService from '../types/service/CategoriesApiService.js';
import CategoriesApiService from '../types/service/CategoriesApiService.js';
import MoviesApiService from '../types/service/MoviesApiService.js';
const useLinesItem = (id) => {
const emptyItem = {
@ -8,7 +7,7 @@ const useLinesItem = (id) => {
categoryId: '',
name: '',
duration: '',
description: '1 hours',
description: '',
image: '',
};
@ -16,7 +15,7 @@ const useLinesItem = (id) => {
const getItem = async (itemId = undefined) => {
if (itemId && itemId > 0) {
const data = await CategoriesApiService.get(itemId);
const data = await MoviesApiService.get(itemId);
setItem(data);
} else {
setItem({ ...emptyItem });

View File

@ -1,5 +1,5 @@
import ApiService from '../../api/ApiService.js';
const CategoriesApiService = new ApiService('movies');
const CategoriesApiService = new ApiService('categories');
export default CategoriesApiService;

View File

@ -0,0 +1,5 @@
import ApiService from '../../api/ApiService.js';
const MoviesApiService = new ApiService('movies');
export default MoviesApiService;