template and back

This commit is contained in:
romantarkin committed 2025-01-29 15:09:27 +05:00
commit 07ef7e9b8f
3773 files changed
+422508

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
export async function list () {
const response = await fetch('/api/v1/body-types');
return (await response.json()).results.rows;
}
export async function add (params: any) {
const response = await fetch('/api/v1/body-types', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
export async function update (params: any) {
const response = await fetch('/api/v1/body-types', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
updates: params,
where: {
id: params.id,
}
})
});
return await response.json();
}
export async function remove (params: any) {
const response = await fetch('/api/v1/body-types', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
+42
View File
@@ -0,0 +1,42 @@
export async function list () {
const response = await fetch('/api/v1/car-brands');
return (await response.json()).results.rows;
}
export async function add (params: any) {
const response = await fetch('/api/v1/car-brands', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
export async function update (params: any) {
const response = await fetch('/api/v1/car-brands', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
updates: params,
where: {
id: params.id,
}
})
});
return await response.json();
}
export async function remove (params: any) {
const response = await fetch('/api/v1/car-brands', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
+42
View File
@@ -0,0 +1,42 @@
export async function list () {
const response = await fetch('/api/v1/car-colors');
return (await response.json()).results.rows;
}
export async function add (params: any) {
const response = await fetch('/api/v1/car-colors', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
export async function update (params: any) {
const response = await fetch('/api/v1/car-colors', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
updates: params,
where: {
id: params.id,
}
})
});
return await response.json();
}
export async function remove (params: any) {
const response = await fetch('/api/v1/car-colors', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
+42
View File
@@ -0,0 +1,42 @@
export async function list () {
const response = await fetch('/api/v1/car-models');
return (await response.json()).results.rows;
}
export async function add (params: any) {
const response = await fetch('/api/v1/car-models', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
export async function update (params: any) {
const response = await fetch('/api/v1/car-models', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
updates: params,
where: {
id: params.id,
}
})
});
return await response.json();
}
export async function remove (params: any) {
const response = await fetch('/api/v1/car-models', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
+42
View File
@@ -0,0 +1,42 @@
export async function list () {
const response = await fetch('/api/v1/cars');
return (await response.json()).results.rows;
}
export async function add (params: any) {
const response = await fetch('/api/v1/cars', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
export async function update (params: any) {
const response = await fetch('/api/v1/cars', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
updates: params,
where: {
id: params.id,
}
})
});
return await response.json();
}
export async function remove (params: any) {
const response = await fetch('/api/v1/cars', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
+38
View File
@@ -0,0 +1,38 @@
"use client"
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import { ReactElement } from 'react';
import { list } from "@/api/bodyTypes";
interface BodyTypeContextType {
bodyType: ReactElement | null;
setBodyType: (content: ReactElement | null) => void;
}
const BodyTypeContext = createContext<BodyTypeContextType | undefined>(undefined);
export const BodyTypeProvider = ({ children }: { children: ReactNode }) => {
const [bodyType, setBodyType] = useState<any | null>(null);
const fetchData = async () => {
setBodyType(await list());
};
useEffect(() => {
fetchData();
}, []);
return (
<BodyTypeContext.Provider value={{ bodyType, setBodyType }}>
{children}
</BodyTypeContext.Provider>
);
};
export const useBodyTypeContext = (): BodyTypeContextType => {
const context = useContext(BodyTypeContext);
if (!context) {
throw new Error('useBodyTypeContext must be used within a BodyTypeProvider');
}
return context;
};
+38
View File
@@ -0,0 +1,38 @@
"use client"
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import { ReactElement } from 'react';
import { list } from "@/api/cars";
interface CarContextType {
car: ReactElement | null;
setCar: (content: ReactElement | null) => void;
}
const CarContext = createContext<CarContextType | undefined>(undefined);
export const CarProvider = ({ children }: { children: ReactNode }) => {
const [car, setCar] = useState<any | null>(null);
const fetchData = async () => {
setCar(await list());
};
useEffect(() => {
fetchData();
}, []);
return (
<CarContext.Provider value={{ car, setCar }}>
{children}
</CarContext.Provider>
);
};
export const useCarContext = (): CarContextType => {
const context = useContext(CarContext);
if (!context) {
throw new Error('useCarContext must be used within a CarProvider');
}
return context;
};
+38
View File
@@ -0,0 +1,38 @@
"use client"
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import { ReactElement } from 'react';
import { list } from "@/api/carBrands";
interface CarBrandContextType {
carBrand: ReactElement | null;
setCarBrand: (content: ReactElement | null) => void;
}
const CarBrandContext = createContext<CarBrandContextType | undefined>(undefined);
export const CarBrandProvider = ({ children }: { children: ReactNode }) => {
const [carBrand, setCarBrand] = useState<any | null>(null);
const fetchData = async () => {
setCarBrand(await list());
};
useEffect(() => {
fetchData();
}, []);
return (
<CarBrandContext.Provider value={{ carBrand, setCarBrand }}>
{children}
</CarBrandContext.Provider>
);
};
export const useCarBrandContext = (): CarBrandContextType => {
const context = useContext(CarBrandContext);
if (!context) {
throw new Error('useCarBrandContext must be used within a CarBrandProvider');
}
return context;
};
+45
View File
@@ -0,0 +1,45 @@
'use client'
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import { list } from "@/api/carColors";
// Define types for carColor item
interface CarColorItem {
id: string;
name: string;
hexCode: string;
}
interface CarColorType {
carColor: CarColorItem[] | null;
setCarColor: (content: CarColorItem[]) => void;
fetchData: () => void;
}
const CarColorContext = createContext<CarColorType | undefined>(undefined);
export const CarColorProvider = ({ children }: { children: ReactNode }) => {
const [carColor, setCarColor] = useState<CarColorItem[]>([]);
const fetchData = async () => {
setCarColor(await list());
};
useEffect(() => {
fetchData();
}, []);
return (
<CarColorContext.Provider value={{ carColor, setCarColor, fetchData }}>
{children}
</CarColorContext.Provider>
);
};
export const useCarColorContext = (): CarColorType => {
const context = useContext(CarColorContext);
if (!context) {
throw new Error('useCarColorContext must be used within a CarColorProvider');
}
return context;
};
+38
View File
@@ -0,0 +1,38 @@
"use client"
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import { ReactElement } from 'react';
import { list } from "@/api/carModels";
interface CarModelContextType {
carModel: ReactElement | null;
setCarModel: (content: ReactElement | null) => void;
}
const CarModelContext = createContext<CarModelContextType | undefined>(undefined);
export const CarModelProvider = ({ children }: { children: ReactNode }) => {
const [carModel, setCarModel] = useState<any | null>(null);
const fetchData = async () => {
setCarModel(await list());
};
useEffect(() => {
fetchData();
}, []);
return (
<CarModelContext.Provider value={{ carModel, setCarModel }}>
{children}
</CarModelContext.Provider>
);
};
export const useCarModelContext = (): CarModelContextType => {
const context = useContext(CarModelContext);
if (!context) {
throw new Error('useCarModelContext must be used within a CarModelProvider');
}
return context;
};
+45
View File
@@ -0,0 +1,45 @@
"use client"
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import { list } from "@/api/customers";
interface CustomerItem {
id: string;
name: string;
phone: string;
email: string;
}
interface CustomerContextType {
customers: CustomerItem[] | [];
setCustomers: (content: CustomerItem[] | []) => void;
fetchData: () => void;
}
const CustomerContext = createContext<CustomerContextType | undefined>(undefined);
export const CustomerProvider = ({ children }: { children: ReactNode }) => {
const [customers, setCustomers] = useState<any | null>([]);
const fetchData = async () => {
setCustomers(await list());
};
useEffect(() => {
fetchData();
}, []);
return (
<CustomerContext.Provider value={{ customers, setCustomers, fetchData }}>
{children}
</CustomerContext.Provider>
);
};
export const useCustomerContext = (): CustomerContextType => {
const context = useContext(CustomerContext);
if (!context) {
throw new Error('useCustomerContext must be used within a CustomerProvider');
}
return context;
};
+38
View File
@@ -0,0 +1,38 @@
"use client"
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import { ReactElement } from 'react';
import { list } from "@/api/engines";
interface EngineContextType {
engine: ReactElement | null;
setEngine: (content: ReactElement | null) => void;
}
const EngineContext = createContext<EngineContextType | undefined>(undefined);
export const EngineProvider = ({ children }: { children: ReactNode }) => {
const [engine, setEngine] = useState<any | null>(null);
const fetchData = async () => {
setEngine(await list());
};
useEffect(() => {
fetchData();
}, []);
return (
<EngineContext.Provider value={{ engine, setEngine }}>
{children}
</EngineContext.Provider>
);
};
export const useEngineContext = (): EngineContextType => {
const context = useContext(EngineContext);
if (!context) {
throw new Error('useEngineContext must be used within an EngineProvider');
}
return context;
};
+38
View File
@@ -0,0 +1,38 @@
"use client"
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import { ReactElement } from 'react';
import { list } from "@/api/sales"; // Assuming your API call for sales is here
interface SaleContextType {
sale: ReactElement | null;
setSale: (content: ReactElement | null) => void;
}
const SaleContext = createContext<SaleContextType | undefined>(undefined);
export const SaleProvider = ({ children }: { children: ReactNode }) => {
const [sale, setSale] = useState<any | null>(null);
const fetchData = async () => {
setSale(await list());
};
useEffect(() => {
fetchData();
}, []);
return (
<SaleContext.Provider value={{ sale, setSale }}>
{children}
</SaleContext.Provider>
);
};
export const useSaleContext = (): SaleContextType => {
const context = useContext(SaleContext);
if (!context) {
throw new Error('useSaleContext must be used within a SaleProvider');
}
return context;
};
+38
View File
@@ -0,0 +1,38 @@
"use client"
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import { ReactElement } from 'react';
import { list } from "@/api/transmissions";
interface TransmissionContextType {
transmission: ReactElement | null;
setTransmission: (content: ReactElement | null) => void;
}
const TransmissionContext = createContext<TransmissionContextType | undefined>(undefined);
export const TransmissionProvider = ({ children }: { children: ReactNode }) => {
const [transmission, setTransmission] = useState<any | null>(null);
const fetchData = async () => {
setTransmission(await list());
};
useEffect(() => {
fetchData();
}, []);
return (
<TransmissionContext.Provider value={{ transmission, setTransmission }}>
{children}
</TransmissionContext.Provider>
);
};
export const useTransmissionContext = (): TransmissionContextType => {
const context = useContext(TransmissionContext);
if (!context) {
throw new Error('useTransmissionContext must be used within a TransmissionProvider');
}
return context;
};
+38
View File
@@ -0,0 +1,38 @@
"use client"
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import { ReactElement } from 'react';
import { list } from "@/api/trims";
interface TrimContextType {
trim: ReactElement | null;
setTrim: (content: ReactElement | null) => void;
}
const TrimContext = createContext<TrimContextType | undefined>(undefined);
export const TrimProvider = ({ children }: { children: ReactNode }) => {
const [trim, setTrim] = useState<any | null>(null);
const fetchData = async () => {
setTrim(await list());
};
useEffect(() => {
fetchData();
}, []);
return (
<TrimContext.Provider value={{ trim, setTrim }}>
{children}
</TrimContext.Provider>
);
};
export const useTrimContext = (): TrimContextType => {
const context = useContext(TrimContext);
if (!context) {
throw new Error('useTrimContext must be used within a TrimProvider');
}
return context;
};
+42
View File
@@ -0,0 +1,42 @@
export async function list () {
const response = await fetch('/api/v1/customers');
return (await response.json()).results.rows;
}
export async function add (params: any) {
const response = await fetch('/api/v1/customers', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
export async function update (params: any) {
const response = await fetch('/api/v1/customers', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
updates: params,
where: {
id: params.id,
}
})
});
return await response.json();
}
export async function remove (params: any) {
const response = await fetch('/api/v1/customers', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
+42
View File
@@ -0,0 +1,42 @@
export async function list () {
const response = await fetch('/api/v1/engines');
return (await response.json()).results.rows;
}
export async function add (params: any) {
const response = await fetch('/api/v1/engines', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
export async function update (params: any) {
const response = await fetch('/api/v1/engines', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
updates: params,
where: {
id: params.id,
}
})
});
return await response.json();
}
export async function remove (params: any) {
const response = await fetch('/api/v1/engines', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
+42
View File
@@ -0,0 +1,42 @@
export async function list () {
const response = await fetch('/api/v1/sales');
return (await response.json()).results.rows;
}
export async function add (params: any) {
const response = await fetch('/api/v1/sales', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
export async function update (params: any) {
const response = await fetch('/api/v1/sales', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
updates: params,
where: {
id: params.id,
}
})
});
return await response.json();
}
export async function remove (params: any) {
const response = await fetch('/api/v1/sales', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
+42
View File
@@ -0,0 +1,42 @@
export async function list () {
const response = await fetch('/api/v1/transmissions');
return (await response.json()).results.rows;
}
export async function add (params: any) {
const response = await fetch('/api/v1/transmissions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
export async function update (params: any) {
const response = await fetch('/api/v1/transmissions', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
updates: params,
where: {
id: params.id,
}
})
});
return await response.json();
}
export async function remove (params: any) {
const response = await fetch('/api/v1/transmissions', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
+42
View File
@@ -0,0 +1,42 @@
export async function list () {
const response = await fetch('/api/v1/trims');
return (await response.json()).results.rows;
}
export async function add (params: any) {
const response = await fetch('/api/v1/trims', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
export async function update (params: any) {
const response = await fetch('/api/v1/trims', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
updates: params,
where: {
id: params.id,
}
})
});
return await response.json();
}
export async function remove (params: any) {
const response = await fetch('/api/v1/trims', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
});
return await response.json();
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+3
View File
@@ -0,0 +1,3 @@
body {
margin: 0;
}
+67
View File
@@ -0,0 +1,67 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import './global.css';
import {ModalProvider} from "@/components/Modal/ModalContext";
import {CarColorProvider} from "@/api/context/CarColor";
import {BodyTypeProvider} from "@/api/context/BodyType";
import {CarProvider} from "@/api/context/Car";
import {CarBrandProvider} from "@/api/context/CarBrand";
import {CarModelProvider} from "@/api/context/CarModel";
import {CustomerProvider} from "@/api/context/Customer";
import {EngineProvider} from "@/api/context/Engine";
import {SaleProvider} from "@/api/context/Sale";
import {TransmissionProvider} from "@/api/context/Transmission";
import {TrimProvider} from "@/api/context/Trim";
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
<BodyTypeProvider>
<CarProvider>
<CarBrandProvider>
<CarModelProvider>
<CustomerProvider>
<EngineProvider>
<SaleProvider>
<TransmissionProvider>
<TrimProvider>
<CarColorProvider>
<ModalProvider>
{children}
</ModalProvider>
</CarColorProvider>
</TrimProvider>
</TransmissionProvider>
</SaleProvider>
</EngineProvider>
</CustomerProvider>
</CarModelProvider>
</CarBrandProvider>
</CarProvider>
</BodyTypeProvider>
</body>
</html>
);
}
+61
View File
@@ -0,0 +1,61 @@
"use client";
import NavBar from "@/components/NavBar/NavBar";
import NavBarItem from "@/components/NavBar/NavBarItem";
import { ReactElement, useState } from "react";
import BodyTypes from "@/pages/BodyType"
import CarBrand from "@/pages/CarBrand";
import CarModel from "@/pages/CarModel";
import Engine from "@/pages/Engine";
import Trim from "@/pages/Trim";
import CarColor from "@/pages/CarColor";
import Transmission from "@/pages/Transmission";
import Sale from "@/pages/Sale";
import Car from "@/pages/Car";
import Customer from "@/pages/Customer";
import {useModalContext} from "@/components/Modal/ModalContext";
import Modal from "@/components/Modal/Modal";
export default function App() {
const [content, setContent] = useState<ReactElement | null>(null);
const { contentModal } = useModalContext();
return (
<>
{contentModal ? <Modal>{contentModal}</Modal> : ""}
<NavBar>
<NavBarItem onClick={() => setContent(<CarBrand />)}>
Марки автомобилей
</NavBarItem>
<NavBarItem onClick={() => setContent(<CarModel />)}>
Модели автомобилей
</NavBarItem>
<NavBarItem onClick={() => setContent(<BodyTypes />)}>
Типы кузовов
</NavBarItem>
<NavBarItem onClick={() => setContent(<Engine />)}>
Двигатели
</NavBarItem>
<NavBarItem onClick={() => setContent(<Trim />)}>
Комплектации
</NavBarItem>
<NavBarItem onClick={() => setContent(<CarColor />)}>
Цвета автомобилей
</NavBarItem>
<NavBarItem onClick={() => setContent(<Transmission />)}>
Трансмиссии
</NavBarItem>
<NavBarItem onClick={() => setContent(<Sale />)}>
Продажи
</NavBarItem>
<NavBarItem onClick={() => setContent(<Car />)}>
Автомобили
</NavBarItem>
<NavBarItem onClick={() => setContent(<Customer />)}>
Клиенты
</NavBarItem>
</NavBar>
{content}
</>
);
}
+12
View File
@@ -0,0 +1,12 @@
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
+17
View File
@@ -0,0 +1,17 @@
'use client'
import './Button.css';
export default function Button({
children,
onClickAction,
}: {
children: React.ReactNode;
onClickAction: (event: React.MouseEvent<HTMLButtonElement>) => void; // Renamed here as well
}) {
return (
<button className="button" onClick={onClickAction}>
{children}
</button>
);
}
+5
View File
@@ -0,0 +1,5 @@
.content {
margin-left: 25%;
padding: 1px 16px;
height: 1000px;
}
+9
View File
@@ -0,0 +1,9 @@
import './Content.css';
export default function Content({children}:any) {
return (
<div className="content">
{children}
</div>
);
}
+6
View File
@@ -0,0 +1,6 @@
input[type=text] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
+11
View File
@@ -0,0 +1,11 @@
import React from 'react';
import './Input.css'
export function Input({children, name, value, onChange}: any) {
return (
<>
<label htmlFor={name}>{children}</label>
<input type="text" value={value} onChange={onChange} placeholder={children} id={name} name={name}/>
</>
);
}
+4
View File
@@ -0,0 +1,4 @@
.input__color {
margin-top: 10px;
width: 100%;
}
+10
View File
@@ -0,0 +1,10 @@
import React from 'react';
import './InputColor.css'
export function InputColor({children, value, onChange, name}: any) {
return (
<>
<input type="color" value={value} name={name} onChange={onChange} className="input__color"/>
</>
);
}
+51
View File
@@ -0,0 +1,51 @@
/* Стили для модального окна */
.modal {
position: fixed;
z-index: 1; /* Окно будет поверх контента */
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5); /* Полупрозрачный фон */
padding-top: 60px;
}
/* Стили для содержимого модального окна */
.modal-content {
background-color: #fff;
margin: 5% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 500px;
}
/* Кнопка для закрытия окна */
.close-btn {
color: #aaa;
font-size: 28px;
font-weight: bold;
position: absolute;
top: 10px;
right: 20px;
}
.close-btn:hover,
.close-btn:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
/* Кнопка открытия модального окна */
#openModalBtn {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
#openModalBtn:hover {
background-color: #45a049;
}
+15
View File
@@ -0,0 +1,15 @@
import './Modal.css';
import {useModalContext} from "@/components/Modal/ModalContext";
export default function Modal({children}:any) {
const { setContentModal } = useModalContext();
return (
<div id="modal" className="modal">
<div className="modal-content">
<span className="close-btn" onClick={() => setContentModal(null)} id="closeModalBtn">&times;</span>
{children}
</div>
</div>
);
}
+33
View File
@@ -0,0 +1,33 @@
'use client'
import React, { createContext, useContext, useState, ReactNode } from 'react';
import { ReactElement } from 'react';
// Типы для контекста с contentModal
interface ModalContextType {
contentModal: ReactElement | null; // Заменим content на contentModal
setContentModal: (content: ReactElement | null) => void; // Заменим setContent на setContentModal
}
// Создание контекста с дефолтными значениями
const ModalContext = createContext<ModalContextType | undefined>(undefined);
// Провайдер контекста
export const ModalProvider = ({ children }: { children: ReactNode }) => {
const [contentModal, setContentModal] = useState<ReactElement | null>(null); // Заменим content на contentModal
return (
<ModalContext.Provider value={{ contentModal, setContentModal }}>
{children}
</ModalContext.Provider>
);
};
// Хук для использования контекста
export const useModalContext = (): ModalContextType => {
const context = useContext(ModalContext);
if (!context) {
throw new Error('useModalContext must be used within a ModalProvider');
}
return context;
};
+27
View File
@@ -0,0 +1,27 @@
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 25%;
background-color: #f1f1f1;
position: fixed;
height: 100%;
overflow: auto;
}
li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}
li a.active {
background-color: #04AA6D;
color: white;
}
li a:hover:not(.active) {
background-color: #555;
color: white;
}
+11
View File
@@ -0,0 +1,11 @@
"use client";
import './NavBar.css';
export default function NavBar({children}:any) {
return (
<ul>
{children}
</ul>
);
}
+24
View File
@@ -0,0 +1,24 @@
export default function NavBarItem({
active = false,
children,
onClick,
}: {
active?: boolean;
children: React.ReactNode;
onClick: (event: React.MouseEvent<HTMLAnchorElement>) => void;
}) {
return (
<li>
<a
href="#"
className={active ? "active" : ""}
onClick={(e) => {
e.preventDefault();
onClick(e);
}}
>
{children}
</a>
</li>
);
}
View File
Whitespace-only changes.
+7
View File
@@ -0,0 +1,7 @@
import React from 'react';
export function Select({children, name}: any) {
return (
<></>
);
}
+7
View File
@@ -0,0 +1,7 @@
import React from 'react';
export function Row({children}: any) {
return (
<td>{children}</td>
);
}
+9
View File
@@ -0,0 +1,9 @@
import React from 'react';
export function Rows({children}: any) {
return (
<tr>
{children}
</tr>
);
}
+15
View File
@@ -0,0 +1,15 @@
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
+23
View File
@@ -0,0 +1,23 @@
import React from 'react';
import "./Table.css"
export function Table({ header, children }: any) {
return (
<div>
<table>
<thead>
<tr>
{
header.map((item: any, index: number) => (
<th key={index}>{item}</th>
))
}
</tr>
</thead>
<tbody>
{children}
</tbody>
</table>
</div>
);
}
+29
View File
@@ -0,0 +1,29 @@
import {Input} from "@/components/Input/Input";
import {useState} from "react";
import Button from "@/components/Button/Button";
export default function BodyType({ initialData }: any) {
const [formData, setFormData] = useState({
id: initialData?.id || null,
name: initialData?.name || "",
});
const handleChange = (e: any) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value
});
};
const handleSubmit = () => {
console.log("Collected Data:", formData);
};
return (
<>
<Input value={formData.name} onChange={handleChange} name="name">Наименование</Input>
<Button onClickAction={handleSubmit}>Сохранить</Button>
</>
);
}
+26
View File
@@ -0,0 +1,26 @@
import Button from "@/components/Button/Button";
import {useState} from "react";
export default function Car({ initialData }: any) {
const [formData, setFormData] = useState({
id: initialData?.id || null,
});
const handleChange = (e: any) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value
});
};
const handleSubmit = () => {
console.log("Collected Data:", formData);
};
return (
<>
<Button onClickAction={handleSubmit}>Сохранить</Button>
</>
);
}
+31
View File
@@ -0,0 +1,31 @@
import {Input} from "@/components/Input/Input";
import {useState} from "react";
import Button from "@/components/Button/Button";
export default function CarBrand({ initialData }: any) {
const [formData, setFormData] = useState({
id: initialData?.id || null,
name: initialData?.name || "",
country: initialData?.country || "",
});
const handleChange = (e: any) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value
});
};
const handleSubmit = () => {
console.log("Collected Data:", formData);
};
return (
<>
<Input value={formData.name} onChange={handleChange} name="name">Наименование</Input>
<Input value={formData.country} onChange={handleChange} name="country">Страна</Input>
<Button onClickAction={handleSubmit}>Сохранить</Button>
</>
);
}
+44
View File
@@ -0,0 +1,44 @@
import { useState } from "react";
import {InputColor} from "@/components/Input/InputColor";
import {Input} from "@/components/Input/Input";
import Button from "@/components/Button/Button";
import {add, update} from "@/api/carColors";
import {useModalContext} from "@/components/Modal/ModalContext";
import {useCarColorContext} from "@/api/context/CarColor";
export default function CarColor({ initialData }: any) {
const { setContentModal } = useModalContext();
const { fetchData } = useCarColorContext();
const [formData, setFormData] = useState({
id: initialData?.id || null,
name: initialData?.name || "",
hexCode: initialData?.hexCode || "#000000",
});
const handleChange = (e: any) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value
});
};
const handleSubmit = async () => {
if (formData.id === null) {
await add(formData);
} else {
await update(formData);
}
fetchData();
setContentModal(null);
};
return (
<>
<Input value={formData.name} onChange={handleChange} name="name">Наименование</Input>
<InputColor onChange={handleChange} name="hexCode" />
<Button onClickAction={handleSubmit}>Сохранить</Button>
</>
);
}
+29
View File
@@ -0,0 +1,29 @@
import {Input} from "@/components/Input/Input";
import {useState} from "react";
import Button from "@/components/Button/Button";
export default function CarModel({ initialData }: any) {
const [formDataCarModel, setFormDataCarModel] = useState({
id: initialData?.id || null,
name: initialData?.name || "",
});
const handleChange = (e: any) => {
const { name, value } = e.target;
setFormDataCarModel({
...formDataCarModel,
[name]: value
});
};
const handleSubmit = () => {
console.log("Collected Data:", formDataCarModel);
};
return (
<>
<Input value={formDataCarModel.name} onChange={handleChange} name="name">Наименование</Input>
<Button onClickAction={handleSubmit}>Сохранить</Button>
</>
);
}
+45
View File
@@ -0,0 +1,45 @@
import {Input} from "@/components/Input/Input";
import {useState} from "react";
import Button from "@/components/Button/Button";
import {useModalContext} from "@/components/Modal/ModalContext";
import {add, update} from "@/api/customers";
import {useCustomerContext} from "@/api/context/Customer";
export default function Customer({ initialData }: any) {
const { setContentModal } = useModalContext();
const { fetchData } = useCustomerContext();
const [formData, setFormData] = useState({
id: initialData?.id || null,
name: initialData?.name || "",
phone: initialData?.phone || "",
email: initialData?.email || "",
});
const handleChange = (e: any) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value
});
};
const handleSubmit = async () => {
if (formData.id === null) {
await add(formData);
} else {
await update(formData);
}
fetchData();
setContentModal(null);
};
return (
<>
<Input value={formData.name} onChange={handleChange} name="name">Фамилия Имя Отчество</Input>
<Input value={formData.phone} onChange={handleChange} name="phone">Телефон</Input>
<Input value={formData.email} onChange={handleChange} name="email">Почта</Input>
<Button onClickAction={handleSubmit}>Сохранить</Button>
</>
);
}
+33
View File
@@ -0,0 +1,33 @@
import {Input} from "@/components/Input/Input";
import {useState} from "react";
import Button from "@/components/Button/Button";
export default function Engine({ initialData }: any) {
const [formData, setFormData] = useState({
id: initialData?.id || null,
type: initialData?.type || "",
powerHR: initialData?.powerHR || "",
volume: initialData?.volume || "",
});
const handleChange = (e: any) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value
});
};
const handleSubmit = () => {
console.log("Collected Data:", formData);
};
return (
<>
<Input value={formData.type} onChange={handleChange} name="type">Тип двигателя</Input>
<Input value={formData.powerHR} onChange={handleChange} name="powerHR">Мощность</Input>
<Input value={formData.volume} onChange={handleChange} name="volume">Объем двигателя</Input>
<Button onClickAction={handleSubmit}>Сохранить</Button>
</>
);
}
+16
View File
@@ -0,0 +1,16 @@
import Content from "@/components/Content/Content";
import {Table} from "@/components/Table/Table";
import Button from "@/components/Button/Button";
import {useModalContext} from "@/components/Modal/ModalContext";
export default function Sale() {
const { setContentModal } = useModalContext();
return (
<Content>
<Button onClickAction={() => setContentModal(<></>)}>Добавить элемент</Button>
<Table header={['Код', 'Дата', 'Стоимость', "Действия"]}>
</Table>
</Content>
);
}
+29
View File
@@ -0,0 +1,29 @@
import {Input} from "@/components/Input/Input";
import {useState} from "react";
import Button from "@/components/Button/Button";
export default function Transmission({ initialData }: any) {
const [formData, setFormData] = useState({
id: initialData?.id || null,
type: initialData?.type || "",
});
const handleChange = (e: any) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value
});
};
const handleSubmit = () => {
console.log("Collected Data:", formData);
};
return (
<>
<Input value={formData.type} onChange={handleChange} name="type">Название</Input>
<Button onClickAction={handleSubmit}>Сохранить</Button>
</>
);
}
+31
View File
@@ -0,0 +1,31 @@
import {Input} from "@/components/Input/Input";
import {useState} from "react";
import Button from "@/components/Button/Button";
export default function Trim({ initialData }: any) {
const [formData, setFormData] = useState({
id: initialData?.id || null,
name: initialData?.name || "",
price: initialData?.price || ""
});
const handleChange = (e: any) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value
});
};
const handleSubmit = () => {
console.log("Collected Data:", formData);
};
return (
<>
<Input value={formData.name} onChange={handleChange} name="name">Название комплектации</Input>
<Input value={formData.price} onChange={handleChange} name="price">Цена</Input>
<Button onClickAction={handleSubmit}>Сохранить</Button>
</>
);
}
+17
View File
@@ -0,0 +1,17 @@
import Content from "@/components/Content/Content";
import {Table} from "@/components/Table/Table";
import Button from "@/components/Button/Button";
import {useModalContext} from "@/components/Modal/ModalContext";
import BodyTypeModal from "@/modals/BodyType"
export default function BodyType() {
const { setContentModal } = useModalContext();
return (
<Content>
<Button onClickAction={() => setContentModal(<BodyTypeModal />)}>Добавить элемент</Button>
<Table header={['Код', 'Наименование', "Действия"]}>
</Table>
</Content>
);
}
+16
View File
@@ -0,0 +1,16 @@
import Content from "@/components/Content/Content";
import {Table} from "@/components/Table/Table";
import Button from "@/components/Button/Button";
import {useModalContext} from "@/components/Modal/ModalContext";
export default function Car() {
const { setContentModal } = useModalContext();
return (
<Content>
<Button onClickAction={() => setContentModal(<></>)}>Добавить элемент</Button>
<Table header={['Код', "Действия"]}>
</Table>
</Content>
);
}
+17
View File
@@ -0,0 +1,17 @@
import Content from "@/components/Content/Content";
import {Table} from "@/components/Table/Table";
import Button from "@/components/Button/Button";
import {useModalContext} from "@/components/Modal/ModalContext";
import CarBrandModal from "@/modals/CarBrand";
export default function CarBrand() {
const { setContentModal } = useModalContext();
return (
<Content>
<Button onClickAction={() => setContentModal(<CarBrandModal />)}>Добавить элемент</Button>
<Table header={['Код', 'Наименование', 'Страна', "Действия"]}>
</Table>
</Content>
);
}
+40
View File
@@ -0,0 +1,40 @@
import Content from "@/components/Content/Content";
import {Table} from "@/components/Table/Table";
import Button from "@/components/Button/Button";
import {useModalContext} from "@/components/Modal/ModalContext";
import CarColorModal from "@/modals/CarColor";
import {Rows} from "@/components/Table/Rows";
import {Row} from "@/components/Table/Row";
import {useCarColorContext} from "@/api/context/CarColor";
import {remove} from "@/api/carColors";
export default function CarColor() {
const { setContentModal } = useModalContext();
const { carColor, fetchData } = useCarColorContext();
if (!carColor) {
return <div>Loading...</div>;
}
return (
<Content>
<Button onClickAction={() => setContentModal(<CarColorModal />)}>Добавить элемент</Button>
<Table header={['Код', 'Наименование', "Цвет HEX", "Действия"]}>
{carColor.map((item, index) => (
<Rows key={index}>
<Row>{item.id}</Row>
<Row>{item.name}</Row>
<Row>{item.hexCode}</Row>
<Row>
<Button onClickAction={() => setContentModal(<CarColorModal initialData={item} />)}>Редактировать</Button>
<Button onClickAction={async () => {
await remove(item)
fetchData()
}}>Удалить</Button>
</Row>
</Rows>
))}
</Table>
</Content>
);
}
+17
View File
@@ -0,0 +1,17 @@
import Content from "@/components/Content/Content";
import {Table} from "@/components/Table/Table";
import Button from "@/components/Button/Button";
import {useModalContext} from "@/components/Modal/ModalContext";
import CarModelsModal from "@/modals/CarModel";
export default function CarModel() {
const { setContentModal } = useModalContext();
return (
<Content>
<Button onClickAction={() => setContentModal(<CarModelsModal />)}>Добавить элемент</Button>
<Table header={['Код', 'Наименование', 'Год начала', 'Год окончания', "Действия"]}>
</Table>
</Content>
);
}
+41
View File
@@ -0,0 +1,41 @@
import Content from "@/components/Content/Content";
import {Table} from "@/components/Table/Table";
import Button from "@/components/Button/Button";
import {useModalContext} from "@/components/Modal/ModalContext";
import CustomerModal from "@/modals/Customer";
import {useCustomerContext} from "@/api/context/Customer";
import {Rows} from "@/components/Table/Rows";
import {Row} from "@/components/Table/Row";
import {remove} from "@/api/customers";
export default function Customer() {
const { setContentModal } = useModalContext();
const { customers, fetchData } = useCustomerContext();
if (!customers) {
return <div>Loading...</div>;
}
return (
<Content>
<Button onClickAction={() => setContentModal(<CustomerModal />)}>Добавить элемент</Button>
<Table header={['Код', 'ФИО', 'Телофон', 'Почта', "Действия"]}>
{customers.map((item, index) => (
<Rows key={index}>
<Row>{item.id}</Row>
<Row>{item.name}</Row>
<Row>{item.phone}</Row>
<Row>{item.email}</Row>
<Row>
<Button onClickAction={() => setContentModal(<CustomerModal initialData={item} />)}>Редактировать</Button>
<Button onClickAction={async () => {
await remove(item);
fetchData();
}}>Удалить</Button>
</Row>
</Rows>
))}
</Table>
</Content>
);
}
+17
View File
@@ -0,0 +1,17 @@
import Content from "@/components/Content/Content";
import {Table} from "@/components/Table/Table";
import Button from "@/components/Button/Button";
import {useModalContext} from "@/components/Modal/ModalContext";
import EngineModal from "@/modals/Engine";
export default function Engine() {
const { setContentModal } = useModalContext();
return (
<Content>
<Button onClickAction={() => setContentModal(<EngineModal />)}>Добавить элемент</Button>
<Table header={['Код', 'Тип двигателя', 'мощность (в лошадиных силах)', 'Объем двигателя', "Действия"]}>
</Table>
</Content>
);
}
+17
View File
@@ -0,0 +1,17 @@
import Content from "@/components/Content/Content";
import {Table} from "@/components/Table/Table";
import Button from "@/components/Button/Button";
import {useModalContext} from "@/components/Modal/ModalContext";
import SaleModal from "@/modals/Sale";
export default function Sale() {
const { setContentModal } = useModalContext();
return (
<Content>
<Button onClickAction={() => setContentModal(<SaleModal />)}>Добавить элемент</Button>
<Table header={['Код', 'Дата', 'Стоимость', "Действия"]}>
</Table>
</Content>
);
}
+17
View File
@@ -0,0 +1,17 @@
import Content from "@/components/Content/Content";
import {Table} from "@/components/Table/Table";
import Button from "@/components/Button/Button";
import {useModalContext} from "@/components/Modal/ModalContext";
import TransmissionModal from "@/modals/Transmission";
export default function Transmission() {
const { setContentModal } = useModalContext();
return (
<Content>
<Button onClickAction={() => setContentModal(<TransmissionModal />)}>Добавить элемент</Button>
<Table header={['Код', 'Тип трансмиссии', "Действия"]}>
</Table>
</Content>
);
}
+17
View File
@@ -0,0 +1,17 @@
import Content from "@/components/Content/Content";
import {Table} from "@/components/Table/Table";
import Button from "@/components/Button/Button";
import {useModalContext} from "@/components/Modal/ModalContext";
import TrimModal from "@/modals/Trim";
export default function Trim() {
const { setContentModal } = useModalContext();
return (
<Content>
<Button onClickAction={() => setContentModal(<TrimModal />)}>Добавить элемент</Button>
<Table header={['Код', 'Название комплектации', 'Цена', "Действия"]}>
</Table>
</Content>
);
}