Compare commits
24
Commits
76009e4abb
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2b6591246 | ||
|
|
d4d3e5d3b1 | ||
|
|
03766057eb | ||
|
|
c74ef84d37 | ||
|
|
15115c5114 | ||
|
|
8928960c34 | ||
|
|
96808c4a12 | ||
|
|
e5a09cd676 | ||
|
|
1dbb6f46c9 | ||
|
|
52bcd63a30 | ||
|
|
c2978bb276 | ||
|
|
05e04886c3 | ||
|
|
c626b697e2 | ||
|
|
a3ff04e545 | ||
|
|
d7521e6ad1 | ||
|
|
e4508cb788 | ||
|
|
df82b7e451 | ||
|
|
b61d6527c4 | ||
|
|
9db7f6b08d | ||
|
|
f5c99f1e09 | ||
|
|
b59cd5d9ff | ||
|
|
09937b2a7b | ||
|
|
c470af4709 | ||
|
|
3770e12d20 |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "no-copy-admin-panel-frontend",
|
"name": "no-copy-admin-panel-frontend",
|
||||||
"version": "0.11.0",
|
"version": "0.17.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev -p 2996",
|
"dev": "next dev -p 2996",
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
@@ -1,29 +1,29 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import ContentModerationTable from '@/app/ui/content/content-moderation-table';
|
||||||
|
import ContentAppealsTable from '@/app/ui/content/content-appeals-table';
|
||||||
|
import { useEmployeInfo } from '@/app/hooks/react-query/useEmployeInfo';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
|
const { getPermissionLevel } = useEmployeInfo();
|
||||||
|
const contentModerationPermissionLevel = getPermissionLevel('content_moderation');
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="admin-content">
|
<div className="admin-content">
|
||||||
<div className="content-header">
|
<div className="content-header">
|
||||||
<h3>Управление контентом</h3>
|
<h3>Управление контентом</h3>
|
||||||
<div className="content-header-actions">
|
</div>
|
||||||
<div className="search-box">
|
{getPermissionLevel('content_moderation') > 0 && (
|
||||||
<span>🔍</span>
|
<>
|
||||||
<input type="text" id="content-search" placeholder="Поиск контента..." />
|
<div className="content-body">
|
||||||
|
<ContentModerationTable permission={contentModerationPermissionLevel} />
|
||||||
</div>
|
</div>
|
||||||
<select id="content-type-filter">
|
<div className="content-body">
|
||||||
<option value="all">Все типы</option>
|
<ContentAppealsTable permission={contentModerationPermissionLevel} />
|
||||||
<option value="image">Изображения</option>
|
</div>
|
||||||
<option value="video">Видео</option>
|
</>
|
||||||
<option value="audio">Аудио</option>
|
)}
|
||||||
<option value="document">Документы</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="content-body" id="content-container">
|
|
||||||
<div className="empty-state">
|
|
||||||
<div className="empty-state-icon">🗂️</div>
|
|
||||||
<h4>Контент не найден</h4>
|
|
||||||
<p>Попробуйте изменить параметры поиска</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,20 @@
|
|||||||
|
|
||||||
import TanstakStuffTable from '@/app/ui/staff-management/tanstak-stuff-table';
|
import TanstakStuffTable from '@/app/ui/staff-management/tanstak-stuff-table';
|
||||||
import { CreateStaffForm } from '@/app/ui/forms/create-staff-form';
|
import { CreateStaffForm } from '@/app/ui/forms/create-staff-form';
|
||||||
|
import { useEmployeInfo } from '@/app/hooks/react-query/useEmployeInfo';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
|
const { getPermissionLevel } = useEmployeInfo();
|
||||||
|
const staffPermissionLevel = getPermissionLevel('staff');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<CreateStaffForm />
|
{staffPermissionLevel === 3 && (
|
||||||
<TanstakStuffTable />
|
<CreateStaffForm />
|
||||||
|
)}
|
||||||
|
{staffPermissionLevel > 0 && (
|
||||||
|
<TanstakStuffTable permission={staffPermissionLevel} />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,78 +1,6 @@
|
|||||||
|
import TariffManagment from '@/app/ui/tariff-management/tariff-management';
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<div className="admin-content">
|
<TariffManagment />
|
||||||
<div className="content-header">
|
|
||||||
<h3>Управление тарифными планами</h3>
|
|
||||||
<div className="content-header-actions">
|
|
||||||
<button className="btn btn-primary">
|
|
||||||
<span>➕</span>
|
|
||||||
<span>Создать тариф</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="content-body" id="plans-container">
|
|
||||||
<div className="stats-grid">
|
|
||||||
<div className="stat-card">
|
|
||||||
<div className="stat-card-header">
|
|
||||||
<span className="stat-card-title">FREE</span>
|
|
||||||
<div className="stat-card-icon blue">🆓</div>
|
|
||||||
</div>
|
|
||||||
<div className="stat-card-value">₽0</div>
|
|
||||||
<div className="stat-card-label">100 токенов</div>
|
|
||||||
<div className="stat-card-footer">
|
|
||||||
<button className="btn btn-outline btn-sm">Редактировать</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="stat-card">
|
|
||||||
<div className="stat-card-header">
|
|
||||||
<span className="stat-card-title">MINI (TELEGRAM)</span>
|
|
||||||
<div className="stat-card-icon cyan">✈️</div>
|
|
||||||
</div>
|
|
||||||
<div className="stat-card-value">₽500</div>
|
|
||||||
<div className="stat-card-label">500 токенов</div>
|
|
||||||
<div className="stat-card-footer">
|
|
||||||
<button className="btn btn-outline btn-sm">Редактировать</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="stat-card">
|
|
||||||
<div className="stat-card-header">
|
|
||||||
<span className="stat-card-title">BASIC</span>
|
|
||||||
<div className="stat-card-icon green">⭐</div>
|
|
||||||
</div>
|
|
||||||
<div className="stat-card-value">₽990</div>
|
|
||||||
<div className="stat-card-label">1,000 токенов</div>
|
|
||||||
<div className="stat-card-footer">
|
|
||||||
<button className="btn btn-outline btn-sm">Редактировать</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="stat-card">
|
|
||||||
<div className="stat-card-header">
|
|
||||||
<span className="stat-card-title">PRO</span>
|
|
||||||
<div className="stat-card-icon purple">💎</div>
|
|
||||||
</div>
|
|
||||||
<div className="stat-card-value">₽2,990</div>
|
|
||||||
<div className="stat-card-label">5,000 токенов</div>
|
|
||||||
<div className="stat-card-footer">
|
|
||||||
<button className="btn btn-outline btn-sm">Редактировать</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="stat-card">
|
|
||||||
<div className="stat-card-header">
|
|
||||||
<span className="stat-card-title">BUSINESS</span>
|
|
||||||
<div className="stat-card-icon orange">🏢</div>
|
|
||||||
</div>
|
|
||||||
<div className="stat-card-value">₽9,990</div>
|
|
||||||
<div className="stat-card-label">20,000 токенов</div>
|
|
||||||
<div className="stat-card-footer">
|
|
||||||
<button className="btn btn-outline btn-sm">Редактировать</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
+114
-37
@@ -9,19 +9,14 @@ export async function authorization(
|
|||||||
previousState: {
|
previousState: {
|
||||||
email: string;
|
email: string;
|
||||||
}
|
}
|
||||||
error: Record<string, string>
|
error: Record<string, string>;
|
||||||
|
requirePasswordChange?: boolean;
|
||||||
|
userData?: { email: string; id: number };
|
||||||
} | undefined,
|
} | undefined,
|
||||||
formData: FormData,
|
formData: FormData,
|
||||||
) {
|
) {
|
||||||
const email = formData.get('email') as string || '';
|
const email = formData.get('email') as string || '';
|
||||||
const password = formData.get('password');
|
const password = formData.get('password') as string || '';
|
||||||
|
|
||||||
/* для теста */
|
|
||||||
if (email === 'test' && password === 'test') {
|
|
||||||
/* await createSession('1111', 'test', 0); */
|
|
||||||
/* redirect('/pages/'); */
|
|
||||||
}
|
|
||||||
/* для теста */
|
|
||||||
|
|
||||||
const validatedFields = loginFormSchema.safeParse({
|
const validatedFields = loginFormSchema.safeParse({
|
||||||
email,
|
email,
|
||||||
@@ -51,11 +46,11 @@ export async function authorization(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { email, password } = validatedFields.data;
|
const { email, password } = validatedFields.data;
|
||||||
const response = await fetch(`${API_BASE_URL}/api/admin`, {
|
const response = await fetch(`${API_BASE_URL}/api/admin/login`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
version: 1,
|
version: 1,
|
||||||
msg_id: 100,
|
msg_id: 101,
|
||||||
message_body: {
|
message_body: {
|
||||||
action: "login",
|
action: "login",
|
||||||
email: email,
|
email: email,
|
||||||
@@ -67,9 +62,27 @@ export async function authorization(
|
|||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
let parsed = await response.json();
|
let parsed = await response.json();
|
||||||
if (parsed.message_code === 0) {
|
if (parsed.message_code === 0) {
|
||||||
|
if (!parsed.message_body.admin.active_password) {
|
||||||
|
const errors: Record<string, string> = {}
|
||||||
|
return {
|
||||||
|
previousState: {
|
||||||
|
email
|
||||||
|
},
|
||||||
|
error: errors,
|
||||||
|
requirePasswordChange: true,
|
||||||
|
userData: {
|
||||||
|
email: parsed.message_body.admin.email,
|
||||||
|
id: parsed.message_body.admin.id,
|
||||||
|
password: password,
|
||||||
|
token: parsed.message_body.token
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
await createSession(parsed.message_body.token, email, parsed.message_body.admin.id);
|
await createSession(parsed.message_body.token, email, parsed.message_body.admin.id);
|
||||||
} else {
|
} else {
|
||||||
throw (`${parsed.message_code}`);
|
throw (`${parsed.message_code}`);
|
||||||
@@ -95,16 +108,80 @@ export async function authorization(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
return {
|
||||||
|
previousState: {
|
||||||
|
email,
|
||||||
|
password
|
||||||
|
},
|
||||||
|
error: errors
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
redirect('/pages/');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updatePasswordAction(
|
||||||
|
id: number,
|
||||||
|
oldPassword: string | null,
|
||||||
|
newPassword: string,
|
||||||
|
email: string,
|
||||||
|
token: string
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const requestBody: any = {
|
||||||
|
version: 1,
|
||||||
|
msg_id: 100,
|
||||||
|
message_body: {
|
||||||
|
action: "update",
|
||||||
|
admin_id: id,
|
||||||
|
new_password: newPassword
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (oldPassword) {
|
||||||
|
requestBody.message_body.old_password = oldPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/admin`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(requestBody),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const parsed = await response.json();
|
||||||
|
|
||||||
|
if (parsed.message_code === 0) {
|
||||||
|
console.log(parsed);
|
||||||
|
if (parsed.message_desc === 'Success') {
|
||||||
|
console.log('Success');
|
||||||
|
await createSession(token, email, id);
|
||||||
|
return { success: true };
|
||||||
|
} else {
|
||||||
|
return { success: false };
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: `password-update-failed-code-${parsed.message_code}`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return {
|
return {
|
||||||
previousState: {
|
success: false,
|
||||||
email,
|
error: 'request-ended-with-an-error'
|
||||||
password
|
|
||||||
},
|
|
||||||
error: errors
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
throw error;
|
} catch (error) {
|
||||||
|
console.error('Password update error:', error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: 'password-update-failed'
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect('/pages/');
|
redirect('/pages/');
|
||||||
@@ -114,25 +191,25 @@ export async function logout() {
|
|||||||
const token = await getSessionData('token');
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/admin`, {
|
/* const response = await fetch(`${API_BASE_URL}/api/admin`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
version: 1,
|
version: 1,
|
||||||
msg_id: 100,
|
msg_id: 100,
|
||||||
token: token,
|
token: token,
|
||||||
message_body: {
|
message_body: {
|
||||||
action: "logout"
|
action: "logout"
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
let parsed = await response.json();
|
let parsed = await response.json();
|
||||||
}
|
} */
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -0,0 +1,200 @@
|
|||||||
|
'use server'
|
||||||
|
|
||||||
|
import { getSessionData } from '@/app/actions/session';
|
||||||
|
import { API_BASE_URL } from '@/app/actions/definitions';
|
||||||
|
|
||||||
|
type ModerationStatus = 'BLOCKED' | 'ACTIVE' | 'MODERATION';
|
||||||
|
|
||||||
|
export async function fetchModerationContentList(
|
||||||
|
page?: number,
|
||||||
|
size?: number,
|
||||||
|
sortBy?: string,
|
||||||
|
sortDirection?: 'asc' | 'desc' | string,
|
||||||
|
statuses?: ModerationStatus[],
|
||||||
|
isAppeal?: boolean
|
||||||
|
) {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
version: 1,
|
||||||
|
msg_id: 40001,
|
||||||
|
message_body: {
|
||||||
|
action: 'files_for_moderation',
|
||||||
|
page: page,
|
||||||
|
page_size: size,
|
||||||
|
sort_by: sortBy || '',
|
||||||
|
sort_order: sortDirection || 'asc',
|
||||||
|
statuses: statuses,
|
||||||
|
is_appeal: isAppeal,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const parsed = await response.json();
|
||||||
|
|
||||||
|
if (parsed.message_code === 0) {
|
||||||
|
return parsed.message_body.message_body;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error(`${response.status}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function changeModerationContentStatus(fileId?: string, fileStatus?: string) {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/admin/control`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
version: 1,
|
||||||
|
msg_id: 40002,
|
||||||
|
message_body: {
|
||||||
|
action: 'change_file_status',
|
||||||
|
file_id: fileId,
|
||||||
|
file_status: fileStatus
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const parsed = await response.json();
|
||||||
|
console.log(parsed);
|
||||||
|
|
||||||
|
if (parsed.message_code === 0) {
|
||||||
|
return parsed.message_body.message_body;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error(`${response.status}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function downloadFile(fileId: string, fileName: string) {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/admin/download/${fileId}`, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw 'failed-to-download-file';
|
||||||
|
}
|
||||||
|
|
||||||
|
const arrayBuffer = await response.arrayBuffer()
|
||||||
|
const base64 = Buffer.from(arrayBuffer).toString('base64')
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: base64,
|
||||||
|
contentType: response.headers.get('content-type') || 'application/octet-stream',
|
||||||
|
fileName: fileName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchAppealsContentList(page?: number, size?: number, sortBy?: string, sortDirection?: 'asc' | 'desc' | string) {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
version: 1,
|
||||||
|
msg_id: 40001,
|
||||||
|
message_body: {
|
||||||
|
action: 'all_appeals',
|
||||||
|
page: page,
|
||||||
|
page_size: size,
|
||||||
|
sort_by: sortBy || '',
|
||||||
|
sort_order: sortDirection || 'asc',
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const parsed = await response.json();
|
||||||
|
|
||||||
|
if (parsed.message_code === 0) {
|
||||||
|
return parsed.message_body.message_body;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error(`${response.status}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function changeAppealContentStatus(appealId?: string, approve?: boolean, comment?: string) {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/admin/control`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
version: 1,
|
||||||
|
msg_id: 40002,
|
||||||
|
message_body: {
|
||||||
|
action: 'review_appeal',
|
||||||
|
appeal_id: appealId,
|
||||||
|
approve: approve,
|
||||||
|
comment: comment
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const parsed = await response.json();
|
||||||
|
|
||||||
|
if (parsed.message_code === 0) {
|
||||||
|
return parsed.message_body.message_body;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error(`${response.status}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,4 +18,10 @@ export const localDevelopmentUrl = process.env.DEV_URL
|
|||||||
|
|
||||||
export const API_BASE_URL = process.env.NODE_ENV === 'development'
|
export const API_BASE_URL = process.env.NODE_ENV === 'development'
|
||||||
? localDevelopmentUrl
|
? localDevelopmentUrl
|
||||||
: 'http://admin:8082';
|
: 'http://admin:8082';
|
||||||
|
|
||||||
|
export const localDashBoardDevelopmentUrl = process.env.DEV_URL ? process.env.DEV_URL : 'http://localhost';
|
||||||
|
|
||||||
|
export const API_DASHBOARD_URL = process.env.NODE_ENV === 'development'
|
||||||
|
? localDashBoardDevelopmentUrl
|
||||||
|
: 'http://app:8080';
|
||||||
@@ -121,7 +121,7 @@ export async function getSessionData(type: 'token' | 'email' | 'employeId'): Pro
|
|||||||
|
|
||||||
|
|
||||||
export async function deleteSession() {
|
export async function deleteSession() {
|
||||||
console.log('delete session')
|
|
||||||
try {
|
try {
|
||||||
const cookieStore = await cookies()
|
const cookieStore = await cookies()
|
||||||
cookieStore.delete('session_nc_ap');
|
cookieStore.delete('session_nc_ap');
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { API_BASE_URL } from '@/app/actions/definitions';
|
|||||||
import { getSessionData } from '@/app/actions/session';
|
import { getSessionData } from '@/app/actions/session';
|
||||||
|
|
||||||
export async function fetchTariffStatistic() {
|
export async function fetchTariffStatistic() {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
||||||
@@ -17,7 +18,8 @@ export async function fetchTariffStatistic() {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -39,6 +41,7 @@ export async function fetchTariffStatistic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchUserFilesTopStatistic() {
|
export async function fetchUserFilesTopStatistic() {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
||||||
@@ -52,7 +55,8 @@ export async function fetchUserFilesTopStatistic() {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -74,6 +78,7 @@ export async function fetchUserFilesTopStatistic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchUserGeneralStatistic() {
|
export async function fetchUserGeneralStatistic() {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
||||||
@@ -87,7 +92,8 @@ export async function fetchUserGeneralStatistic() {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -109,6 +115,7 @@ export async function fetchUserGeneralStatistic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchSubscribeGeneralStatistic() {
|
export async function fetchSubscribeGeneralStatistic() {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
||||||
@@ -122,7 +129,8 @@ export async function fetchSubscribeGeneralStatistic() {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -144,6 +152,7 @@ export async function fetchSubscribeGeneralStatistic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchProtectedContentGeneralStatistic() {
|
export async function fetchProtectedContentGeneralStatistic() {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
||||||
@@ -157,7 +166,8 @@ export async function fetchProtectedContentGeneralStatistic() {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -179,6 +189,7 @@ export async function fetchProtectedContentGeneralStatistic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchViolationGeneralStatistic() {
|
export async function fetchViolationGeneralStatistic() {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
||||||
@@ -192,7 +203,8 @@ export async function fetchViolationGeneralStatistic() {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -214,6 +226,7 @@ export async function fetchViolationGeneralStatistic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchTokensGeneralStatistic() {
|
export async function fetchTokensGeneralStatistic() {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
||||||
@@ -227,7 +240,8 @@ export async function fetchTokensGeneralStatistic() {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -249,6 +263,7 @@ export async function fetchTokensGeneralStatistic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchIncomeGeneralStatistic() {
|
export async function fetchIncomeGeneralStatistic() {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
||||||
@@ -262,7 +277,8 @@ export async function fetchIncomeGeneralStatistic() {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ export async function fetchStuffList(page?: number, size?: number, sortBy?: stri
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
version: 1,
|
version: 1,
|
||||||
msg_id: 100,
|
msg_id: 100,
|
||||||
token: token,
|
|
||||||
message_body: {
|
message_body: {
|
||||||
action: 'get_all',
|
action: 'get_all',
|
||||||
page: page,
|
page: page,
|
||||||
@@ -24,7 +23,8 @@ export async function fetchStuffList(page?: number, size?: number, sortBy?: stri
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -83,7 +83,8 @@ export async function createStuff(fullName: string, email: string, password: str
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -124,7 +125,8 @@ export async function removeStuff(id: number) {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -166,7 +168,8 @@ export async function updateStuffPermissions(id: number, permissions: Permission
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -204,7 +207,8 @@ export async function fetchEmployeInfo() {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -240,7 +244,8 @@ export async function fetchStuffTemplates() {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -279,7 +284,8 @@ export async function createStuffTemplates(name: string, changePassword: boolean
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -316,7 +322,8 @@ export async function removeStuffTemplates(id: number,) {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,201 @@
|
|||||||
|
'use server'
|
||||||
|
|
||||||
|
import { getSessionData } from '@/app/actions/session';
|
||||||
|
import { API_BASE_URL } from '@/app/actions/definitions';
|
||||||
|
|
||||||
|
export async function fetchTariffs(page: number) {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
version: 1,
|
||||||
|
msg_id: 40004,
|
||||||
|
message_body: {
|
||||||
|
action: 'get_all',
|
||||||
|
page: page,
|
||||||
|
page_size: 8
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const parsed = await response.json();
|
||||||
|
|
||||||
|
if (parsed.message_code === 0) {
|
||||||
|
return parsed.message_body.message_body;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error(`${response.status}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateTariffs(
|
||||||
|
id: number,
|
||||||
|
tariffPrice: number,
|
||||||
|
tariffName: string,
|
||||||
|
type: string,
|
||||||
|
tariffTokens: number,
|
||||||
|
maxFiles: number,
|
||||||
|
diskSize: number,
|
||||||
|
maxUsers: number,
|
||||||
|
description: string,
|
||||||
|
tariffTerm: 'MONTHLY' | 'YEAR',
|
||||||
|
accountType: 'b2c' | 'b2b' | 'token'
|
||||||
|
) {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/admin/control`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
version: 1,
|
||||||
|
msg_id: 40003,
|
||||||
|
message_body: {
|
||||||
|
action: 'add',
|
||||||
|
id: id,
|
||||||
|
tariff_price: tariffPrice,
|
||||||
|
tariff_name: tariffName,
|
||||||
|
type: type,
|
||||||
|
tariff_tokens: tariffTokens,
|
||||||
|
max_files: maxFiles,
|
||||||
|
disk_size: diskSize,
|
||||||
|
max_users: maxUsers,
|
||||||
|
description: description,
|
||||||
|
tariff_term: tariffTerm,
|
||||||
|
account_type: accountType
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const parsed = await response.json();
|
||||||
|
|
||||||
|
if (parsed.message_code === 0) {
|
||||||
|
return parsed.message_body.message_body;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error(`${response.status}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addTariffs(
|
||||||
|
tariffPrice: number,
|
||||||
|
tariffName: string,
|
||||||
|
type: string,
|
||||||
|
tariffTokens: number,
|
||||||
|
maxFiles: number,
|
||||||
|
diskSize: number,
|
||||||
|
maxUsers: number,
|
||||||
|
description: string,
|
||||||
|
tariffTerm: 'MONTHLY' | 'YEAR',
|
||||||
|
accountType: 'b2c' | 'b2b' | 'token'
|
||||||
|
) {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/admin/control`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
version: 1,
|
||||||
|
msg_id: 40003,
|
||||||
|
message_body: {
|
||||||
|
action: 'add',
|
||||||
|
tariff_price: tariffPrice,
|
||||||
|
tariff_name: tariffName,
|
||||||
|
type: type,
|
||||||
|
tariff_tokens: tariffTokens,
|
||||||
|
max_files: maxFiles,
|
||||||
|
disk_size: diskSize,
|
||||||
|
max_users: maxUsers,
|
||||||
|
description: description,
|
||||||
|
tariff_term: tariffTerm,
|
||||||
|
account_type: accountType
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const parsed = await response.json();
|
||||||
|
|
||||||
|
if (parsed.message_code === 0) {
|
||||||
|
return parsed.message_body.message_body;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error(`${response.status}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function removeTariffs(
|
||||||
|
id: number
|
||||||
|
) {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/admin/control`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
version: 1,
|
||||||
|
msg_id: 40003,
|
||||||
|
message_body: {
|
||||||
|
action: 'remove',
|
||||||
|
id: id
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const parsed = await response.json();
|
||||||
|
|
||||||
|
if (parsed.message_code === 0) {
|
||||||
|
return parsed.message_body.message_body;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error(`${response.status}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,6 @@ export async function fetchUsesData(page: number, size: number, sortBy?: string,
|
|||||||
version: 1,
|
version: 1,
|
||||||
msg_id: 30014,
|
msg_id: 30014,
|
||||||
message_body: {
|
message_body: {
|
||||||
/* token: token, */
|
|
||||||
action: 'getAllWithPagination',
|
action: 'getAllWithPagination',
|
||||||
page: page,
|
page: page,
|
||||||
size: size,
|
size: size,
|
||||||
@@ -24,7 +23,8 @@ export async function fetchUsesData(page: number, size: number, sortBy?: string,
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -46,6 +46,7 @@ export async function fetchUsesData(page: number, size: number, sortBy?: string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchUsesInfo(userInfo: number) {
|
export async function fetchUsesInfo(userInfo: number) {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
||||||
@@ -60,7 +61,8 @@ export async function fetchUsesInfo(userInfo: number) {
|
|||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { IconImageFile, IconVideoFile, IconAudioFile, IconDocument } from '@/app/ui/icons/icons';
|
||||||
|
|
||||||
|
export const FileTypeIcon = ({ type }: { type: string }) => {
|
||||||
|
switch (type) {
|
||||||
|
case 'image':
|
||||||
|
return <span className="color-image">
|
||||||
|
<IconImageFile />
|
||||||
|
</span>;
|
||||||
|
case 'video':
|
||||||
|
return <span className="color-video">
|
||||||
|
<IconVideoFile />
|
||||||
|
</span>;
|
||||||
|
case 'audio':
|
||||||
|
return <span className="color-audio">
|
||||||
|
<IconAudioFile />
|
||||||
|
</span>;
|
||||||
|
default:
|
||||||
|
return <span className="color-document">
|
||||||
|
<IconDocument />
|
||||||
|
</span>;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { fetchAppealsContentList } from '@/app/actions/contentActions';
|
||||||
|
|
||||||
|
export interface AppealsFile {
|
||||||
|
additionalInfo: string;
|
||||||
|
adminComment: string;
|
||||||
|
appealId: string;
|
||||||
|
appealReason: string;
|
||||||
|
createdAt: string;
|
||||||
|
fileId: string;
|
||||||
|
resolvedAt: string;
|
||||||
|
fileName: string;
|
||||||
|
status: 'REJECTED' | 'APPROVED' | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ContentForAppeals {
|
||||||
|
appeals: AppealsFile[];
|
||||||
|
totalPages: number;
|
||||||
|
currentPage: number;
|
||||||
|
pageSize: number;
|
||||||
|
totalCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useContentForAppeals = (
|
||||||
|
page?: number,
|
||||||
|
size?: number,
|
||||||
|
sortBy?: string,
|
||||||
|
sortDirection?: 'asc' | 'desc' | string
|
||||||
|
) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ['contentForAppeals', page, size, sortBy, sortDirection],
|
||||||
|
queryFn: () => {
|
||||||
|
return fetchAppealsContentList(page, size, sortBy, sortDirection);
|
||||||
|
},
|
||||||
|
select: (data: ContentForAppeals | null) => {
|
||||||
|
if (!data) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
refetchInterval: 30000,
|
||||||
|
placeholderData: (previousData) => previousData // для оптимистичных обновлений
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { fetchModerationContentList } from '@/app/actions/contentActions';
|
||||||
|
|
||||||
|
export interface AppealInfo {
|
||||||
|
additionalInfo: string | null;
|
||||||
|
adminComment: null;
|
||||||
|
appealId: string | null;
|
||||||
|
appealReason: string | null;
|
||||||
|
createdAt: string | null;
|
||||||
|
fileId: string | null;
|
||||||
|
fileName: string | null;
|
||||||
|
resolvedAt: string | null;
|
||||||
|
status: string;
|
||||||
|
}
|
||||||
|
export interface ModerationFile {
|
||||||
|
fileName: string;
|
||||||
|
moderationInfo: {
|
||||||
|
appealInfo: null | AppealInfo;
|
||||||
|
hasActiveAppeal: boolean;
|
||||||
|
};
|
||||||
|
userId: number;
|
||||||
|
fileId: string;
|
||||||
|
status: 'BLOCKED' | 'MODERATION' | string;
|
||||||
|
image: string;
|
||||||
|
downloadUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ContentForModeration {
|
||||||
|
files: ModerationFile[];
|
||||||
|
totalPages: number;
|
||||||
|
currentPage: number;
|
||||||
|
pageSize: number;
|
||||||
|
totalCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ModerationStatus = 'BLOCKED' | 'ACTIVE' | 'MODERATION';
|
||||||
|
|
||||||
|
export const useContentForModeration = (
|
||||||
|
page?: number,
|
||||||
|
size?: number,
|
||||||
|
sortBy?: string,
|
||||||
|
sortDirection?: 'asc' | 'desc' | string,
|
||||||
|
statuses?: ModerationStatus[],
|
||||||
|
isAppeal?: boolean
|
||||||
|
) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ['contentForModeration', page, size, sortBy, sortDirection, statuses, isAppeal],
|
||||||
|
queryFn: () => {
|
||||||
|
return fetchModerationContentList(page, size, sortBy, sortDirection, statuses, isAppeal);
|
||||||
|
},
|
||||||
|
select: (data: ContentForModeration | null) => {
|
||||||
|
if (!data) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
refetchInterval: 30000,
|
||||||
|
placeholderData: (previousData) => previousData // для оптимистичных обновлений
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { fetchTariffs } from '@/app/actions/tariffActions';
|
||||||
|
|
||||||
|
export interface Tariff {
|
||||||
|
id: number;
|
||||||
|
type: string;
|
||||||
|
name: string;
|
||||||
|
price: number;
|
||||||
|
tokens: number;
|
||||||
|
maxFilesCount: number;
|
||||||
|
diskSize: number;
|
||||||
|
maxUsers: number;
|
||||||
|
tariffTerm: string;
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TariffsData {
|
||||||
|
page: number;
|
||||||
|
page_size: number;
|
||||||
|
sort_by: string;
|
||||||
|
sort_direction: 'asc' | 'desc';
|
||||||
|
total_pages: number;
|
||||||
|
total_elements: number;
|
||||||
|
tariffs: Tariff[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useTariffsData = (page: number) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ['tariffsData', page],
|
||||||
|
queryFn: () => {
|
||||||
|
return fetchTariffs(page);
|
||||||
|
},
|
||||||
|
select: (data: TariffsData | null) => {
|
||||||
|
if (!data) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
refetchInterval: 30000,
|
||||||
|
placeholderData: (previousData) => previousData
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -51,19 +51,7 @@ export const useUsersData = (page: number, size: number, sortBy?: string, sortDi
|
|||||||
select: (data: ApiResponse): UsersDataWithPagination => {
|
select: (data: ApiResponse): UsersDataWithPagination => {
|
||||||
if (!data?.content || data.content.length === 0) {
|
if (!data?.content || data.content.length === 0) {
|
||||||
return {
|
return {
|
||||||
users: [{
|
users: [],
|
||||||
id: 1,
|
|
||||||
userName: 'userName',
|
|
||||||
userEmail: 'userEmail',
|
|
||||||
userCompany: 'userCompany',
|
|
||||||
userSubscription: Date.now(),
|
|
||||||
userRole: 'role',
|
|
||||||
userContent: 0,
|
|
||||||
tariff: 'EXPIRED',
|
|
||||||
tokens: 0,
|
|
||||||
verificationStatus: 'UNVERIFIED',
|
|
||||||
_original: {} as ApiUser
|
|
||||||
}],
|
|
||||||
pagination: {
|
pagination: {
|
||||||
totalElements: data?.totalElements || 0,
|
totalElements: data?.totalElements || 0,
|
||||||
totalPages: data?.totalPages || 0,
|
totalPages: data?.totalPages || 0,
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
export const getFileType = (fileName: string): 'image' | 'video' | 'audio' | 'document' | 'unknown' => {
|
||||||
|
const lastDotIndex = fileName.lastIndexOf('.');
|
||||||
|
|
||||||
|
if (lastDotIndex <= 0) {
|
||||||
|
return 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
|
const extension = fileName.substring(lastDotIndex + 1).toLowerCase();
|
||||||
|
|
||||||
|
const allowedExtensions = {
|
||||||
|
images: ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg', 'ico'],
|
||||||
|
videos: ['mp4', 'webm', 'ogg', 'mov', 'avi', 'mkv', 'flv', 'wmv'],
|
||||||
|
audios: ['mp3', 'wav', 'ogg', 'flac', 'aac', 'm4a', 'wma'],
|
||||||
|
documents: ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'rtf', 'csv', 'md']
|
||||||
|
};
|
||||||
|
|
||||||
|
if (allowedExtensions.images.includes(extension)) {
|
||||||
|
return 'image';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allowedExtensions.videos.includes(extension)) {
|
||||||
|
return 'video';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allowedExtensions.audios.includes(extension)) {
|
||||||
|
return 'audio';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allowedExtensions.documents.includes(extension)) {
|
||||||
|
return 'document';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'unknown';
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
@use './variable.scss' as v;
|
||||||
|
|
||||||
|
.loading-animation {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
top: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
|
||||||
|
.global-spinner {
|
||||||
|
display: block;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0 auto;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border: 4px solid #e5e7eb;
|
||||||
|
border-top: 4px solid #667eea;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.large {
|
||||||
|
width: 80px;
|
||||||
|
height: 80px;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
border: 10px solid #e5e7eb;
|
||||||
|
border-top: 10px solid #667eea;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-placeholder {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
/* min-width: 80px;
|
||||||
|
min-height: 80px; */
|
||||||
|
|
||||||
|
&.start {
|
||||||
|
justify-content: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-animation {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
position: relative;
|
||||||
|
left: auto;
|
||||||
|
top: auto;
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.global-spinner {
|
||||||
|
display: inline-block;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
@use './variable.scss' as v;
|
||||||
|
|
||||||
|
.file-moderation-modal {
|
||||||
|
padding: 1.5rem;
|
||||||
|
min-width: 400px;
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__info-section,
|
||||||
|
&__status-section,
|
||||||
|
&__status-change-section,
|
||||||
|
&__comment-section {
|
||||||
|
border-bottom: 1px solid #e5e7eb;
|
||||||
|
padding-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__label,
|
||||||
|
&__status-label,
|
||||||
|
&__status-change-label {
|
||||||
|
display: block;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__label {
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__status-label {
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__status-change-label {
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__value {
|
||||||
|
color: #111827;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__button {
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
transition: all 0.2s;
|
||||||
|
cursor: pointer;
|
||||||
|
border: none;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__button-cancel {
|
||||||
|
@extend .file-moderation-modal__button;
|
||||||
|
color: #374151;
|
||||||
|
background-color: #f3f4f6;
|
||||||
|
|
||||||
|
&:hover:not(:disabled) {
|
||||||
|
background-color: #e5e7eb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__button-save {
|
||||||
|
@extend .file-moderation-modal__button;
|
||||||
|
color: white;
|
||||||
|
background-color: #3b82f6;
|
||||||
|
|
||||||
|
&:hover:not(:disabled) {
|
||||||
|
background-color: #2563eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
background-color: #93c5fd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__comment-label {
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__comment-textarea {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-family: inherit;
|
||||||
|
color: #111827;
|
||||||
|
background-color: #ffffff;
|
||||||
|
resize: vertical;
|
||||||
|
transition: all 0.2s;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #3b82f6;
|
||||||
|
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: #9ca3af;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
background-color: #f3f4f6;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs-modal__header {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs-modal__tabs {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
border-bottom: 1px solid #e2e8f0;
|
||||||
|
padding-bottom: 0.5rem;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs-modal__tab {
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
border-radius: 0.375rem;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #64748b;
|
||||||
|
transition: all 0.2s;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs-modal__tab:hover:not(:disabled) {
|
||||||
|
color: #3b82f6;
|
||||||
|
background: #f1f5f9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs-modal__tab--active {
|
||||||
|
color: #3b82f6;
|
||||||
|
background: #eff6ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs-modal__tab--disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs-modal__tab-badge {
|
||||||
|
display: inline-block;
|
||||||
|
margin-left: 0.5rem;
|
||||||
|
padding: 0.125rem 0.375rem;
|
||||||
|
background: #e2e8f0;
|
||||||
|
border-radius: 9999px;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs-modal__content {
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-badge {
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
border-radius: 9999px;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 500;
|
||||||
|
display: inline-block;
|
||||||
|
|
||||||
|
&--blocked {
|
||||||
|
@extend .status-badge;
|
||||||
|
background-color: #fee2e2;
|
||||||
|
color: #991b1b;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--moderation {
|
||||||
|
@extend .status-badge;
|
||||||
|
background-color: #fef3c7;
|
||||||
|
color: #92400e;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--approved {
|
||||||
|
@extend .status-badge;
|
||||||
|
background-color: #dcfce7;
|
||||||
|
color: #166534;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--default {
|
||||||
|
@extend .status-badge;
|
||||||
|
background-color: #f3f4f6;
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
}
|
||||||
+240
-109
@@ -1,5 +1,9 @@
|
|||||||
@use './variable.scss' as v;
|
@use './variable.scss' as v;
|
||||||
@use './edit-permissions-modal.scss';
|
@use './edit-permissions-modal.scss';
|
||||||
|
@use './animation.scss';
|
||||||
|
@use './file-moderation-modal.scss';
|
||||||
|
@use './tariff-edit-modal.scss';
|
||||||
|
@use './tariff-remove-modal.scss';
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--primary-color: #2563eb;
|
--primary-color: #2563eb;
|
||||||
@@ -8,8 +12,8 @@
|
|||||||
--secondary-hover: #4c5869;
|
--secondary-hover: #4c5869;
|
||||||
--success-color: #10b981;
|
--success-color: #10b981;
|
||||||
--success-hover: #0d8a60;
|
--success-hover: #0d8a60;
|
||||||
--danger-color: #ef4444;
|
--danger-color: #dc2626;
|
||||||
--danger-hover: #bd3434;
|
--danger-hover: #b91c1c;
|
||||||
--warning-color: #f59e0b;
|
--warning-color: #f59e0b;
|
||||||
--warning-hover: #b3750b;
|
--warning-hover: #b3750b;
|
||||||
--info-color: #3b82f6;
|
--info-color: #3b82f6;
|
||||||
@@ -294,6 +298,11 @@
|
|||||||
&:hover {
|
&:hover {
|
||||||
background: var(--danger-hover);
|
background: var(--danger-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
@@ -354,12 +363,12 @@
|
|||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
|
|
||||||
&-actions {
|
/* &-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
|
||||||
}
|
} */
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
@@ -526,13 +535,27 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.stat-card-title {
|
.stat-card-title {
|
||||||
font-size: 13px;
|
font-size: 14px;
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
letter-spacing: 0.5px;
|
letter-spacing: 0.5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.stat-card-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tariff-term-badge {
|
||||||
|
background: #eff6ff;
|
||||||
|
padding: 2px 12px;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
.stat-card-value {
|
.stat-card-value {
|
||||||
/* width: 40px; */
|
/* width: 40px; */
|
||||||
width: auto;
|
width: auto;
|
||||||
@@ -557,6 +580,8 @@
|
|||||||
border-top: 1px solid var(--border);
|
border-top: 1px solid var(--border);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-outline {
|
.btn-outline {
|
||||||
@@ -746,127 +771,120 @@
|
|||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.table-filtres-item {
|
.table-filtres-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
width: 12.5rem;
|
width: 12.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-filtres-label {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.table-filtres-text-filter {
|
||||||
|
background-color: #fff;
|
||||||
|
border: 2px solid v.$border-color-1;
|
||||||
|
border-radius: 12px;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px 16px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
line-height: 1.25;
|
||||||
|
transition: background-color .2s ease-in-out;
|
||||||
|
display: flex;
|
||||||
|
box-shadow: 0 1px 2px #0000000d;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
outline-offset: 2px;
|
||||||
|
outline: 2px solid v.$black;
|
||||||
|
box-shadow: 0 0 0 2px #6365f187;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.table-filtres-label {
|
.status-filters {
|
||||||
font-size: 0.875rem;
|
display: flex;
|
||||||
font-weight: 500;
|
gap: 10px;
|
||||||
margin-bottom: 0.25rem;
|
align-items: center;
|
||||||
}
|
flex-wrap: wrap;
|
||||||
|
|
||||||
|
.status-btn {
|
||||||
.table-filtres-text-filter {
|
padding: 4px 12px;
|
||||||
background-color: #fff;
|
border-radius: 16px;
|
||||||
border: 2px solid v.$border-color-1;
|
border: 1px solid;
|
||||||
border-radius: 12px;
|
transition: all 0.2s ease;
|
||||||
justify-content: space-between;
|
cursor: pointer;
|
||||||
align-items: center;
|
|
||||||
width: 100%;
|
|
||||||
padding: 8px 16px;
|
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
line-height: 1.25;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
display: flex;
|
|
||||||
box-shadow: 0 1px 2px #0000000d;
|
|
||||||
|
|
||||||
&:focus {
|
|
||||||
outline-offset: 2px;
|
|
||||||
outline: 2px solid v.$black;
|
|
||||||
box-shadow: 0 0 0 2px #6365f187;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.tanstak-table-pagination {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: flex-end;
|
|
||||||
justify-content: space-between;
|
|
||||||
margin-top: 1.5rem;
|
|
||||||
gap: 1rem;
|
|
||||||
|
|
||||||
@media (min-width: 768px) {
|
|
||||||
flex-direction: row;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pagination-info {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5rem;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
|
|
||||||
&-pages {
|
|
||||||
color: v.$text-p;
|
|
||||||
}
|
|
||||||
|
|
||||||
&-files {
|
|
||||||
color: v.$text-s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.pagination-controls {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5rem;
|
|
||||||
|
|
||||||
.arrow {
|
|
||||||
padding-left: 0.5rem;
|
|
||||||
padding-right: 0.5rem;
|
|
||||||
padding-top: 0.25rem;
|
|
||||||
padding-bottom: 0.25rem;
|
|
||||||
border: 2px solid v.$border-color-1;
|
|
||||||
border-radius: 10px;
|
|
||||||
box-shadow: 0 1px 2px #0000000d;
|
|
||||||
color: var(--primary-color);
|
|
||||||
|
|
||||||
.icon {
|
|
||||||
width: 18px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* */
|
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: v.$bg-light;
|
transform: translateY(-1px);
|
||||||
}
|
}
|
||||||
|
|
||||||
&:disabled {
|
&:active {
|
||||||
opacity: 0.5;
|
transform: translateY(0);
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
&-pages {
|
// BLOCK статус
|
||||||
display: flex;
|
&--block {
|
||||||
align-items: center;
|
background-color: white;
|
||||||
gap: 0.25rem;
|
color: #dc2626;
|
||||||
|
border-color: #fca5a5;
|
||||||
|
|
||||||
button {
|
&:hover {
|
||||||
border: 2px solid v.$border-color-1;
|
background-color: #fef2f2;
|
||||||
padding: 0.25rem 0.75rem;
|
border-color: #f87171;
|
||||||
border-radius: 10px;
|
|
||||||
color: var(--primary-color);
|
|
||||||
|
|
||||||
&:disabled {
|
|
||||||
opacity: 0.5;
|
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.current {
|
&.active {
|
||||||
background-color: var(--primary-color);
|
background-color: #dc2626;
|
||||||
color: v.$white;
|
color: white;
|
||||||
|
border-color: #b91c1c;
|
||||||
|
box-shadow: 0 2px 4px rgba(220, 38, 38, 0.2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ACTIVE статус
|
||||||
|
&--active {
|
||||||
|
background-color: white;
|
||||||
|
color: #16a34a;
|
||||||
|
border-color: #86efac;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #f0fdf4;
|
||||||
|
border-color: #4ade80;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.other {
|
&.active {
|
||||||
&:hover {
|
background-color: #16a34a;
|
||||||
background-color: v.$bg-light;
|
color: white;
|
||||||
}
|
border-color: #15803d;
|
||||||
|
box-shadow: 0 2px 4px rgba(22, 163, 74, 0.2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MODERATION статус
|
||||||
|
&--moderation {
|
||||||
|
background-color: white;
|
||||||
|
color: #ca8a04;
|
||||||
|
border-color: #fde047;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #fefce8;
|
||||||
|
border-color: #facc15;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background-color: #ca8a04;
|
||||||
|
color: white;
|
||||||
|
border-color: #a16207;
|
||||||
|
box-shadow: 0 2px 4px rgba(202, 138, 4, 0.2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1017,6 +1035,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.table-status {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
.table-item-protected {
|
.table-item-protected {
|
||||||
color: #10b981;
|
color: #10b981;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
@@ -1197,6 +1223,111 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.color-image {
|
||||||
|
color: v.$color-image;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-video {
|
||||||
|
color: v.$color-video;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-audio {
|
||||||
|
color: v.$color-audio;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-document {
|
||||||
|
color: v.$color-document;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tanstak-table-pagination {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-end;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
gap: 1rem;
|
||||||
|
|
||||||
|
@media (min-width: 768px) {
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination-info {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
|
||||||
|
&-pages {
|
||||||
|
color: v.$text-p;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-files {
|
||||||
|
color: v.$text-s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination-controls {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
|
||||||
|
.arrow {
|
||||||
|
padding-left: 0.5rem;
|
||||||
|
padding-right: 0.5rem;
|
||||||
|
padding-top: 0.25rem;
|
||||||
|
padding-bottom: 0.25rem;
|
||||||
|
border: 2px solid v.$border-color-1;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 1px 2px #0000000d;
|
||||||
|
color: var(--primary-color);
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
width: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: v.$bg-light;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-pages {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.25rem;
|
||||||
|
|
||||||
|
button {
|
||||||
|
border: 2px solid v.$border-color-1;
|
||||||
|
padding: 0.25rem 0.75rem;
|
||||||
|
border-radius: 10px;
|
||||||
|
color: var(--primary-color);
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.current {
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
color: v.$white;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.other {
|
||||||
|
&:hover {
|
||||||
|
background-color: v.$bg-light;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.empty-state {
|
.empty-state {
|
||||||
|
|||||||
@@ -187,6 +187,14 @@
|
|||||||
margin-bottom: 18px;
|
margin-bottom: 18px;
|
||||||
margin: 20px 0 0 0;
|
margin: 20px 0 0 0;
|
||||||
|
|
||||||
|
/* &.save {
|
||||||
|
background: #0d50e0;
|
||||||
|
|
||||||
|
&:hover:not(:disabled) {
|
||||||
|
background: #355fd3;
|
||||||
|
}
|
||||||
|
} */
|
||||||
|
|
||||||
&:hover:not(:disabled) {
|
&:hover:not(:disabled) {
|
||||||
background: #1d4ed8;
|
background: #1d4ed8;
|
||||||
}
|
}
|
||||||
@@ -294,4 +302,45 @@
|
|||||||
.checkbox-label {
|
.checkbox-label {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.change-password-modal {
|
||||||
|
padding: 24px;
|
||||||
|
min-width: 400px;
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
justify-content: flex-end;
|
||||||
|
margin-top: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
padding: 8px 16px;
|
||||||
|
background: #6c757d;
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
margin: 20 0 0;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: #5a6268;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.change-password-btn {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: #007bff;
|
||||||
|
text-decoration: underline;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-left: 8px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: #0056b3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
@use './variable.scss' as v;
|
||||||
|
|
||||||
|
.tariff-edit-modal {
|
||||||
|
padding: 1.5rem;
|
||||||
|
min-width: 500px;
|
||||||
|
max-width: 600px;
|
||||||
|
max-height: 80vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
color: #111827;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__info-section {
|
||||||
|
border-bottom: 1px solid #e5e7eb;
|
||||||
|
padding-bottom: 0.75rem;
|
||||||
|
|
||||||
|
&:last-of-type {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__label {
|
||||||
|
display: block;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #374151;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__value {
|
||||||
|
color: #111827;
|
||||||
|
word-break: break-word;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-family: inherit;
|
||||||
|
color: #111827;
|
||||||
|
background-color: #ffffff;
|
||||||
|
transition: all 0.2s;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #3b82f6;
|
||||||
|
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: #9ca3af;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
background-color: #f3f4f6;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
&[type="number"] {
|
||||||
|
-moz-appearance: textfield;
|
||||||
|
|
||||||
|
&::-webkit-inner-spin-button,
|
||||||
|
&::-webkit-outer-spin-button {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__textarea {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-family: inherit;
|
||||||
|
color: #111827;
|
||||||
|
background-color: #ffffff;
|
||||||
|
resize: vertical;
|
||||||
|
transition: all 0.2s;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #3b82f6;
|
||||||
|
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: #9ca3af;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
background-color: #f3f4f6;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Стили для DropDownList внутри модального окна
|
||||||
|
.dropdown {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Адаптация для мобильных устройств
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.tariff-edit-modal {
|
||||||
|
min-width: 90vw;
|
||||||
|
padding: 1rem;
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__info-section {
|
||||||
|
padding-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__actions {
|
||||||
|
flex-direction: column-reverse;
|
||||||
|
|
||||||
|
button {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Стили для скроллбара (опционально)
|
||||||
|
.tariff-edit-modal {
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: #cbd5e1 #f1f5f9;
|
||||||
|
|
||||||
|
&::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::-webkit-scrollbar-track {
|
||||||
|
background: #f1f5f9;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::-webkit-scrollbar-thumb {
|
||||||
|
background: #cbd5e1;
|
||||||
|
border-radius: 3px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: #94a3b8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tariff-edit-modal__row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 1rem;
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tariff-edit-modal__info-section--half {
|
||||||
|
@extend .tariff-edit-modal__info-section;
|
||||||
|
|
||||||
|
@media (min-width: 769px) {
|
||||||
|
&:first-child {
|
||||||
|
padding-right: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
padding-left: 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
.tariff-delete-modal {
|
||||||
|
min-width: 400px;
|
||||||
|
max-width: 500px;
|
||||||
|
|
||||||
|
.tariff-delete-modal__title {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
color: #dc2626;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tariff-delete-modal__warning {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 16px;
|
||||||
|
background: #fef2f2;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning-icon {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning-text {
|
||||||
|
margin: 0;
|
||||||
|
color: #991b1b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tariff-delete-modal__info {
|
||||||
|
padding: 12px;
|
||||||
|
background: #f3f4f6;
|
||||||
|
border-radius: 6px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #4b5563;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tariff-delete-modal__confirm {
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px solid #d1d5db;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #dc2626;
|
||||||
|
ring: 2px solid #dc2626;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tariff-delete-modal__actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import DropDownList from '@/app/components/dropDownList';
|
||||||
|
import { AppealsFile } from '@/app/hooks/react-query/useContentForAppeals';
|
||||||
|
import { changeAppealContentStatus } from '@/app/actions/contentActions';
|
||||||
|
import { formatDate, formatDateTime } from '@/app/lib/formatDate';
|
||||||
|
import { AppealInfo } from '@/app/hooks/react-query/useContentForModeration';
|
||||||
|
|
||||||
|
interface AppealModerationModalProps {
|
||||||
|
file: AppealInfo | AppealsFile | null;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLabel = (status: string) => {
|
||||||
|
switch (status) {
|
||||||
|
case 'REJECTED':
|
||||||
|
return 'Заблокировано';
|
||||||
|
case 'MODERATION':
|
||||||
|
return 'На модерации';
|
||||||
|
case 'APPROVED':
|
||||||
|
return 'Одобрено';
|
||||||
|
default:
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStatusValue = (label: string) => {
|
||||||
|
switch (label) {
|
||||||
|
case 'REJECTED':
|
||||||
|
return 'REJECTED';
|
||||||
|
case 'MODERATION':
|
||||||
|
return 'MODERATION';
|
||||||
|
case 'APPROVED':
|
||||||
|
return 'APPROVED';
|
||||||
|
default:
|
||||||
|
return 'MODERATION';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const StatusBadge = ({ status }: { status: string }) => {
|
||||||
|
const getBadgeClass = () => {
|
||||||
|
switch (status) {
|
||||||
|
case 'REJECTED':
|
||||||
|
return 'status-badge--blocked';
|
||||||
|
case 'MODERATION':
|
||||||
|
return 'status-badge--moderation';
|
||||||
|
case 'APPROVED':
|
||||||
|
return 'status-badge--approved';
|
||||||
|
default:
|
||||||
|
return 'status-badge--default';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<span className={getBadgeClass()}>
|
||||||
|
{getLabel(status)}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function AppealModerationModal({ file, onClose }: AppealModerationModalProps) {
|
||||||
|
const [selectedStatus, setSelectedStatus] = useState<string>(getLabel(file?.status || 'MODERATION'));
|
||||||
|
const [adminComment, setAdminComment] = useState<string>(file?.adminComment || '');
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const changeStatusMutation = useMutation({
|
||||||
|
mutationFn: async ({ appealId, approve, comment }: { appealId: string; approve: boolean; comment: string }) => {
|
||||||
|
return await changeAppealContentStatus(appealId, approve, comment);
|
||||||
|
},
|
||||||
|
onSuccess: (data) => {
|
||||||
|
if (data !== null && data !== undefined) {
|
||||||
|
toast.success('Статус апелляции успешно изменен');
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['contentForAppeals'] });
|
||||||
|
onClose();
|
||||||
|
} else {
|
||||||
|
toast.error('Не удалось изменить статус апелляции');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error('Произошла ошибка при изменении статуса');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleStatusChange = () => {
|
||||||
|
if (!file?.appealId) {
|
||||||
|
toast.error('ID апелляции не найден');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const statusValue = getStatusValue(selectedStatus);
|
||||||
|
const approve = statusValue === 'APPROVED';
|
||||||
|
|
||||||
|
changeStatusMutation.mutate({
|
||||||
|
appealId: file.appealId,
|
||||||
|
approve: approve,
|
||||||
|
comment: adminComment,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!file) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{/* Информация о файле */}
|
||||||
|
<div className="file-moderation-modal__info-section">
|
||||||
|
<label className="file-moderation-modal__label">Название файла</label>
|
||||||
|
<p className="file-moderation-modal__value">{file?.fileName ? file?.fileName : '---'}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="file-moderation-modal__info-section">
|
||||||
|
<label className="file-moderation-modal__label">User ID</label>
|
||||||
|
{/* @ts-ignore сейчас нету айди юзера возможно нужно будет удалить или добавить*/}
|
||||||
|
<p className="file-moderation-modal__value">{file?.userId ? file?.userId : '---'}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="file-moderation-modal__info-section">
|
||||||
|
<label className="file-moderation-modal__label">Причина апелляции</label>
|
||||||
|
<p className="file-moderation-modal__value">{file.appealReason}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="file-moderation-modal__info-section">
|
||||||
|
<label className="file-moderation-modal__label">Дополнительная информация</label>
|
||||||
|
<p className="file-moderation-modal__value">{file.additionalInfo || '—'}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="file-moderation-modal__info-section">
|
||||||
|
<label className="file-moderation-modal__label">Дата создания</label>
|
||||||
|
<p className="file-moderation-modal__value">
|
||||||
|
{file.createdAt && (
|
||||||
|
`${formatDate(file.createdAt)}, ${formatDateTime(file.createdAt)}`
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{file.resolvedAt && (
|
||||||
|
<div className="file-moderation-modal__info-section">
|
||||||
|
<label className="file-moderation-modal__label">Дата решения</label>
|
||||||
|
<p className="file-moderation-modal__value">
|
||||||
|
{formatDate(file.resolvedAt)}, {formatDateTime(file.resolvedAt)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="file-moderation-modal__status-section">
|
||||||
|
<label className="file-moderation-modal__status-label">Текущий статус</label>
|
||||||
|
<StatusBadge status={file.status} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Комментарий администратора */}
|
||||||
|
<div className="file-moderation-modal__comment-section">
|
||||||
|
<label className="file-moderation-modal__comment-label">Комментарий администратора</label>
|
||||||
|
<textarea
|
||||||
|
className="file-moderation-modal__comment-textarea"
|
||||||
|
value={adminComment}
|
||||||
|
onChange={(e) => setAdminComment(e.target.value)}
|
||||||
|
placeholder="Введите комментарий..."
|
||||||
|
rows={4}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Смена статуса */}
|
||||||
|
<div className="file-moderation-modal__status-change-section">
|
||||||
|
<label className="file-moderation-modal__status-change-label">Изменить статус</label>
|
||||||
|
<DropDownList
|
||||||
|
value={getLabel(selectedStatus)}
|
||||||
|
callBack={(value: string) => setSelectedStatus(value)}
|
||||||
|
>
|
||||||
|
<li value="REJECTED">Заблокировано</li>
|
||||||
|
<li value="APPROVED">Одобрено</li>
|
||||||
|
</DropDownList>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Кнопки действий */}
|
||||||
|
<div className="file-moderation-modal__actions">
|
||||||
|
<button
|
||||||
|
onClick={onClose}
|
||||||
|
className="btn btn-secondary"
|
||||||
|
disabled={changeStatusMutation.isPending}
|
||||||
|
>
|
||||||
|
Отмена
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleStatusChange}
|
||||||
|
className="btn btn-primary"
|
||||||
|
disabled={changeStatusMutation.isPending || selectedStatus === getLabel(file.status)}
|
||||||
|
>
|
||||||
|
{changeStatusMutation.isPending ? 'Сохранение...' : 'Сохранить'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import DropDownList from '@/app/components/dropDownList';
|
||||||
|
import { changeModerationContentStatus } from '@/app/actions/contentActions';
|
||||||
|
import { ModerationFile } from '@/app/hooks/react-query/useContentForModeration';
|
||||||
|
|
||||||
|
interface FileModerationModalProps {
|
||||||
|
file: ModerationFile | null;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLabel = (status: string) => {
|
||||||
|
switch (status) {
|
||||||
|
case 'BLOCKED':
|
||||||
|
return 'Заблокировано';
|
||||||
|
case 'MODERATION':
|
||||||
|
return 'На модерации';
|
||||||
|
case 'ACTIVE':
|
||||||
|
return 'Одобрено';
|
||||||
|
default:
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const StatusBadge = ({ status }: { status: string }) => {
|
||||||
|
const getBadgeClass = () => {
|
||||||
|
switch (status) {
|
||||||
|
case 'BLOCKED':
|
||||||
|
return 'status-badge--blocked';
|
||||||
|
case 'MODERATION':
|
||||||
|
return 'status-badge--moderation';
|
||||||
|
case 'ACTIVE':
|
||||||
|
return 'status-badge--approved';
|
||||||
|
default:
|
||||||
|
return 'status-badge--default';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<span className={getBadgeClass()}>
|
||||||
|
{getLabel(status)}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function FileModerationModal({ file, onClose }: FileModerationModalProps) {
|
||||||
|
const [selectedStatus, setSelectedStatus] = useState<string>(file?.status || 'MODERATION');
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const changeStatusMutation = useMutation({
|
||||||
|
mutationFn: async ({ fileId, fileStatus }: { fileId: string; fileStatus: string }) => {
|
||||||
|
return await changeModerationContentStatus(fileId, fileStatus);
|
||||||
|
},
|
||||||
|
onSuccess: (data) => {
|
||||||
|
if (data) {
|
||||||
|
toast.success('Статус файла успешно изменен');
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['contentForModeration'] });
|
||||||
|
onClose();
|
||||||
|
} else {
|
||||||
|
toast.error('Не удалось изменить статус файла');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error('Произошла ошибка при изменении статуса');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleStatusChange = () => {
|
||||||
|
if (!file?.fileId) {
|
||||||
|
toast.error('ID файла не найден');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
changeStatusMutation.mutate({
|
||||||
|
fileId: file.fileId,
|
||||||
|
fileStatus: selectedStatus,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!file) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="file-moderation-modal__content">
|
||||||
|
{/* Информация о файле */}
|
||||||
|
<div className="file-moderation-modal__info-section">
|
||||||
|
<label className="file-moderation-modal__label">Название файла</label>
|
||||||
|
<p className="file-moderation-modal__value">{file.fileName}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="file-moderation-modal__info-section">
|
||||||
|
<label className="file-moderation-modal__label">User ID</label>
|
||||||
|
<p className="file-moderation-modal__value">{file.userId}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="file-moderation-modal__status-section">
|
||||||
|
<label className="file-moderation-modal__status-label">Текущий статус</label>
|
||||||
|
<StatusBadge status={file.status} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Смена статуса */}
|
||||||
|
<div className="file-moderation-modal__status-change-section">
|
||||||
|
<label className="file-moderation-modal__status-change-label">Изменить статус</label>
|
||||||
|
<DropDownList
|
||||||
|
value={getLabel(selectedStatus)}
|
||||||
|
callBack={(value: string) => setSelectedStatus(value)}
|
||||||
|
>
|
||||||
|
<li value="MODERATION">На модерации</li>
|
||||||
|
<li value="BLOCKED">Заблокировано</li>
|
||||||
|
<li value="ACTIVE">Одобрено</li>
|
||||||
|
</DropDownList>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Кнопки действий */}
|
||||||
|
<div className="file-moderation-modal__actions">
|
||||||
|
<button
|
||||||
|
onClick={onClose}
|
||||||
|
className="btn btn-secondary"
|
||||||
|
disabled={changeStatusMutation.isPending}
|
||||||
|
>
|
||||||
|
Отмена
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleStatusChange}
|
||||||
|
className="btn btn-primary"
|
||||||
|
disabled={changeStatusMutation.isPending || selectedStatus === file.status}
|
||||||
|
>
|
||||||
|
{changeStatusMutation.isPending ? 'Сохранение...' : 'Сохранить'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { ModerationFile } from '@/app/hooks/react-query/useContentForModeration';
|
||||||
|
import FileModerationModal from './FileModerationModal';
|
||||||
|
import AppealModerationModal from './AppealModerationModal';
|
||||||
|
|
||||||
|
interface FileWithAppealModerationModalProps {
|
||||||
|
file: ModerationFile | null;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
type TabType = 'file' | 'appeal';
|
||||||
|
|
||||||
|
export default function FileWithAppealModerationModal({ file, onClose }: FileWithAppealModerationModalProps) {
|
||||||
|
const [activeTab, setActiveTab] = useState<TabType>('file');
|
||||||
|
|
||||||
|
if (!file) return null;
|
||||||
|
|
||||||
|
const hasAppeal = !!file.moderationInfo?.appealInfo;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="file-moderation-modal tabs-modal">
|
||||||
|
<div className="tabs-modal__header">
|
||||||
|
<h2 className="file-moderation-modal__title">
|
||||||
|
Модерация контента
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div className="tabs-modal__tabs">
|
||||||
|
<button
|
||||||
|
className={`tabs-modal__tab ${activeTab === 'file' ? 'tabs-modal__tab--active' : ''}`}
|
||||||
|
onClick={() => setActiveTab('file')}
|
||||||
|
>
|
||||||
|
Модерация файла
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className={`tabs-modal__tab ${activeTab === 'appeal' ? 'tabs-modal__tab--active' : ''} ${!hasAppeal ? 'tabs-modal__tab--disabled' : ''}`}
|
||||||
|
onClick={() => hasAppeal && setActiveTab('appeal')}
|
||||||
|
disabled={!hasAppeal}
|
||||||
|
title={!hasAppeal ? 'Апелляция отсутствует' : ''}
|
||||||
|
>
|
||||||
|
Модерация апелляции
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tabs-modal__content">
|
||||||
|
{activeTab === 'file' && (
|
||||||
|
<FileModerationModal file={file} onClose={onClose} />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === 'appeal' && hasAppeal && (
|
||||||
|
<AppealModerationModal
|
||||||
|
file={file.moderationInfo.appealInfo}
|
||||||
|
onClose={onClose}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,520 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState, useMemo, useEffect, ReactNode, useCallback } from 'react';
|
||||||
|
import {
|
||||||
|
useReactTable,
|
||||||
|
getCoreRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
getPaginationRowModel,
|
||||||
|
getFilteredRowModel,
|
||||||
|
ColumnDef,
|
||||||
|
SortingState,
|
||||||
|
ColumnFiltersState,
|
||||||
|
} from '@tanstack/react-table';
|
||||||
|
import { IconEye, IconDoubleArrowRight, IconArrowRight, IconDoubleArrowLeft, IconArrowLeft, IconArrowUp, IconArrowDown, IconFilter, IconFileDownload } from '@/app/ui/icons/icons';
|
||||||
|
import { useTranslations } from 'next-intl';
|
||||||
|
import DropDownList from '@/app/components/dropDownList';
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import ModalWindow from '@/app/components/modalWindow';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { FileTypeIcon } from '@/app/components/FileTypeIcon';
|
||||||
|
import { downloadFile } from '@/app/actions/contentActions';
|
||||||
|
import { useContentForAppeals, AppealsFile } from '@/app/hooks/react-query/useContentForAppeals';
|
||||||
|
import AppealModerationModal from '@/app/ui/content/AppealModerationModal';
|
||||||
|
import { formatDate, formatDateTime } from '@/app/lib/formatDate';
|
||||||
|
import {AppealInfo} from '@/app/hooks/react-query/useContentForModeration';
|
||||||
|
|
||||||
|
const cutFileExtension = (fileName: string) => {
|
||||||
|
const lastDotIndex = fileName.lastIndexOf('.');
|
||||||
|
const extension = fileName.substring(lastDotIndex + 1);
|
||||||
|
return extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cutFileName = (fileName: string) => {
|
||||||
|
const MAX_FILE_NAME_LENGTH = 30;
|
||||||
|
const lastDotIndex = fileName.lastIndexOf('.');
|
||||||
|
|
||||||
|
if (lastDotIndex <= 0) {
|
||||||
|
return fileName.length > MAX_FILE_NAME_LENGTH ? fileName.substring(0, MAX_FILE_NAME_LENGTH - 3) + '...' : fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nameWithoutExtension = fileName.substring(0, lastDotIndex);
|
||||||
|
const extension = fileName.substring(lastDotIndex);
|
||||||
|
|
||||||
|
if (fileName.length <= MAX_FILE_NAME_LENGTH) {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxNameLength = MAX_FILE_NAME_LENGTH - extension.length - 3;
|
||||||
|
|
||||||
|
if (maxNameLength <= 0) {
|
||||||
|
return '...' + extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nameWithoutExtension.substring(0, maxNameLength) + '...' + extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StatusBadge = ({ status }: { status: string }) => {
|
||||||
|
const statusConfig: Record<string, { className: string; label: string }> = {
|
||||||
|
'REJECTED': { className: 'bg-red-100 text-red-800', label: 'Заблокировано' },
|
||||||
|
'MODERATION': { className: 'bg-yellow-100 text-yellow-800', label: 'На модерации' },
|
||||||
|
'APPROVED': { className: 'bg-green-100 text-green-800', label: 'Одобрено' },
|
||||||
|
'PENDING': { className: 'bg-gray-100 text-gray-800', label: 'На рассмотрении' }
|
||||||
|
};
|
||||||
|
|
||||||
|
const config = statusConfig[status] || { className: 'bg-gray-100 text-gray-800', label: status };
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className={`px-2 py-1 rounded-full text-xs font-medium ${config.className}`}>
|
||||||
|
{config.label}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function ContentAppealsTable({ permission }: { permission: number }) {
|
||||||
|
// Состояния
|
||||||
|
const [sorting, setSorting] = useState<SortingState>([]);
|
||||||
|
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
||||||
|
const [pagination, setPagination] = useState({
|
||||||
|
pageIndex: 0,
|
||||||
|
pageSize: 10,
|
||||||
|
});
|
||||||
|
const [openWindow, setOpenWindow] = useState<boolean>(false);
|
||||||
|
const [selectedFile, setSelectedFile] = useState<AppealsFile | AppealInfo | null>(null);
|
||||||
|
const [isFileLoading, setIsFileLoading] = useState(false);
|
||||||
|
|
||||||
|
const t = useTranslations("Global");
|
||||||
|
|
||||||
|
const getSortParams = useMemo(() => {
|
||||||
|
if (sorting.length === 0) {
|
||||||
|
return { sortBy: '', sortDirection: undefined };
|
||||||
|
}
|
||||||
|
|
||||||
|
const sort = sorting[0];
|
||||||
|
const sortByMap: Record<string, string> = {
|
||||||
|
'fileName': 'fileName',
|
||||||
|
'appealId': 'appealId',
|
||||||
|
'status': 'status',
|
||||||
|
'createdAt': 'createdAt',
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
sortBy: sortByMap[sort.id] || sort.id,
|
||||||
|
sortDirection: sort.desc ? 'desc' : 'asc'
|
||||||
|
};
|
||||||
|
}, [sorting]);
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: appealsData,
|
||||||
|
isLoading,
|
||||||
|
isError,
|
||||||
|
isFetching,
|
||||||
|
error
|
||||||
|
} = useContentForAppeals(
|
||||||
|
pagination.pageIndex,
|
||||||
|
pagination.pageSize,
|
||||||
|
getSortParams.sortBy,
|
||||||
|
getSortParams.sortDirection
|
||||||
|
);
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const handleViewFile = useCallback((file: AppealsFile) => {
|
||||||
|
console.log('View file:', file);
|
||||||
|
setSelectedFile(file);
|
||||||
|
setOpenWindow(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleCloseModal = useCallback(() => {
|
||||||
|
setOpenWindow(false);
|
||||||
|
setSelectedFile(null);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleDownload = async (file: AppealsFile) => {
|
||||||
|
setIsFileLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await downloadFile(
|
||||||
|
file.fileId,
|
||||||
|
`file-${file.fileId}`
|
||||||
|
);
|
||||||
|
|
||||||
|
const byteCharacters = atob(result.data);
|
||||||
|
const byteNumbers = new Array(byteCharacters.length);
|
||||||
|
for (let i = 0; i < byteCharacters.length; i++) {
|
||||||
|
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
const byteArray = new Uint8Array(byteNumbers);
|
||||||
|
const blob = new Blob([byteArray], { type: result.contentType });
|
||||||
|
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = result.fileName;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
document.body.removeChild(a);
|
||||||
|
toast.success(`${t('file-is-downloading')}`);
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(t('failed-to-download-file'));
|
||||||
|
} finally {
|
||||||
|
setIsFileLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns = useMemo<ColumnDef<AppealsFile>[]>(() => {
|
||||||
|
const allColumns: ColumnDef<AppealsFile>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: 'fileName',
|
||||||
|
header: ({ column }) => (
|
||||||
|
<div className="column start">
|
||||||
|
<span>
|
||||||
|
fileName
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
|
className="sort-button hidden"
|
||||||
|
>
|
||||||
|
{column.getIsSorted() === 'asc' ?
|
||||||
|
<span><IconArrowUp /></span>
|
||||||
|
: column.getIsSorted() === 'desc' ?
|
||||||
|
<span><IconArrowDown /></span>
|
||||||
|
: <span><IconFilter /></span>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center space-x-2 table-item table-item-file-name">
|
||||||
|
<FileTypeIcon type={row.original.fileName} />
|
||||||
|
<div>
|
||||||
|
<div className="font-medium w-full truncate" title={row.original.fileName}>
|
||||||
|
<span className="font-semibold">
|
||||||
|
{/* {cutFileName(row.original.fileName)} */}
|
||||||
|
{row.original.fileName}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
enableColumnFilter: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'appealId',
|
||||||
|
header: ({ column }) => (
|
||||||
|
<div className="column">
|
||||||
|
<span>
|
||||||
|
Appeal ID
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
|
className="sort-button hidden"
|
||||||
|
>
|
||||||
|
{column.getIsSorted() === 'asc' ?
|
||||||
|
<span><IconArrowUp /></span>
|
||||||
|
: column.getIsSorted() === 'desc' ?
|
||||||
|
<span><IconArrowDown /></span>
|
||||||
|
: <span><IconFilter /></span>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="text-center">
|
||||||
|
{row.original.appealId}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'status',
|
||||||
|
header: ({ column }) => (
|
||||||
|
<div className="column">
|
||||||
|
<span>
|
||||||
|
Статус
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
|
className="sort-button"
|
||||||
|
>
|
||||||
|
{column.getIsSorted() === 'asc' ?
|
||||||
|
<span><IconArrowUp /></span>
|
||||||
|
: column.getIsSorted() === 'desc' ?
|
||||||
|
<span><IconArrowDown /></span>
|
||||||
|
: <span><IconFilter /></span>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="text-center">
|
||||||
|
<StatusBadge status={row.original.status} />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'createdAt',
|
||||||
|
header: ({ column }) => (
|
||||||
|
<div className="column">
|
||||||
|
<span>
|
||||||
|
createdAt
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
|
className="sort-button"
|
||||||
|
>
|
||||||
|
{column.getIsSorted() === 'asc' ?
|
||||||
|
<span><IconArrowUp /></span>
|
||||||
|
: column.getIsSorted() === 'desc' ?
|
||||||
|
<span><IconArrowDown /></span>
|
||||||
|
: <span><IconFilter /></span>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="text-center">
|
||||||
|
{row.original.createdAt ? formatDate(row.original.createdAt) : '---'}
|
||||||
|
<br />
|
||||||
|
{row.original.createdAt ? formatDateTime(row.original.createdAt) : '---'}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
if (permission === 3) {
|
||||||
|
allColumns.push({
|
||||||
|
id: 'actions',
|
||||||
|
header: () => <div className="column">{t('actions')}</div>,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="actions">
|
||||||
|
<div className="actions-group">
|
||||||
|
<button
|
||||||
|
onClick={() => handleViewFile(row.original)}
|
||||||
|
className="bg-blue-500 hover:bg-blue-600 text-white p-2 rounded"
|
||||||
|
title="Просмотреть файл"
|
||||||
|
>
|
||||||
|
<IconEye />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() => handleDownload(row.original)}
|
||||||
|
disabled={isFileLoading}
|
||||||
|
className="table-action-download"
|
||||||
|
title={t('download')}
|
||||||
|
>
|
||||||
|
<IconFileDownload />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
enableSorting: false,
|
||||||
|
enableColumnFilter: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return allColumns;
|
||||||
|
}, [permission, handleViewFile, handleDownload, isFileLoading, t]);
|
||||||
|
|
||||||
|
// Данные для таблицы
|
||||||
|
const tableData = useMemo(() => {
|
||||||
|
if (!appealsData?.appeals) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return appealsData.appeals;
|
||||||
|
}, [appealsData]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const currentPageRows = table.getRowModel().rows;
|
||||||
|
const pageCount = table.getPageCount();
|
||||||
|
|
||||||
|
if (currentPageRows.length === 0 && pagination.pageIndex > 0 && pageCount > 0) {
|
||||||
|
table.setPageIndex(pagination.pageIndex - 1);
|
||||||
|
}
|
||||||
|
}, [tableData, pagination.pageIndex]);
|
||||||
|
|
||||||
|
// Создание таблицы
|
||||||
|
const table = useReactTable({
|
||||||
|
data: tableData,
|
||||||
|
columns,
|
||||||
|
state: {
|
||||||
|
sorting,
|
||||||
|
columnFilters,
|
||||||
|
pagination
|
||||||
|
},
|
||||||
|
manualPagination: true,
|
||||||
|
manualSorting: true,
|
||||||
|
manualFiltering: true,
|
||||||
|
pageCount: appealsData?.totalPages || 0,
|
||||||
|
onPaginationChange: setPagination,
|
||||||
|
onSortingChange: (updater) => {
|
||||||
|
const newSorting = typeof updater === 'function' ? updater(sorting) : updater;
|
||||||
|
setSorting(newSorting);
|
||||||
|
setPagination(prev => ({ ...prev, pageIndex: 0 }));
|
||||||
|
},
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
getPaginationRowModel: getPaginationRowModel()
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isError) {
|
||||||
|
return (
|
||||||
|
<div className="text-center text-red-600 p-4">
|
||||||
|
Ошибка загрузки данных: {error?.message || 'Неизвестная ошибка'}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="tanstak-table-wrapper">
|
||||||
|
<ModalWindow state={openWindow} callBack={handleCloseModal}>
|
||||||
|
<AppealModerationModal file={selectedFile} onClose={handleCloseModal} />
|
||||||
|
</ModalWindow>
|
||||||
|
|
||||||
|
{/* Фильтры */}
|
||||||
|
<div className="tanstak-table-filtres">
|
||||||
|
<h3>
|
||||||
|
Таблица апелляций
|
||||||
|
</h3>
|
||||||
|
<div className="table-filtres-item">
|
||||||
|
<div className="table-filtres-label">{t('items-per-page')}:</div>
|
||||||
|
<DropDownList
|
||||||
|
value={table.getState().pagination.pageSize}
|
||||||
|
//@ts-ignore
|
||||||
|
callBack={table.setPageSize}
|
||||||
|
>
|
||||||
|
{[5, 10, 20, 50, 100].map(pageSize => (
|
||||||
|
<li key={pageSize} value={pageSize}>
|
||||||
|
{t('show')} {pageSize}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</DropDownList>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Таблица */}
|
||||||
|
<div className="tanstak-table-block">
|
||||||
|
<table className="tanstak-table">
|
||||||
|
<thead className="tanstak-table-head">
|
||||||
|
{table.getHeaderGroups().map(headerGroup => (
|
||||||
|
<tr key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map(header => (
|
||||||
|
<th key={header.id}>
|
||||||
|
{header.isPlaceholder
|
||||||
|
? null
|
||||||
|
: typeof header.column.columnDef.header === 'function'
|
||||||
|
? header.column.columnDef.header(header.getContext())
|
||||||
|
: header.column.columnDef.header as string}
|
||||||
|
</th>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</thead>
|
||||||
|
<tbody className={`tanstak-table-body ${isFetching ? 'loading' : ''}`}>
|
||||||
|
{isLoading ? (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={columns.length} className="text-center py-8">
|
||||||
|
Загрузка...
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : table.getRowModel().rows.length > 0 ? (
|
||||||
|
table.getRowModel().rows.map(row => (
|
||||||
|
<tr key={row.original.appealId}>
|
||||||
|
{row.getVisibleCells().map(cell => (
|
||||||
|
<td key={cell.id}>
|
||||||
|
{typeof cell.column.columnDef.cell === 'function'
|
||||||
|
? cell.column.columnDef.cell(cell.getContext())
|
||||||
|
: cell.getValue() as string}
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={columns.length} className="text-center py-8">
|
||||||
|
{t('no-data-for-selected-filters')}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Пагинация */}
|
||||||
|
<div className="tanstak-table-pagination">
|
||||||
|
<div className="pagination-info">
|
||||||
|
<span className="pagination-info-pages">
|
||||||
|
{t('page')}{' '}
|
||||||
|
<strong>
|
||||||
|
{(appealsData?.currentPage ?? 0) + 1} {t('out-of')} {appealsData?.totalPages ?? 1}
|
||||||
|
</strong>
|
||||||
|
</span>
|
||||||
|
<span className="pagination-info-files">
|
||||||
|
| {t('shown')} {table.getRowModel().rows.length} {t('out-of')} {appealsData?.totalCount ?? 0}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="pagination-controls">
|
||||||
|
<button
|
||||||
|
className="arrow"
|
||||||
|
onClick={() => table.firstPage()}
|
||||||
|
disabled={!table.getCanPreviousPage()}
|
||||||
|
>
|
||||||
|
<IconDoubleArrowLeft />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="arrow"
|
||||||
|
onClick={() => table.previousPage()}
|
||||||
|
disabled={!table.getCanPreviousPage()}
|
||||||
|
>
|
||||||
|
<IconArrowLeft />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div className="pagination-controls-pages">
|
||||||
|
{(() => {
|
||||||
|
const totalPages = appealsData?.totalPages;
|
||||||
|
if (!totalPages || totalPages === 0) return null;
|
||||||
|
|
||||||
|
const currentPageIndex = table.getState().pagination.pageIndex;
|
||||||
|
const maxVisiblePages = 5;
|
||||||
|
const visiblePagesCount = Math.min(maxVisiblePages, totalPages);
|
||||||
|
|
||||||
|
let startPage = currentPageIndex - Math.floor(maxVisiblePages / 2);
|
||||||
|
startPage = Math.max(0, Math.min(startPage, totalPages - visiblePagesCount));
|
||||||
|
|
||||||
|
return Array.from({ length: visiblePagesCount }, (_, i) => {
|
||||||
|
const pageIndex = startPage + i;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={pageIndex}
|
||||||
|
className={currentPageIndex === pageIndex ? 'current' : 'other'}
|
||||||
|
onClick={() => table.setPageIndex(pageIndex)}
|
||||||
|
>
|
||||||
|
{pageIndex + 1}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
})()}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className="arrow"
|
||||||
|
onClick={() => table.nextPage()}
|
||||||
|
disabled={!table.getCanNextPage()}
|
||||||
|
>
|
||||||
|
<IconArrowRight />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="arrow"
|
||||||
|
onClick={() => table.lastPage()}
|
||||||
|
disabled={!table.getCanNextPage()}
|
||||||
|
>
|
||||||
|
<IconDoubleArrowRight />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,613 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState, useMemo, useEffect, useCallback } from 'react';
|
||||||
|
import {
|
||||||
|
useReactTable,
|
||||||
|
getCoreRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
getPaginationRowModel,
|
||||||
|
getFilteredRowModel,
|
||||||
|
ColumnDef,
|
||||||
|
SortingState,
|
||||||
|
ColumnFiltersState,
|
||||||
|
} from '@tanstack/react-table';
|
||||||
|
import { IconEye, IconDoubleArrowRight, IconArrowRight, IconDoubleArrowLeft, IconArrowLeft, IconArrowUp, IconArrowDown, IconFilter, IconFileDownload } from '@/app/ui/icons/icons';
|
||||||
|
import { useTranslations } from 'next-intl';
|
||||||
|
import DropDownList from '@/app/components/dropDownList';
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import ModalWindow from '@/app/components/modalWindow';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { useContentForModeration, ModerationFile, ModerationStatus } from '@/app/hooks/react-query/useContentForModeration';
|
||||||
|
import { FileTypeIcon } from '@/app/components/FileTypeIcon';
|
||||||
|
import { getFileType } from '@/app/lib/getFileType';
|
||||||
|
import Image from 'next/image';
|
||||||
|
import { downloadFile } from '@/app/actions/contentActions';
|
||||||
|
import FileWithAppealModerationModal from './FileWithAppealModerationModal';
|
||||||
|
|
||||||
|
const cutFileExtension = (fileName: string) => {
|
||||||
|
const lastDotIndex = fileName.lastIndexOf('.');
|
||||||
|
const extension = fileName.substring(lastDotIndex + 1);
|
||||||
|
return extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cutFileName = (fileName: string) => {
|
||||||
|
const MAX_FILE_NAME_LENGTH = 30;
|
||||||
|
const lastDotIndex = fileName.lastIndexOf('.');
|
||||||
|
|
||||||
|
if (lastDotIndex <= 0) {
|
||||||
|
return fileName.length > MAX_FILE_NAME_LENGTH ? fileName.substring(0, MAX_FILE_NAME_LENGTH - 3) + '...' : fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nameWithoutExtension = fileName.substring(0, lastDotIndex);
|
||||||
|
const extension = fileName.substring(lastDotIndex);
|
||||||
|
|
||||||
|
if (fileName.length <= MAX_FILE_NAME_LENGTH) {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxNameLength = MAX_FILE_NAME_LENGTH - extension.length - 3;
|
||||||
|
|
||||||
|
if (maxNameLength <= 0) {
|
||||||
|
return '...' + extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nameWithoutExtension.substring(0, maxNameLength) + '...' + extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StatusBadge = ({ status }: { status: string }) => {
|
||||||
|
const statusConfig: Record<string, { className: string; label: string }> = {
|
||||||
|
'BLOCKED': { className: 'bg-red-100 text-red-800', label: 'Заблокировано' },
|
||||||
|
'MODERATION': { className: 'bg-yellow-100 text-yellow-800', label: 'На модерации' },
|
||||||
|
'APPROVED': { className: 'bg-green-100 text-green-800', label: 'Одобрено' },
|
||||||
|
'ACTIVE': { className: 'bg-green-100 text-green-800', label: 'ACTIVE' },
|
||||||
|
};
|
||||||
|
|
||||||
|
const config = statusConfig[status] || { className: 'bg-gray-100 text-gray-800', label: status };
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className={`px-2 py-1 rounded-full text-xs font-medium ${config.className}`}>
|
||||||
|
{config.label}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const AppealStatusBadge = ({ status }: { status: string }) => {
|
||||||
|
const statusConfig: Record<string, { className: string; label: string }> = {
|
||||||
|
'REJECTED': { className: 'bg-red-100 text-red-800', label: 'Заблокировано' },
|
||||||
|
'MODERATION': { className: 'bg-yellow-100 text-yellow-800', label: 'На модерации' },
|
||||||
|
'APPROVED': { className: 'bg-green-100 text-green-800', label: 'Одобрено' },
|
||||||
|
'PENDING': { className: 'bg-gray-100 text-gray-800', label: 'На рассмотрении' }
|
||||||
|
};
|
||||||
|
|
||||||
|
const config = statusConfig[status] || { className: 'bg-gray-100 text-gray-800', label: status };
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className={`px-2 py-1 rounded-full text-xs font-medium ${config.className}`}>
|
||||||
|
{config.label}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function ContentModerationTable({ permission }: { permission: number }) {
|
||||||
|
// Состояния
|
||||||
|
const [sorting, setSorting] = useState<SortingState>([]);
|
||||||
|
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
||||||
|
const [pagination, setPagination] = useState({
|
||||||
|
pageIndex: 0,
|
||||||
|
pageSize: 10,
|
||||||
|
});
|
||||||
|
const [openWindow, setOpenWindow] = useState<boolean>(false);
|
||||||
|
const [selectedFile, setSelectedFile] = useState<ModerationFile | null>(null);
|
||||||
|
const [isFileLoading, setIsFileLoading] = useState(false);
|
||||||
|
|
||||||
|
// НОВЫЕ СОСТОЯНИЯ ДЛЯ ФИЛЬТРОВ
|
||||||
|
const [selectedStatuses, setSelectedStatuses] = useState<ModerationStatus[]>([]);
|
||||||
|
const [isAppeal, setIsAppeal] = useState<boolean | undefined>(undefined);
|
||||||
|
|
||||||
|
const t = useTranslations("Global");
|
||||||
|
|
||||||
|
// Получаем параметры сортировки для API
|
||||||
|
const getSortParams = useMemo(() => {
|
||||||
|
if (sorting.length === 0) {
|
||||||
|
return { sortBy: '', sortDirection: undefined };
|
||||||
|
}
|
||||||
|
|
||||||
|
const sort = sorting[0];
|
||||||
|
const sortByMap: Record<string, string> = {
|
||||||
|
'fileName': 'originalFileName',
|
||||||
|
'userId': 'userId',
|
||||||
|
'status': 'status',
|
||||||
|
'createdAt': 'createdAt',
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
sortBy: sortByMap[sort.id] || sort.id,
|
||||||
|
sortDirection: sort.desc ? 'desc' : 'asc'
|
||||||
|
};
|
||||||
|
}, [sorting]);
|
||||||
|
|
||||||
|
// Используем хук с фильтрами
|
||||||
|
const {
|
||||||
|
data: moderationData,
|
||||||
|
isLoading,
|
||||||
|
isError,
|
||||||
|
isFetching,
|
||||||
|
error
|
||||||
|
} = useContentForModeration(
|
||||||
|
pagination.pageIndex,
|
||||||
|
pagination.pageSize,
|
||||||
|
getSortParams.sortBy,
|
||||||
|
getSortParams.sortDirection,
|
||||||
|
selectedStatuses.length > 0 ? selectedStatuses : undefined,
|
||||||
|
isAppeal
|
||||||
|
);
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const toggleStatus = (status: ModerationStatus) => {
|
||||||
|
setSelectedStatuses(prev => {
|
||||||
|
if (prev.includes(status)) {
|
||||||
|
return prev.filter(s => s !== status);
|
||||||
|
} else {
|
||||||
|
return [...prev, status];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setPagination(prev => ({ ...prev, pageIndex: 0 }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearAllStatuses = () => {
|
||||||
|
setSelectedStatuses([]);
|
||||||
|
setPagination(prev => ({ ...prev, pageIndex: 0 }));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Обработчик изменения isAppeal
|
||||||
|
const handleAppealChange = (value: string) => {
|
||||||
|
if (value === 'all') {
|
||||||
|
setIsAppeal(undefined);
|
||||||
|
} else if (value === 'hasAppeal') {
|
||||||
|
setIsAppeal(true);
|
||||||
|
} else if (value === 'noAppeal') {
|
||||||
|
setIsAppeal(false);
|
||||||
|
}
|
||||||
|
setPagination(prev => ({ ...prev, pageIndex: 0 }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleViewFile = useCallback((file: ModerationFile) => {
|
||||||
|
console.log('View file:', file);
|
||||||
|
setSelectedFile(file);
|
||||||
|
setOpenWindow(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleCloseModal = useCallback(() => {
|
||||||
|
setOpenWindow(false);
|
||||||
|
setSelectedFile(null);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleDownload = async (file: any) => {
|
||||||
|
setIsFileLoading(true)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await downloadFile(
|
||||||
|
file.fileId,
|
||||||
|
file.fileName || `file-${file.fileId}`
|
||||||
|
);
|
||||||
|
|
||||||
|
const byteCharacters = atob(result.data);
|
||||||
|
const byteNumbers = new Array(byteCharacters.length);
|
||||||
|
for (let i = 0; i < byteCharacters.length; i++) {
|
||||||
|
byteNumbers[i] = byteCharacters.charCodeAt(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
const byteArray = new Uint8Array(byteNumbers);
|
||||||
|
const blob = new Blob([byteArray], { type: result.contentType });
|
||||||
|
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = result.fileName;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
document.body.removeChild(a);
|
||||||
|
toast.success(`${t('file-is-downloading')} - ${file.fileName}`);
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(t('failed-to-download-file'));
|
||||||
|
} finally {
|
||||||
|
setIsFileLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns = useMemo<ColumnDef<ModerationFile>[]>(() => {
|
||||||
|
const allColumns: ColumnDef<ModerationFile>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: 'fileName',
|
||||||
|
header: ({ column }) => (
|
||||||
|
<div className="column start">
|
||||||
|
<span>
|
||||||
|
Название файла
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
|
className="sort-button"
|
||||||
|
>
|
||||||
|
{column.getIsSorted() === 'asc' ?
|
||||||
|
<span><IconArrowUp /></span>
|
||||||
|
: column.getIsSorted() === 'desc' ?
|
||||||
|
<span><IconArrowDown /></span>
|
||||||
|
: <span><IconFilter /></span>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center space-x-2 table-item table-item-file-name">
|
||||||
|
{getFileType(row.original.fileName) === 'image' && row.original?.image.length !== 0 ? (
|
||||||
|
<span
|
||||||
|
className="table-item-file-name-image-wrapper"
|
||||||
|
>
|
||||||
|
<Image
|
||||||
|
sizes="40px"
|
||||||
|
src={row.original?.image}
|
||||||
|
alt={row.original?.fileName}
|
||||||
|
unoptimized
|
||||||
|
fill
|
||||||
|
onError={(e) => {
|
||||||
|
const target = e.target as HTMLImageElement;
|
||||||
|
target.src = '/images/no-image.png';
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<FileTypeIcon type={row.original.fileName} />
|
||||||
|
)}
|
||||||
|
<div>
|
||||||
|
<div className="font-medium w-full truncate" title={row.original.fileName}>
|
||||||
|
<span className="font-semibold">
|
||||||
|
{cutFileName(row.original.fileName)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
enableColumnFilter: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'userId',
|
||||||
|
header: ({ column }) => (
|
||||||
|
<div className="column">
|
||||||
|
<span>
|
||||||
|
User ID
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
|
className="sort-button"
|
||||||
|
>
|
||||||
|
{column.getIsSorted() === 'asc' ?
|
||||||
|
<span><IconArrowUp /></span>
|
||||||
|
: column.getIsSorted() === 'desc' ?
|
||||||
|
<span><IconArrowDown /></span>
|
||||||
|
: <span><IconFilter /></span>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="text-center">
|
||||||
|
{row.original.userId}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'status',
|
||||||
|
header: ({ column }) => (
|
||||||
|
<div className="column">
|
||||||
|
<span>
|
||||||
|
Статус
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
|
className="sort-button"
|
||||||
|
>
|
||||||
|
{column.getIsSorted() === 'asc' ?
|
||||||
|
<span><IconArrowUp /></span>
|
||||||
|
: column.getIsSorted() === 'desc' ?
|
||||||
|
<span><IconArrowDown /></span>
|
||||||
|
: <span><IconFilter /></span>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="table-status">
|
||||||
|
<div>
|
||||||
|
<StatusBadge status={row.original.status} />
|
||||||
|
</div>
|
||||||
|
{row.original.moderationInfo.appealInfo?.status && (
|
||||||
|
<div>
|
||||||
|
{t('appeal')}: <AppealStatusBadge status={row.original.moderationInfo.appealInfo?.status} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (permission === 3) {
|
||||||
|
allColumns.push({
|
||||||
|
id: 'actions',
|
||||||
|
header: () => <div className="column">{t('actions')}</div>,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="actions">
|
||||||
|
<div className="actions-group">
|
||||||
|
<button
|
||||||
|
onClick={() => handleViewFile(row.original)}
|
||||||
|
className="bg-blue-500 hover:bg-blue-600 text-white p-2 rounded"
|
||||||
|
title="Просмотреть файл"
|
||||||
|
>
|
||||||
|
<IconEye />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() => handleDownload(row.original)}
|
||||||
|
disabled={isFileLoading}
|
||||||
|
className="table-action-download"
|
||||||
|
title={t('download')}
|
||||||
|
>
|
||||||
|
<IconFileDownload />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
enableSorting: false,
|
||||||
|
enableColumnFilter: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return allColumns;
|
||||||
|
}, [permission, handleViewFile, t]);
|
||||||
|
|
||||||
|
// Фильтрация данных (клиентская фильтрация, если нужно)
|
||||||
|
const filteredData = useMemo(() => {
|
||||||
|
if (!moderationData?.files) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = [...moderationData.files];
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}, [moderationData]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const currentPageRows = table.getRowModel().rows;
|
||||||
|
const pageCount = table.getPageCount();
|
||||||
|
|
||||||
|
if (currentPageRows.length === 0 && pagination.pageIndex > 0 && pageCount > 0) {
|
||||||
|
table.setPageIndex(pagination.pageIndex - 1);
|
||||||
|
}
|
||||||
|
}, [filteredData, pagination.pageIndex]);
|
||||||
|
|
||||||
|
// Создание таблицы
|
||||||
|
const table = useReactTable({
|
||||||
|
data: filteredData,
|
||||||
|
columns,
|
||||||
|
state: {
|
||||||
|
sorting,
|
||||||
|
columnFilters,
|
||||||
|
pagination
|
||||||
|
},
|
||||||
|
manualPagination: true,
|
||||||
|
manualSorting: true,
|
||||||
|
manualFiltering: true,
|
||||||
|
pageCount: moderationData?.totalPages || 0,
|
||||||
|
onPaginationChange: setPagination,
|
||||||
|
onSortingChange: (updater) => {
|
||||||
|
const newSorting = typeof updater === 'function' ? updater(sorting) : updater;
|
||||||
|
setSorting(newSorting);
|
||||||
|
setPagination(prev => ({ ...prev, pageIndex: 0 }));
|
||||||
|
},
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
getPaginationRowModel: getPaginationRowModel()
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isError) {
|
||||||
|
return (
|
||||||
|
<div className="text-center text-red-600 p-4">
|
||||||
|
Ошибка загрузки данных: {error?.message || 'Неизвестная ошибка'}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="tanstak-table-wrapper">
|
||||||
|
<ModalWindow state={openWindow} callBack={handleCloseModal}>
|
||||||
|
<FileWithAppealModerationModal file={selectedFile} onClose={handleCloseModal} />
|
||||||
|
</ModalWindow>
|
||||||
|
<h3>
|
||||||
|
Таблица модерации контента
|
||||||
|
</h3>
|
||||||
|
{/* Фильтры */}
|
||||||
|
<div className="tanstak-table-filtres">
|
||||||
|
{/* Блок фильтрации по статусам */}
|
||||||
|
<div className="">
|
||||||
|
<div className="table-filtres-label">Статусы:</div>
|
||||||
|
<div className="status-filters">
|
||||||
|
<button
|
||||||
|
onClick={() => toggleStatus('BLOCKED')}
|
||||||
|
className={`status-btn status-btn--block ${selectedStatuses.includes('BLOCKED') ? 'active' : ''}`}
|
||||||
|
>
|
||||||
|
BLOCKED
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => toggleStatus('ACTIVE')}
|
||||||
|
className={`status-btn status-btn--active ${selectedStatuses.includes('ACTIVE') ? 'active' : ''}`}
|
||||||
|
>
|
||||||
|
ACTIVE
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => toggleStatus('MODERATION')}
|
||||||
|
className={`status-btn status-btn--moderation ${selectedStatuses.includes('MODERATION') ? 'active' : ''}`}
|
||||||
|
>
|
||||||
|
MODERATION
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Блок фильтрации по апелляции */}
|
||||||
|
<div className="table-filtres-item appeal">
|
||||||
|
<div className="table-filtres-label">Апелляция:</div>
|
||||||
|
<DropDownList
|
||||||
|
value={isAppeal === undefined ? t('all') : t('has-appeal')}
|
||||||
|
callBack={handleAppealChange}
|
||||||
|
>
|
||||||
|
<li value="all">
|
||||||
|
{t('all')}
|
||||||
|
</li>
|
||||||
|
<li value="hasAppeal">
|
||||||
|
{t('has-appeal')}
|
||||||
|
</li>
|
||||||
|
{/* <li value="noAppeal">Без апелляции</li> */}
|
||||||
|
</DropDownList>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="table-filtres-item">
|
||||||
|
<div className="table-filtres-label">{t('items-per-page')}:</div>
|
||||||
|
<DropDownList
|
||||||
|
value={table.getState().pagination.pageSize}
|
||||||
|
//@ts-ignore
|
||||||
|
callBack={table.setPageSize}
|
||||||
|
>
|
||||||
|
{[5, 10, 20, 50, 100].map(pageSize => (
|
||||||
|
<li key={pageSize} value={pageSize}>
|
||||||
|
{t('show')} {pageSize}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</DropDownList>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Таблица */}
|
||||||
|
<div className="tanstak-table-block">
|
||||||
|
<table className="tanstak-table">
|
||||||
|
<thead className="tanstak-table-head">
|
||||||
|
{table.getHeaderGroups().map(headerGroup => (
|
||||||
|
<tr key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map(header => (
|
||||||
|
<th key={header.id}>
|
||||||
|
{header.isPlaceholder
|
||||||
|
? null
|
||||||
|
: typeof header.column.columnDef.header === 'function'
|
||||||
|
? header.column.columnDef.header(header.getContext())
|
||||||
|
: header.column.columnDef.header as string}
|
||||||
|
</th>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</thead>
|
||||||
|
<tbody className={`tanstak-table-body ${isFetching ? 'loading' : ''}`}>
|
||||||
|
{isLoading ? (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={columns.length} className="text-center py-8">
|
||||||
|
Загрузка...
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : table.getRowModel().rows.length > 0 ? (
|
||||||
|
table.getRowModel().rows.map(row => (
|
||||||
|
<tr key={row.original.fileId}>
|
||||||
|
{row.getVisibleCells().map(cell => (
|
||||||
|
<td key={cell.id}>
|
||||||
|
{typeof cell.column.columnDef.cell === 'function'
|
||||||
|
? cell.column.columnDef.cell(cell.getContext())
|
||||||
|
: cell.getValue() as string}
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={columns.length} className="text-center py-8">
|
||||||
|
{t('no-data-for-selected-filters')}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Пагинация */}
|
||||||
|
<div className="tanstak-table-pagination">
|
||||||
|
<div className="pagination-info">
|
||||||
|
<span className="pagination-info-pages">
|
||||||
|
{t('page')}{' '}
|
||||||
|
<strong>
|
||||||
|
{(moderationData?.currentPage ?? 0) + 1} {t('out-of')} {moderationData?.totalPages ?? 1}
|
||||||
|
</strong>
|
||||||
|
</span>
|
||||||
|
<span className="pagination-info-files">
|
||||||
|
| {t('shown')} {table.getRowModel().rows.length} {t('out-of')} {moderationData?.totalCount ?? 0}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="pagination-controls">
|
||||||
|
<button
|
||||||
|
className="arrow"
|
||||||
|
onClick={() => table.firstPage()}
|
||||||
|
disabled={!table.getCanPreviousPage()}
|
||||||
|
>
|
||||||
|
<IconDoubleArrowLeft />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="arrow"
|
||||||
|
onClick={() => table.previousPage()}
|
||||||
|
disabled={!table.getCanPreviousPage()}
|
||||||
|
>
|
||||||
|
<IconArrowLeft />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div className="pagination-controls-pages">
|
||||||
|
{(() => {
|
||||||
|
const totalPages = moderationData?.totalPages;
|
||||||
|
if (!totalPages || totalPages === 0) return null;
|
||||||
|
|
||||||
|
const currentPageIndex = table.getState().pagination.pageIndex;
|
||||||
|
const maxVisiblePages = 5;
|
||||||
|
const visiblePagesCount = Math.min(maxVisiblePages, totalPages);
|
||||||
|
|
||||||
|
let startPage = currentPageIndex - Math.floor(maxVisiblePages / 2);
|
||||||
|
startPage = Math.max(0, Math.min(startPage, totalPages - visiblePagesCount));
|
||||||
|
|
||||||
|
return Array.from({ length: visiblePagesCount }, (_, i) => {
|
||||||
|
const pageIndex = startPage + i;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={pageIndex}
|
||||||
|
className={currentPageIndex === pageIndex ? 'current' : 'other'}
|
||||||
|
onClick={() => table.setPageIndex(pageIndex)}
|
||||||
|
>
|
||||||
|
{pageIndex + 1}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
})()}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className="arrow"
|
||||||
|
onClick={() => table.nextPage()}
|
||||||
|
disabled={!table.getCanNextPage()}
|
||||||
|
>
|
||||||
|
<IconArrowRight />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="arrow"
|
||||||
|
onClick={() => table.lastPage()}
|
||||||
|
disabled={!table.getCanNextPage()}
|
||||||
|
>
|
||||||
|
<IconDoubleArrowRight />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -301,17 +301,6 @@ export function CreateStaffForm({ onSuccess }: { onSuccess?: () => void }) {
|
|||||||
<div className="templates-section">
|
<div className="templates-section">
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '10px' }}>
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '10px' }}>
|
||||||
<h3 style={{ margin: 0 }}>{tGeneral('template-management')}</h3>
|
<h3 style={{ margin: 0 }}>{tGeneral('template-management')}</h3>
|
||||||
<div style={{ display: 'flex', gap: '8px' }}>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setShowSaveDialog(true)}
|
|
||||||
className="btn-icon"
|
|
||||||
title={tGeneral('save-current-as-template')}
|
|
||||||
disabled={isPending}
|
|
||||||
>
|
|
||||||
<IconDiscet />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style={{ display: 'flex', gap: '10px', alignItems: 'center' }}>
|
<div style={{ display: 'flex', gap: '10px', alignItems: 'center' }}>
|
||||||
@@ -412,18 +401,30 @@ export function CreateStaffForm({ onSuccess }: { onSuccess?: () => void }) {
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<button
|
<div style={{ display: 'flex', gap: '8px' }}>
|
||||||
type="submit"
|
<button
|
||||||
className={`${styles['btn']}`}
|
type="button"
|
||||||
disabled={isPending}
|
onClick={() => setShowSaveDialog(true)}
|
||||||
>
|
className={`${styles['btn']} ${styles['save']}`}
|
||||||
{tGeneral('create')}
|
title={tGeneral('save-current-as-template')}
|
||||||
{isPending && (
|
disabled={isPending}
|
||||||
<div className="loading-animation">
|
>
|
||||||
<div className="global-spinner"></div>
|
{tGeneral('save-template')}
|
||||||
</div>
|
</button>
|
||||||
)}
|
|
||||||
</button>
|
<button
|
||||||
|
type="submit"
|
||||||
|
className={`${styles['btn']}`}
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
{tGeneral('create-stuff')}
|
||||||
|
{isPending && (
|
||||||
|
<div className="loading-animation">
|
||||||
|
<div className="global-spinner"></div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<ModalWindow state={showSaveDialog} callBack={setShowSaveDialog}>
|
<ModalWindow state={showSaveDialog} callBack={setShowSaveDialog}>
|
||||||
|
|||||||
+248
-86
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
import styles from '@/app/styles/module/login.module.scss'
|
import styles from '@/app/styles/module/login.module.scss'
|
||||||
import { useActionState, useState, useRef, useEffect } from 'react';
|
import { useActionState, useState, useRef, useEffect } from 'react';
|
||||||
import { authorization } from '@/app/actions/auth';
|
import { authorization, updatePasswordAction } from '@/app/actions/auth';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { IconEye } from '@/app/ui/icons/icons';
|
import { IconEye } from '@/app/ui/icons/icons';
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
|
import ModalWindow from '@/app/components/modalWindow';
|
||||||
|
|
||||||
export default function LoginForm() {
|
export default function LoginForm() {
|
||||||
const [state, formAction, isPending] = useActionState(
|
const [state, formAction, isPending] = useActionState(
|
||||||
@@ -15,8 +16,23 @@ export default function LoginForm() {
|
|||||||
const t = useTranslations('Login-register-form');
|
const t = useTranslations('Login-register-form');
|
||||||
|
|
||||||
const [showPassword, setShowPassword] = useState(false);
|
const [showPassword, setShowPassword] = useState(false);
|
||||||
|
const [showChangePasswordModal, setShowChangePasswordModal] = useState(false);
|
||||||
|
const [pendingPasswordUpdate, setPendingPasswordUpdate] = useState(false);
|
||||||
|
const [pendingUserData, setPendingUserData] = useState<{
|
||||||
|
email: string;
|
||||||
|
id: number;
|
||||||
|
oldPassword: string;
|
||||||
|
token: string;
|
||||||
|
} | null>(null);
|
||||||
|
const [passwordUpdateError, setPasswordUpdateError] = useState<string | null>(null);
|
||||||
|
|
||||||
function showPassowrd() {
|
const [newPassword, setNewPassword] = useState('');
|
||||||
|
const [confirmPassword, setConfirmPassword] = useState('');
|
||||||
|
const [showNewPassword, setShowNewPassword] = useState(false);
|
||||||
|
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
|
||||||
|
const [isRedirecting, setIsRedirecting] = useState(false);
|
||||||
|
|
||||||
|
function toggleShowPassword() {
|
||||||
setShowPassword(!showPassword);
|
setShowPassword(!showPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,92 +43,238 @@ export default function LoginForm() {
|
|||||||
queryClient.clear();
|
queryClient.clear();
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
const handlePasswordChangeRequired = (email: string, id: number, oldPassword: string, token: string) => {
|
||||||
<form
|
setPendingUserData({ email, id, oldPassword, token });
|
||||||
className={`${styles['form-wrapper']}`}
|
setShowChangePasswordModal(true);
|
||||||
action={formAction}
|
};
|
||||||
>
|
|
||||||
<div className={`${styles['form-group']}`}>
|
const handlePasswordUpdate = async () => {
|
||||||
<label className={`${styles['form-label']}`}>
|
if (!pendingUserData) return;
|
||||||
{t('email-adress')}
|
|
||||||
</label>
|
if (newPassword !== confirmPassword) {
|
||||||
<input
|
setPasswordUpdateError(t('passwords-do-not-match'));
|
||||||
type="readOnly"
|
return;
|
||||||
id="email"
|
}
|
||||||
name="email"
|
|
||||||
className={`${styles['form-input']}`}
|
if (newPassword.length < 6) {
|
||||||
placeholder={t('enter-email')}
|
setPasswordUpdateError(t('password-too-short'));
|
||||||
defaultValue={state?.previousState?.email ? state?.previousState?.email : ''}
|
return;
|
||||||
onChange={(e) => {
|
}
|
||||||
e.target.value = e.target.value.toLocaleLowerCase();
|
|
||||||
}}
|
setPendingPasswordUpdate(true);
|
||||||
/>
|
setPasswordUpdateError(null);
|
||||||
{state?.error?.email && (
|
|
||||||
<p className={`${styles['form-error']}`}>
|
try {
|
||||||
{t(state?.error?.email)}
|
const result = await updatePasswordAction(
|
||||||
</p>
|
pendingUserData.id,
|
||||||
)}
|
pendingUserData.oldPassword,
|
||||||
</div>
|
newPassword,
|
||||||
<div className={`${styles['form-group']}`}>
|
pendingUserData.email,
|
||||||
<label className={`${styles['form-label']}`}>
|
pendingUserData.token
|
||||||
{t('password')}
|
);
|
||||||
</label>
|
|
||||||
<div className={`${styles['password-wrapper']}`}>
|
if (result.success) {
|
||||||
<input
|
setShowChangePasswordModal(false);
|
||||||
type={showPassword ? "text" : "password"}
|
setIsRedirecting(true);
|
||||||
id="password"
|
setTimeout(() => {
|
||||||
name="password"
|
window.location.href = '/pages/';
|
||||||
className={`${styles['form-input']} ${styles['password']}`}
|
}, 500);
|
||||||
placeholder={t('enter-password')}
|
} else {
|
||||||
/>
|
setPasswordUpdateError(result.error || t('password-update-failed'));
|
||||||
<button
|
}
|
||||||
onClick={() => {
|
} catch (error) {
|
||||||
showPassowrd();
|
setPasswordUpdateError(t('password-update-failed'));
|
||||||
}}
|
} finally {
|
||||||
type="button"
|
setPendingPasswordUpdate(false);
|
||||||
className={`show-password-button ${showPassword ? 'show' : ''}`}
|
}
|
||||||
>
|
};
|
||||||
<IconEye />
|
|
||||||
</button>
|
if (isRedirecting) {
|
||||||
</div>
|
return (
|
||||||
{state?.error?.password && (
|
<div
|
||||||
<p className={`${styles['form-error']}`}>
|
className="loading-animation"
|
||||||
{t(state?.error?.password)}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{state?.error.server && (
|
|
||||||
<p className={`${styles['form-error']}`}>
|
|
||||||
{t(state?.error.server)}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
{/* <div className={`${styles['form-options']}`}>
|
|
||||||
<div className={`${styles['form-checkbox']}`}>
|
|
||||||
<input type="checkbox" id="remember" name="remember" ref={checkBoxRememberMe} />
|
|
||||||
<label
|
|
||||||
onClick={() => {
|
|
||||||
if (checkBoxRememberMe.current) {
|
|
||||||
checkBoxRememberMe.current.click();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className="select-none"
|
|
||||||
>
|
|
||||||
{t('remember-me')}
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div> */}
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
className={`${styles['btn']}`}
|
|
||||||
disabled={isPending}
|
|
||||||
>
|
>
|
||||||
{t("sign-in")}
|
<div
|
||||||
{isPending && (
|
className="global-spinner large"
|
||||||
<div className="loading-animation">
|
>
|
||||||
<div className="global-spinner"></div>
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<form
|
||||||
|
className={`${styles['form-wrapper']}`}
|
||||||
|
action={formAction}
|
||||||
|
>
|
||||||
|
<div className={`${styles['form-group']}`}>
|
||||||
|
<label className={`${styles['form-label']}`}>
|
||||||
|
{t('email-adress')}
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="email"
|
||||||
|
name="email"
|
||||||
|
className={`${styles['form-input']}`}
|
||||||
|
placeholder={t('enter-email')}
|
||||||
|
defaultValue={state?.previousState?.email ? state?.previousState?.email : ''}
|
||||||
|
onChange={(e) => {
|
||||||
|
e.target.value = e.target.value.toLowerCase();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{state?.error?.email && (
|
||||||
|
<p className={`${styles['form-error']}`}>
|
||||||
|
{t(state?.error?.email)}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className={`${styles['form-group']}`}>
|
||||||
|
<label className={`${styles['form-label']}`}>
|
||||||
|
{t('password')}
|
||||||
|
</label>
|
||||||
|
<div className={`${styles['password-wrapper']}`}>
|
||||||
|
<input
|
||||||
|
type={showPassword ? "text" : "password"}
|
||||||
|
id="password"
|
||||||
|
name="password"
|
||||||
|
className={`${styles['form-input']} ${styles['password']}`}
|
||||||
|
placeholder={t('enter-password')}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={toggleShowPassword}
|
||||||
|
type="button"
|
||||||
|
className={`show-password-button ${showPassword ? 'show' : ''}`}
|
||||||
|
>
|
||||||
|
<IconEye />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{state?.error?.password && (
|
||||||
|
<p className={`${styles['form-error']}`}>
|
||||||
|
{t(state?.error?.password)}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{state?.error?.server && (
|
||||||
|
<p className={`${styles['form-error']}`}>
|
||||||
|
{t(state?.error?.server)}
|
||||||
|
</p>
|
||||||
)}
|
)}
|
||||||
</button>
|
{state?.requirePasswordChange && state?.userData && (
|
||||||
</form>
|
<p className={`${styles['form-error']}`}>
|
||||||
|
{t('password-change-required')}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => handlePasswordChangeRequired(state.userData.email, state.userData.id, state.userData!.password, state.userData!.token)}
|
||||||
|
className={styles['change-password-btn']}
|
||||||
|
>
|
||||||
|
{t('change-password')}
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className={`${styles['btn']}`}
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
{t("sign-in")}
|
||||||
|
{isPending && (
|
||||||
|
<div className="loading-animation">
|
||||||
|
<div className="global-spinner"></div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<ModalWindow
|
||||||
|
state={showChangePasswordModal}
|
||||||
|
callBack={() => {
|
||||||
|
setShowChangePasswordModal(false);
|
||||||
|
setPendingUserData(null);
|
||||||
|
setNewPassword('');
|
||||||
|
setConfirmPassword('');
|
||||||
|
setPasswordUpdateError(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className={styles['change-password-modal']}>
|
||||||
|
<h3>{t('change-password')}</h3>
|
||||||
|
<p>{t('password-change-required-message')}</p>
|
||||||
|
|
||||||
|
<div className={styles['form-group']}>
|
||||||
|
<label className={styles['form-label']}>
|
||||||
|
{t('new-password')}
|
||||||
|
</label>
|
||||||
|
<div className={styles['password-wrapper']}>
|
||||||
|
<input
|
||||||
|
type={showNewPassword ? "text" : "password"}
|
||||||
|
value={newPassword}
|
||||||
|
onChange={(e) => setNewPassword(e.target.value)}
|
||||||
|
className={styles['form-input']}
|
||||||
|
placeholder={t('enter-new-password')}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setShowNewPassword(!showNewPassword)}
|
||||||
|
className="show-password-button"
|
||||||
|
>
|
||||||
|
<IconEye />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles['form-group']}>
|
||||||
|
<label className={styles['form-label']}>
|
||||||
|
{t('confirm-password')}
|
||||||
|
</label>
|
||||||
|
<div className={styles['password-wrapper']}>
|
||||||
|
<input
|
||||||
|
type={showConfirmPassword ? "text" : "password"}
|
||||||
|
value={confirmPassword}
|
||||||
|
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||||
|
className={styles['form-input']}
|
||||||
|
placeholder={t('confirm-new-password')}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setShowConfirmPassword(!showConfirmPassword)}
|
||||||
|
className="show-password-button"
|
||||||
|
>
|
||||||
|
<IconEye />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{passwordUpdateError && (
|
||||||
|
<p className={styles['form-error']}>{passwordUpdateError}</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className={styles['modal-buttons']}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
setShowChangePasswordModal(false);
|
||||||
|
setPendingUserData(null);
|
||||||
|
}}
|
||||||
|
className={`${styles['btn-secondary']} ${styles['btn']}`}
|
||||||
|
>
|
||||||
|
{t('cancel')}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handlePasswordUpdate}
|
||||||
|
disabled={pendingPasswordUpdate || !newPassword || !confirmPassword}
|
||||||
|
className={styles['btn']}
|
||||||
|
>
|
||||||
|
{t('update-password')}
|
||||||
|
{pendingPasswordUpdate && (
|
||||||
|
<div className="loading-animation">
|
||||||
|
<div className="global-spinner"></div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ModalWindow>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ export interface StaffMember {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TanstakStuffTable() {
|
export default function TanstakStuffTable({ permission }: { permission: 0 | 1 | 3 }) {
|
||||||
// Состояния
|
// Состояния
|
||||||
const [sorting, setSorting] = useState<SortingState>([]);
|
const [sorting, setSorting] = useState<SortingState>([]);
|
||||||
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
||||||
@@ -140,9 +140,9 @@ export default function TanstakStuffTable() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Определение колонок для сотрудников
|
// Определение колонок
|
||||||
const columns = useMemo<ColumnDef<StaffMember>[]>(
|
const columns = useMemo<ColumnDef<StaffMember>[]>(() => {
|
||||||
() => [
|
const allColumns: ColumnDef<StaffMember>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: 'id',
|
accessorKey: 'id',
|
||||||
header: ({ column }) => (
|
header: ({ column }) => (
|
||||||
@@ -282,7 +282,10 @@ export default function TanstakStuffTable() {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
]
|
||||||
|
|
||||||
|
if (permission === 3) {
|
||||||
|
allColumns.push({
|
||||||
id: 'actions',
|
id: 'actions',
|
||||||
header: () => {
|
header: () => {
|
||||||
return (
|
return (
|
||||||
@@ -320,10 +323,11 @@ export default function TanstakStuffTable() {
|
|||||||
),
|
),
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
},
|
},);
|
||||||
],
|
}
|
||||||
[t]
|
|
||||||
);
|
return allColumns;
|
||||||
|
}, [permission]);
|
||||||
|
|
||||||
const handleView = (staff: StaffMember) => {
|
const handleView = (staff: StaffMember) => {
|
||||||
setSelectedStaff(staff);
|
setSelectedStaff(staff);
|
||||||
|
|||||||
@@ -0,0 +1,232 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { useMutation } from '@tanstack/react-query';
|
||||||
|
import { addTariffs } from '@/app/actions/tariffActions';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import DropDownList from '@/app/components/dropDownList';
|
||||||
|
|
||||||
|
interface NewTariff {
|
||||||
|
name: string;
|
||||||
|
price: number;
|
||||||
|
tokens: number;
|
||||||
|
maxFilesCount: number;
|
||||||
|
diskSize: number;
|
||||||
|
maxUsers: number;
|
||||||
|
description: string;
|
||||||
|
tariffTerm: 'MONTHLY' | 'YEAR';
|
||||||
|
accountType: 'b2c' | 'b2b' | 'token';
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TariffCreateModal({ onClose, onSuccess }: {
|
||||||
|
onClose: () => void;
|
||||||
|
onSuccess: () => void;
|
||||||
|
}) {
|
||||||
|
const [formData, setFormData] = useState<NewTariff>({
|
||||||
|
price: 0,
|
||||||
|
name: '',
|
||||||
|
tokens: 0,
|
||||||
|
maxFilesCount: 0,
|
||||||
|
diskSize: 0,
|
||||||
|
maxUsers: 0,
|
||||||
|
description: '',
|
||||||
|
tariffTerm: 'MONTHLY',
|
||||||
|
accountType: 'b2c',
|
||||||
|
type: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const [typeError, setTypeError] = useState('');
|
||||||
|
|
||||||
|
const createTariffMutation = useMutation({
|
||||||
|
mutationFn: async () => {
|
||||||
|
return await addTariffs(
|
||||||
|
formData.price,
|
||||||
|
formData.name,
|
||||||
|
formData.type,
|
||||||
|
formData.tokens,
|
||||||
|
formData.maxFilesCount,
|
||||||
|
formData.diskSize,
|
||||||
|
formData.maxUsers,
|
||||||
|
formData.description,
|
||||||
|
formData.tariffTerm,
|
||||||
|
formData.accountType
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onSuccess: (data) => {
|
||||||
|
if (data !== null && data !== undefined) {
|
||||||
|
toast.success('Тариф успешно создан');
|
||||||
|
onSuccess();
|
||||||
|
} else {
|
||||||
|
toast.error('Не удалось создать тариф');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error('Произошла ошибка при создании тарифа');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
if (!formData.type.trim()) {
|
||||||
|
setTypeError('Введите тип тарифа');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setTypeError('');
|
||||||
|
createTariffMutation.mutate();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (field: string, value: any) => {
|
||||||
|
setFormData(prev => ({ ...prev, [field]: value }));
|
||||||
|
if (field === 'type') {
|
||||||
|
setTypeError('');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="tariff-edit-modal">
|
||||||
|
<h2 className="tariff-edit-modal__title">Создание нового тарифа</h2>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__content">
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Тип тарифа *</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className={`tariff-edit-modal__input ${typeError ? 'error' : ''}`}
|
||||||
|
value={formData.type}
|
||||||
|
onChange={(e) => handleChange('type', e.target.value)}
|
||||||
|
placeholder="Например: BASE, PREMIUM, TOKEN_1000"
|
||||||
|
/>
|
||||||
|
{typeError && <div className="error-message">{typeError}</div>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Название</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="tariff-edit-modal__input"
|
||||||
|
value={formData.name}
|
||||||
|
onChange={(e) => handleChange('name', e.target.value)}
|
||||||
|
placeholder="Введите название тарифа"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Цена (₽)</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="tariff-edit-modal__input"
|
||||||
|
value={formData.price}
|
||||||
|
onChange={(e) => handleChange('price', Number(e.target.value))}
|
||||||
|
placeholder="Введите цену"
|
||||||
|
min="0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Количество токенов</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="tariff-edit-modal__input"
|
||||||
|
value={formData.tokens}
|
||||||
|
onChange={(e) => handleChange('tokens', Number(e.target.value))}
|
||||||
|
placeholder="Введите количество токенов"
|
||||||
|
min="0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Максимальное количество файлов</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="tariff-edit-modal__input"
|
||||||
|
value={formData.maxFilesCount}
|
||||||
|
onChange={(e) => handleChange('maxFilesCount', Number(e.target.value))}
|
||||||
|
placeholder="Введите максимальное количество файлов"
|
||||||
|
min="0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Размер диска (байт)</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="tariff-edit-modal__input"
|
||||||
|
value={formData.diskSize}
|
||||||
|
onChange={(e) => handleChange('diskSize', Number(e.target.value))}
|
||||||
|
placeholder="Введите размер диска в байтах"
|
||||||
|
min="0"
|
||||||
|
step="1"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Максимальное количество пользователей</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="tariff-edit-modal__input"
|
||||||
|
value={formData.maxUsers}
|
||||||
|
onChange={(e) => handleChange('maxUsers', Number(e.target.value))}
|
||||||
|
placeholder="Введите максимальное количество пользователей"
|
||||||
|
min="0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Срок тарифа</label>
|
||||||
|
<DropDownList
|
||||||
|
value={formData.tariffTerm === 'YEAR' ? 'Год' : 'Месяц'}
|
||||||
|
callBack={(value: string) => {
|
||||||
|
handleChange('tariffTerm', value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<li value="MONTHLY">Месяц</li>
|
||||||
|
<li value="YEAR">Год</li>
|
||||||
|
</DropDownList>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Тип аккаунта</label>
|
||||||
|
<DropDownList
|
||||||
|
value={
|
||||||
|
formData.accountType === 'b2c' ? 'B2C' :
|
||||||
|
formData.accountType === 'b2b' ? 'B2B' : 'Token'
|
||||||
|
}
|
||||||
|
callBack={(value: string) => {
|
||||||
|
handleChange('accountType', value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<li value="b2c">B2C</li>
|
||||||
|
<li value="b2b">B2B</li>
|
||||||
|
<li value="token">Token</li>
|
||||||
|
</DropDownList>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Описание</label>
|
||||||
|
<textarea
|
||||||
|
className="tariff-edit-modal__textarea"
|
||||||
|
value={formData.description}
|
||||||
|
onChange={(e) => handleChange('description', e.target.value)}
|
||||||
|
placeholder="Введите описание тарифа"
|
||||||
|
rows={4}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__actions">
|
||||||
|
<button
|
||||||
|
onClick={onClose}
|
||||||
|
className="btn btn-secondary"
|
||||||
|
disabled={createTariffMutation.isPending}
|
||||||
|
>
|
||||||
|
Отмена
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleSubmit}
|
||||||
|
className="btn btn-primary"
|
||||||
|
disabled={createTariffMutation.isPending}
|
||||||
|
>
|
||||||
|
{createTariffMutation.isPending ? 'Создание...' : 'Создать'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { useMutation } from '@tanstack/react-query';
|
||||||
|
import { removeTariffs } from '@/app/actions/tariffActions';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
interface TariffDeleteModalProps {
|
||||||
|
tariffId: number;
|
||||||
|
tariffName: string;
|
||||||
|
onClose: () => void;
|
||||||
|
onSuccess: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TariffDeleteModal({ tariffId, tariffName, onClose, onSuccess }: TariffDeleteModalProps) {
|
||||||
|
const [isConfirmText, setIsConfirmText] = useState('');
|
||||||
|
const confirmText = 'УДАЛИТЬ';
|
||||||
|
|
||||||
|
const deleteTariffMutation = useMutation({
|
||||||
|
mutationFn: async () => {
|
||||||
|
return await removeTariffs(tariffId);
|
||||||
|
},
|
||||||
|
onSuccess: (data) => {
|
||||||
|
if (data !== null && data !== undefined) {
|
||||||
|
toast.success('Тариф успешно удален');
|
||||||
|
onSuccess();
|
||||||
|
} else {
|
||||||
|
toast.error('Не удалось удалить тариф');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error('Произошла ошибка при удалении тарифа');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleDelete = () => {
|
||||||
|
deleteTariffMutation.mutate();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getDisplayName = (name: string) => {
|
||||||
|
if (name) {
|
||||||
|
return name.toUpperCase().replace(/_/g, ' ');
|
||||||
|
}
|
||||||
|
return `ID: ${tariffId}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="tariff-delete-modal">
|
||||||
|
<h2 className="tariff-delete-modal__title">Удаление тарифа</h2>
|
||||||
|
|
||||||
|
<div className="tariff-delete-modal__content">
|
||||||
|
<div className="tariff-delete-modal__warning">
|
||||||
|
<p className="warning-text">
|
||||||
|
Вы действительно хотите удалить тариф <strong>"{getDisplayName(tariffName)}"</strong>?
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-delete-modal__info">
|
||||||
|
<p>Это действие невозможно отменить.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-delete-modal__confirm">
|
||||||
|
<label className="confirm-label">
|
||||||
|
Для подтверждения введите <strong>{confirmText}</strong>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="confirm-input"
|
||||||
|
value={isConfirmText}
|
||||||
|
onChange={(e) => setIsConfirmText(e.target.value)}
|
||||||
|
placeholder={`Введите "${confirmText}"`}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-delete-modal__actions">
|
||||||
|
<button
|
||||||
|
onClick={onClose}
|
||||||
|
className="btn btn-secondary"
|
||||||
|
disabled={deleteTariffMutation.isPending}
|
||||||
|
>
|
||||||
|
Отмена
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleDelete}
|
||||||
|
className="btn btn-danger"
|
||||||
|
disabled={isConfirmText !== confirmText || deleteTariffMutation.isPending}
|
||||||
|
>
|
||||||
|
{deleteTariffMutation.isPending ? 'Удаление...' : 'Удалить'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,223 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useMutation } from '@tanstack/react-query';
|
||||||
|
import { updateTariffs } from '@/app/actions/tariffActions';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import DropDownList from '@/app/components/dropDownList';
|
||||||
|
import { convertBytes } from '@/app/lib/convertBytes';
|
||||||
|
|
||||||
|
export interface EditingTariff {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
price: number;
|
||||||
|
tokens: number;
|
||||||
|
maxFilesCount: number;
|
||||||
|
diskSize: number;
|
||||||
|
maxUsers: number;
|
||||||
|
description: string;
|
||||||
|
tariffTerm: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TariffEditModal({ tariff, onClose, onSuccess }: {
|
||||||
|
tariff: EditingTariff;
|
||||||
|
onClose: () => void;
|
||||||
|
onSuccess: () => void;
|
||||||
|
}) {
|
||||||
|
const [formData, setFormData] = useState({
|
||||||
|
price: tariff.price,
|
||||||
|
name: tariff.name,
|
||||||
|
tokens: tariff.tokens,
|
||||||
|
maxFilesCount: tariff.maxFilesCount,
|
||||||
|
diskSize: tariff.diskSize,
|
||||||
|
maxUsers: tariff.maxUsers,
|
||||||
|
description: tariff.description,
|
||||||
|
tariffTerm: tariff.tariffTerm === 'YEAR' ? 'YEAR' : 'MONTHLY' as 'MONTHLY' | 'YEAR',
|
||||||
|
accountType: tariff.type.includes('TOKEN') ? 'token' : tariff.type.includes('STUDIO') ? 'b2b' : 'b2c' as 'b2c' | 'b2b' | 'token'
|
||||||
|
});
|
||||||
|
|
||||||
|
const updateTariffMutation = useMutation({
|
||||||
|
mutationFn: async () => {
|
||||||
|
return await updateTariffs(
|
||||||
|
tariff.id,
|
||||||
|
formData.price,
|
||||||
|
formData.name,
|
||||||
|
tariff.type,
|
||||||
|
formData.tokens,
|
||||||
|
formData.maxFilesCount,
|
||||||
|
formData.diskSize,
|
||||||
|
formData.maxUsers,
|
||||||
|
formData.description,
|
||||||
|
formData.tariffTerm,
|
||||||
|
formData.accountType
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onSuccess: (data) => {
|
||||||
|
if (data !== null && data !== undefined) {
|
||||||
|
toast.success('Тариф успешно обновлен');
|
||||||
|
|
||||||
|
onSuccess();
|
||||||
|
} else {
|
||||||
|
toast.error('Не удалось обновить тариф');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error('Произошла ошибка при обновлении тарифа');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
updateTariffMutation.mutate();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (field: string, value: any) => {
|
||||||
|
setFormData(prev => ({ ...prev, [field]: value }));
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="tariff-edit-modal">
|
||||||
|
<h2 className="tariff-edit-modal__title">Редактирование тарифа</h2>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__content">
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">ID тарифа</label>
|
||||||
|
<p className="tariff-edit-modal__value">{tariff.id}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Тип тарифа</label>
|
||||||
|
<p className="tariff-edit-modal__value">{tariff.type}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Название</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="tariff-edit-modal__input"
|
||||||
|
value={formData.name}
|
||||||
|
onChange={(e) => handleChange('name', e.target.value)}
|
||||||
|
placeholder="Введите название тарифа"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Цена (₽)</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="tariff-edit-modal__input"
|
||||||
|
value={formData.price}
|
||||||
|
onChange={(e) => handleChange('price', Number(e.target.value))}
|
||||||
|
placeholder="Введите цену"
|
||||||
|
min="0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Количество токенов</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="tariff-edit-modal__input"
|
||||||
|
value={formData.tokens}
|
||||||
|
onChange={(e) => handleChange('tokens', Number(e.target.value))}
|
||||||
|
placeholder="Введите количество токенов"
|
||||||
|
min="0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Максимальное количество файлов</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="tariff-edit-modal__input"
|
||||||
|
value={formData.maxFilesCount}
|
||||||
|
onChange={(e) => handleChange('maxFilesCount', Number(e.target.value))}
|
||||||
|
placeholder="Введите максимальное количество файлов"
|
||||||
|
min="0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Размер диска</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="tariff-edit-modal__input"
|
||||||
|
value={formData.diskSize}
|
||||||
|
onChange={(e) => handleChange('diskSize', Number(e.target.value))}
|
||||||
|
placeholder="Введите размер диска в ГБ"
|
||||||
|
min="0"
|
||||||
|
step="1"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Максимальное количество пользователей</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="tariff-edit-modal__input"
|
||||||
|
value={formData.maxUsers}
|
||||||
|
onChange={(e) => handleChange('maxUsers', Number(e.target.value))}
|
||||||
|
placeholder="Введите максимальное количество пользователей"
|
||||||
|
min="0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Срок тарифа</label>
|
||||||
|
<DropDownList
|
||||||
|
value={formData.tariffTerm === 'YEAR' ? 'Год' : 'Месяц'}
|
||||||
|
callBack={(value: string) => {
|
||||||
|
handleChange('tariffTerm', value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<li value="MONTHLY">Месяц</li>
|
||||||
|
<li value="YEAR">Год</li>
|
||||||
|
</DropDownList>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Тип аккаунта</label>
|
||||||
|
<DropDownList
|
||||||
|
value={
|
||||||
|
formData.accountType === 'b2c' ? 'B2C' :
|
||||||
|
formData.accountType === 'b2b' ? 'B2B' : 'Token'
|
||||||
|
}
|
||||||
|
callBack={(value: string) => {
|
||||||
|
handleChange('accountType', value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<li value="b2c">B2C</li>
|
||||||
|
<li value="b2b">B2B</li>
|
||||||
|
<li value="token">Token</li>
|
||||||
|
</DropDownList>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__info-section">
|
||||||
|
<label className="tariff-edit-modal__label">Описание</label>
|
||||||
|
<textarea
|
||||||
|
className="tariff-edit-modal__textarea"
|
||||||
|
value={formData.description}
|
||||||
|
onChange={(e) => handleChange('description', e.target.value)}
|
||||||
|
placeholder="Введите описание тарифа"
|
||||||
|
rows={4}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tariff-edit-modal__actions">
|
||||||
|
<button
|
||||||
|
onClick={onClose}
|
||||||
|
className="btn btn-secondary"
|
||||||
|
disabled={updateTariffMutation.isPending}
|
||||||
|
>
|
||||||
|
Отмена
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleSubmit}
|
||||||
|
className="btn btn-primary"
|
||||||
|
disabled={updateTariffMutation.isPending}
|
||||||
|
>
|
||||||
|
{updateTariffMutation.isPending ? 'Сохранение...' : 'Сохранить'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,271 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useTariffsData } from '@/app/hooks/react-query/useTariffsData';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { convertBytes } from '@/app/lib/convertBytes';
|
||||||
|
import { IconDoubleArrowRight, IconArrowRight, IconDoubleArrowLeft, IconArrowLeft } from '@/app/ui/icons/icons';
|
||||||
|
import ModalWindow from '@/app/components/modalWindow';
|
||||||
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { EditingTariff, TariffEditModal } from './TariffEditModal';
|
||||||
|
import { TariffCreateModal } from './TariffCreateModal';
|
||||||
|
import { TariffDeleteModal } from './TariffDeleteModal';
|
||||||
|
|
||||||
|
export default function TariffManagment() {
|
||||||
|
const [currentPage, setCurrentPage] = useState(0);
|
||||||
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
|
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
||||||
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
|
const [editingTariff, setEditingTariff] = useState<EditingTariff | null>(null);
|
||||||
|
const [deletingTariff, setDeletingTariff] = useState<{ id: number; name: string } | null>(null);
|
||||||
|
|
||||||
|
const { data: tariffData, isLoading, isError, isFetching, error } = useTariffsData(currentPage);
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(tariffData);
|
||||||
|
}, [tariffData])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (tariffData && tariffData.page !== currentPage) {
|
||||||
|
setCurrentPage(tariffData.page);
|
||||||
|
}
|
||||||
|
}, [tariffData, currentPage]);
|
||||||
|
|
||||||
|
const handlePageChange = (newPage: number) => {
|
||||||
|
if (tariffData && newPage >= 0 && newPage < tariffData.total_pages) {
|
||||||
|
setCurrentPage(newPage);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditClick = (tariff: any) => {
|
||||||
|
setEditingTariff({
|
||||||
|
id: tariff.id,
|
||||||
|
name: tariff.name,
|
||||||
|
type: tariff.type,
|
||||||
|
price: tariff.price,
|
||||||
|
tokens: tariff.tokens,
|
||||||
|
maxFilesCount: tariff.maxFilesCount,
|
||||||
|
diskSize: tariff.diskSize,
|
||||||
|
maxUsers: tariff.maxUsers,
|
||||||
|
description: tariff.description,
|
||||||
|
tariffTerm: tariff.tariffTerm
|
||||||
|
});
|
||||||
|
setIsModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteClick = (tariff: any) => {
|
||||||
|
setDeletingTariff({
|
||||||
|
id: tariff.id,
|
||||||
|
name: tariff.name || tariff.type
|
||||||
|
});
|
||||||
|
setIsDeleteModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatPrice = (price: number) => {
|
||||||
|
return new Intl.NumberFormat('ru-RU').format(price);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getDisplayName = (tariff: any) => {
|
||||||
|
if (tariff.name) {
|
||||||
|
return tariff.name.toUpperCase().replace(/_/g, ' ');
|
||||||
|
}
|
||||||
|
return tariff.type.replace(/_/g, ' ');
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="admin-content">
|
||||||
|
<div className="content-header">
|
||||||
|
<h3>Управление тарифными планами</h3>
|
||||||
|
</div>
|
||||||
|
<div className="content-body">
|
||||||
|
<div className="loading-spinner">Загрузка тарифов...</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isError) {
|
||||||
|
return (
|
||||||
|
<div className="admin-content">
|
||||||
|
<div className="content-header">
|
||||||
|
<h3>Управление тарифными планами</h3>
|
||||||
|
</div>
|
||||||
|
<div className="content-body">
|
||||||
|
<div className="error-message">
|
||||||
|
Ошибка загрузки тарифов: {error?.message || 'Неизвестная ошибка'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="admin-content">
|
||||||
|
<div className="content-header">
|
||||||
|
<h3>Управление тарифными планами</h3>
|
||||||
|
<div className="content-header-actions">
|
||||||
|
<button
|
||||||
|
className="btn btn-primary"
|
||||||
|
onClick={() => setIsCreateModalOpen(true)}
|
||||||
|
>
|
||||||
|
<span>➕</span>
|
||||||
|
<span>Создать тариф</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="content-body" id="plans-container">
|
||||||
|
<div className="stats-grid">
|
||||||
|
{tariffData?.tariffs?.map((tariff) => (
|
||||||
|
<div key={tariff.id} className="stat-card">
|
||||||
|
<div className="stat-card-header">
|
||||||
|
<span className="stat-card-title">{getDisplayName(tariff)}</span>
|
||||||
|
{tariff.tariffTerm && (
|
||||||
|
<span className="tariff-term-badge">{tariff.tariffTerm}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="stat-card-value">₽{formatPrice(tariff.price)}</div>
|
||||||
|
<div className="stat-card-label">
|
||||||
|
{tariff.tokens > 0 && `${tariff.tokens.toLocaleString()} токенов`}
|
||||||
|
{tariff.diskSize > 0 && ` • ${convertBytes(tariff.diskSize)}`}
|
||||||
|
{tariff.maxFilesCount > 0 && ` • ${tariff.maxFilesCount} файлов`}
|
||||||
|
</div>
|
||||||
|
{tariff.description && (
|
||||||
|
<div className="stat-card-description">{tariff.description}</div>
|
||||||
|
)}
|
||||||
|
<div className="stat-card-footer">
|
||||||
|
<button
|
||||||
|
className="btn btn-outline btn-sm"
|
||||||
|
onClick={() => handleEditClick(tariff)}
|
||||||
|
>
|
||||||
|
Редактировать
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="btn btn-outline btn-sm btn-danger"
|
||||||
|
onClick={() => handleDeleteClick(tariff)}
|
||||||
|
>
|
||||||
|
Удалить
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Пагинация */}
|
||||||
|
{tariffData && tariffData.total_pages > 0 && (
|
||||||
|
<div className="tanstak-table-pagination">
|
||||||
|
<div className="pagination-info">
|
||||||
|
<span className="pagination-info-pages">
|
||||||
|
Страница{' '}
|
||||||
|
<strong>
|
||||||
|
{currentPage + 1} из {tariffData.total_pages}
|
||||||
|
</strong>
|
||||||
|
</span>
|
||||||
|
<span className="pagination-info-files">
|
||||||
|
| Показано {tariffData.tariffs?.length || 0} из {tariffData.total_elements}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="pagination-controls">
|
||||||
|
<button
|
||||||
|
className="arrow"
|
||||||
|
onClick={() => handlePageChange(0)}
|
||||||
|
disabled={currentPage === 0 || isFetching}
|
||||||
|
>
|
||||||
|
<IconDoubleArrowLeft />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="arrow"
|
||||||
|
onClick={() => handlePageChange(currentPage - 1)}
|
||||||
|
disabled={currentPage === 0 || isFetching}
|
||||||
|
>
|
||||||
|
<IconArrowLeft />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div className="pagination-controls-pages">
|
||||||
|
{(() => {
|
||||||
|
const totalPages = tariffData.total_pages;
|
||||||
|
if (!totalPages || totalPages === 0) return null;
|
||||||
|
|
||||||
|
const maxVisiblePages = 5;
|
||||||
|
const visiblePagesCount = Math.min(maxVisiblePages, totalPages);
|
||||||
|
|
||||||
|
let startPage = currentPage - Math.floor(maxVisiblePages / 2);
|
||||||
|
startPage = Math.max(0, Math.min(startPage, totalPages - visiblePagesCount));
|
||||||
|
|
||||||
|
return Array.from({ length: visiblePagesCount }, (_, i) => {
|
||||||
|
const pageIndex = startPage + i;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={pageIndex}
|
||||||
|
className={currentPage === pageIndex ? 'current' : 'other'}
|
||||||
|
onClick={() => handlePageChange(pageIndex)}
|
||||||
|
disabled={isFetching}
|
||||||
|
>
|
||||||
|
{pageIndex + 1}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
})()}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className="arrow"
|
||||||
|
onClick={() => handlePageChange(currentPage + 1)}
|
||||||
|
disabled={currentPage === tariffData.total_pages - 1 || isFetching}
|
||||||
|
>
|
||||||
|
<IconArrowRight />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="arrow"
|
||||||
|
onClick={() => handlePageChange(tariffData.total_pages - 1)}
|
||||||
|
disabled={currentPage === tariffData.total_pages - 1 || isFetching}
|
||||||
|
>
|
||||||
|
<IconDoubleArrowRight />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{/* Модальное окно редактирования тарифа */}
|
||||||
|
<ModalWindow state={isModalOpen} callBack={setIsModalOpen}>
|
||||||
|
{editingTariff && (
|
||||||
|
<TariffEditModal
|
||||||
|
tariff={editingTariff}
|
||||||
|
onClose={() => setIsModalOpen(false)}
|
||||||
|
onSuccess={() => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['tariffsData'] });
|
||||||
|
setIsModalOpen(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</ModalWindow>
|
||||||
|
{/* Модальное окно создания тарифа */}
|
||||||
|
<ModalWindow state={isCreateModalOpen} callBack={setIsCreateModalOpen}>
|
||||||
|
<TariffCreateModal
|
||||||
|
onClose={() => setIsCreateModalOpen(false)}
|
||||||
|
onSuccess={() => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['tariffsData'] });
|
||||||
|
setIsCreateModalOpen(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ModalWindow>
|
||||||
|
{/* Модальное окно удаления тарифа */}
|
||||||
|
<ModalWindow state={isDeleteModalOpen} callBack={setIsDeleteModalOpen}>
|
||||||
|
{deletingTariff && (
|
||||||
|
<TariffDeleteModal
|
||||||
|
tariffId={deletingTariff.id}
|
||||||
|
tariffName={deletingTariff.name}
|
||||||
|
onClose={() => setIsDeleteModalOpen(false)}
|
||||||
|
onSuccess={() => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['tariffsData'] });
|
||||||
|
setIsDeleteModalOpen(false);
|
||||||
|
setDeletingTariff(null);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</ModalWindow>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -65,7 +65,7 @@ const cutFileName = (userId: string) => {
|
|||||||
return nameWithoutExtension.substring(0, maxNameLength) + '...' + extension;
|
return nameWithoutExtension.substring(0, maxNameLength) + '...' + extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TanstakUsersTable() {
|
export default function TanstakUsersTable({ permission }: { permission: number }) {
|
||||||
// Состояния
|
// Состояния
|
||||||
const [sorting, setSorting] = useState<SortingState>([]);
|
const [sorting, setSorting] = useState<SortingState>([]);
|
||||||
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
||||||
@@ -128,8 +128,8 @@ export default function TanstakUsersTable() {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
// Определение колонок
|
// Определение колонок
|
||||||
const columns = useMemo<ColumnDef<TransformedUser>[]>(
|
const columns = useMemo<ColumnDef<TransformedUser>[]>(() => {
|
||||||
() => [
|
const allColumns: ColumnDef<TransformedUser>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: 'id',
|
accessorKey: 'id',
|
||||||
header: ({ column }) => (
|
header: ({ column }) => (
|
||||||
@@ -383,16 +383,13 @@ export default function TanstakUsersTable() {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
{
|
]
|
||||||
|
|
||||||
|
if (permission === 3) {
|
||||||
|
allColumns.push({
|
||||||
id: 'actions',
|
id: 'actions',
|
||||||
header: () => {
|
header: () => <div className="column">{t('actions')}</div>,
|
||||||
return (
|
|
||||||
<div className="column">
|
|
||||||
{t('actions')}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<div className="actions">
|
<div className="actions">
|
||||||
<div className="actions-group">
|
<div className="actions-group">
|
||||||
@@ -407,10 +404,11 @@ export default function TanstakUsersTable() {
|
|||||||
),
|
),
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
},
|
});
|
||||||
],
|
}
|
||||||
[]
|
|
||||||
);
|
return allColumns;
|
||||||
|
}, [permission]);
|
||||||
|
|
||||||
const handleView = async (useId: number) => {
|
const handleView = async (useId: number) => {
|
||||||
let userInfo = await fetchUsesInfo(useId);
|
let userInfo = await fetchUsesInfo(useId);
|
||||||
|
|||||||
@@ -2,14 +2,15 @@
|
|||||||
|
|
||||||
import TanstakFilesTable from '@/app/ui/users/tanstak-users-table';
|
import TanstakFilesTable from '@/app/ui/users/tanstak-users-table';
|
||||||
import { useEmployeInfo } from '@/app/hooks/react-query/useEmployeInfo';
|
import { useEmployeInfo } from '@/app/hooks/react-query/useEmployeInfo';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
export function UsersTable() {
|
export function UsersTable() {
|
||||||
const { canRead } = useEmployeInfo();
|
const { getPermissionLevel } = useEmployeInfo();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{canRead('users') && (
|
{getPermissionLevel('users') > 0 && (
|
||||||
<TanstakFilesTable />
|
<TanstakFilesTable permission={getPermissionLevel('users')}/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -221,14 +221,18 @@
|
|||||||
"delete-template-confirm": "Delete template",
|
"delete-template-confirm": "Delete template",
|
||||||
"delete-template-warning": "Are you sure you want to delete this template?",
|
"delete-template-warning": "Are you sure you want to delete this template?",
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"delete": "Delete"
|
"delete": "Delete",
|
||||||
|
"create-stuff": "Create stuff",
|
||||||
|
"download": "Download",
|
||||||
|
"all": "All",
|
||||||
|
"has-appeal": "Has appeal",
|
||||||
|
"appeal": "Appeal"
|
||||||
},
|
},
|
||||||
"Login-register-form": {
|
"Login-register-form": {
|
||||||
"and": "and",
|
"and": "and",
|
||||||
"already-have-an-account": "Already have an account",
|
"already-have-an-account": "Already have an account",
|
||||||
"company": "Company",
|
"company": "Company",
|
||||||
"company-placeholder": "Your company",
|
"company-placeholder": "Your company",
|
||||||
"confirm-password": "Confirm password",
|
|
||||||
"copyright-protection": "Copyright protection",
|
"copyright-protection": "Copyright protection",
|
||||||
"create-an-account": "Create an account",
|
"create-an-account": "Create an account",
|
||||||
"email-adress": "Email adress",
|
"email-adress": "Email adress",
|
||||||
@@ -291,7 +295,19 @@
|
|||||||
"confirmation-code": "Confirmation code",
|
"confirmation-code": "Confirmation code",
|
||||||
"enter-confirmation-code": "Enter the confirmation code",
|
"enter-confirmation-code": "Enter the confirmation code",
|
||||||
"full-name-too-short": "Full name must be at least 2 characters",
|
"full-name-too-short": "Full name must be at least 2 characters",
|
||||||
"full-name-too-long": "Full name must not exceed 100 characters"
|
"full-name-too-long": "Full name must not exceed 100 characters",
|
||||||
|
"passwords-do-not-match": "Passwords do not match",
|
||||||
|
"password-too-short": "Password must be at least 6 characters",
|
||||||
|
"password-change-required": "Password change required",
|
||||||
|
"change-password": "Change password",
|
||||||
|
"password-change-required-message": "You must set a new password to continue",
|
||||||
|
"new-password": "New password",
|
||||||
|
"confirm-password": "Confirm password",
|
||||||
|
"enter-new-password": "Enter new password",
|
||||||
|
"confirm-new-password": "Confirm new password",
|
||||||
|
"update-password": "Update password",
|
||||||
|
"password-update-failed": "Failed to update password. Please try again later",
|
||||||
|
"cancel": "Cancel"
|
||||||
},
|
},
|
||||||
"Permissions": {
|
"Permissions": {
|
||||||
"edit-permissions": "Edit Permissions",
|
"edit-permissions": "Edit Permissions",
|
||||||
|
|||||||
@@ -221,14 +221,18 @@
|
|||||||
"delete-template-confirm": "Удалить шаблон",
|
"delete-template-confirm": "Удалить шаблон",
|
||||||
"delete-template-warning": "Вы уверены, что хотите удалить шаблон?",
|
"delete-template-warning": "Вы уверены, что хотите удалить шаблон?",
|
||||||
"save": "Сохранить",
|
"save": "Сохранить",
|
||||||
"delete": "Удалить"
|
"delete": "Удалить",
|
||||||
|
"create-stuff": "Создать сотрудника",
|
||||||
|
"download": "Скачать",
|
||||||
|
"all": "Все",
|
||||||
|
"has-appeal": "Есть апелляция",
|
||||||
|
"appeal": "Апелляция"
|
||||||
},
|
},
|
||||||
"Login-register-form": {
|
"Login-register-form": {
|
||||||
"and": "и",
|
"and": "и",
|
||||||
"already-have-an-account": "Уже есть аккаунт",
|
"already-have-an-account": "Уже есть аккаунт",
|
||||||
"company": "Компания",
|
"company": "Компания",
|
||||||
"company-placeholder": "ООО «Ваша компания»",
|
"company-placeholder": "ООО «Ваша компания»",
|
||||||
"confirm-password": "Подтвердите пароль",
|
|
||||||
"copyright-protection": "Защита авторских прав",
|
"copyright-protection": "Защита авторских прав",
|
||||||
"create-an-account": "Создать аккаунт",
|
"create-an-account": "Создать аккаунт",
|
||||||
"email-adress": "Email адрес",
|
"email-adress": "Email адрес",
|
||||||
@@ -291,7 +295,19 @@
|
|||||||
"confirmation-code": "Код подтверждения",
|
"confirmation-code": "Код подтверждения",
|
||||||
"enter-confirmation-code": "Введите код подтверждения",
|
"enter-confirmation-code": "Введите код подтверждения",
|
||||||
"full-name-too-short": "Полное имя должно состоять как минимум из 2 символов",
|
"full-name-too-short": "Полное имя должно состоять как минимум из 2 символов",
|
||||||
"full-name-too-long": "Полное имя не должно превышать 100 символов"
|
"full-name-too-long": "Полное имя не должно превышать 100 символов",
|
||||||
|
"passwords-do-not-match": "Пароли не совпадают",
|
||||||
|
"password-too-short": "Пароль должен содержать не менее 6 символов",
|
||||||
|
"password-change-required": "Требуется смена пароля",
|
||||||
|
"change-password": "Сменить пароль",
|
||||||
|
"password-change-required-message": "Для продолжения работы необходимо установить новый пароль",
|
||||||
|
"new-password": "Новый пароль",
|
||||||
|
"confirm-password": "Подтверждение пароля",
|
||||||
|
"enter-new-password": "Введите новый пароль",
|
||||||
|
"confirm-new-password": "Подтвердите новый пароль",
|
||||||
|
"update-password": "Обновить пароль",
|
||||||
|
"password-update-failed": "Не удалось обновить пароль. Попробуйте позже",
|
||||||
|
"cancel": "Отмена"
|
||||||
},
|
},
|
||||||
"Permissions": {
|
"Permissions": {
|
||||||
"edit-permissions": "Редактирование прав доступа",
|
"edit-permissions": "Редактирование прав доступа",
|
||||||
|
|||||||
Reference in New Issue
Block a user