81 lines
2.0 KiB
TypeScript
81 lines
2.0 KiB
TypeScript
import createContextHook from '@nkzw/create-context-hook';
|
|
import { useState } from 'react';
|
|
import { Announcement, Bonus, Employee, ProductService } from './type';
|
|
|
|
export const [ProfileDataProvider, useProfileData] = createContextHook(() => {
|
|
const [employees, setEmployees] = useState<Employee[]>([
|
|
{
|
|
id: '1',
|
|
firstName: 'Aziz',
|
|
lastName: 'Rahimov',
|
|
phoneNumber: '+998901234567',
|
|
addedAt: new Date().toISOString(),
|
|
},
|
|
]);
|
|
|
|
const [announcements] = useState<Announcement[]>([
|
|
{
|
|
id: '1',
|
|
name: "Yangi loyiha bo'yicha hamkorlik",
|
|
companyTypes: ['IT', 'Qurilish'],
|
|
totalAmount: 5000000,
|
|
paymentStatus: 'paid',
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
]);
|
|
|
|
const [bonuses] = useState<Bonus[]>([
|
|
{
|
|
id: '1',
|
|
title: 'Yillik bonus',
|
|
description: "Yil davomida ko'rsatilgan yuqori natijalarga oid bonus",
|
|
percentage: 15,
|
|
bonusAmount: 3000000,
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
]);
|
|
|
|
const [productServices, setProductServices] = useState<ProductService[]>([]);
|
|
|
|
const addEmployee = (employee: Omit<Employee, 'id' | 'addedAt'>) => {
|
|
setEmployees((prev) => [
|
|
...prev,
|
|
{
|
|
...employee,
|
|
id: Date.now().toString(),
|
|
addedAt: new Date().toISOString(),
|
|
},
|
|
]);
|
|
};
|
|
|
|
const removeEmployee = (id: string) => {
|
|
setEmployees((prev) => prev.filter((e) => e.id !== id));
|
|
};
|
|
|
|
const updateEmployee = (id: string, data: Partial<Employee>) => {
|
|
setEmployees((prev) => prev.map((e) => (e.id === id ? { ...e, ...data } : e)));
|
|
};
|
|
|
|
const addProductService = (service: Omit<ProductService, 'id' | 'createdAt'>) => {
|
|
setProductServices((prev) => [
|
|
...prev,
|
|
{
|
|
...service,
|
|
id: Date.now().toString(),
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
]);
|
|
};
|
|
|
|
return {
|
|
employees,
|
|
addEmployee,
|
|
removeEmployee,
|
|
updateEmployee,
|
|
announcements,
|
|
bonuses,
|
|
productServices,
|
|
addProductService,
|
|
};
|
|
});
|