landing page added

This commit is contained in:
nabijonovdavronbek619@gmail.com
2026-04-01 01:22:31 +05:00
parent 291375ce02
commit 80343c9ca8
34 changed files with 1262 additions and 49 deletions

View File

@@ -0,0 +1,29 @@
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import { getRouteLang } from './getLanguage';
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
const api = axios.create({
baseURL: baseUrl,
});
export const apiRequest = async <T>(
method: 'GET' | 'POST' | 'PUT' | 'DELETE',
url: string,
data?: unknown,
config?: Omit<AxiosRequestConfig, 'method' | 'url' | 'data'>,
): Promise<T> => {
const response: AxiosResponse<T> = await api.request<T>({
method,
url,
data,
...config,
headers: {
'Accept-Language': getRouteLang(), // evaluated per-request
...config?.headers,
},
});
return response.data;
};

View File

@@ -0,0 +1,30 @@
const defaultLocale = 'uz';
const locales = ['uz', 'ru', 'en'] as const;
export function getRouteLang(): string {
if (typeof window === 'undefined') return defaultLocale;
// 1)Fall back to the first non-empty pathname segment
const rawSegments = window.location.pathname.split('/'); // e.g. ['', 'uz', 'path', ...]
const segments = rawSegments.filter(Boolean); // removes empty strings
if (segments.length > 0) {
const candidate = segments[0]; // first segment after root
if (locales.includes(candidate as (typeof locales)[number]))
return candidate;
}
// 2) Try cookie NEXT_LOCALE first (language switcher sets it)
const cookieMatch = document.cookie
.split(';')
.map((c) => c.trim())
.find((c) => c.startsWith('NEXT_LOCALE='));
if (cookieMatch) {
const cookieLang = cookieMatch.split('=')[1];
if (locales.includes(cookieLang as (typeof locales)[number]))
return cookieLang;
}
// 3) final fallback
return defaultLocale;
}

View File

@@ -0,0 +1,4 @@
export const links = {
login: '/users/login/',
register: '/users/register/',
};

View File

@@ -0,0 +1,41 @@
// ─── Constants ───────────────────────────────────────────────────────────────
import {
PlagiarismSubmissionPayload,
PlagiarismSubmissionResponse,
} from '@/widgets/fileUpload/lib/types';
const API_BASE_URL = process.env.VITE_API_BASE_URL ?? '/api';
const ENDPOINT = `${API_BASE_URL}/plagiarism/submit`;
// ─── API Function ────────────────────────────────────────────────────────────
/**
* Submits a document for plagiarism checking.
* Sends a multipart/form-data request to the backend API.
*/
export async function submitPlagiarismCheck(
payload: PlagiarismSubmissionPayload,
): Promise<PlagiarismSubmissionResponse> {
const formData = new FormData();
formData.append('topic', payload.topic);
formData.append('senderFullName', payload.senderFullName);
formData.append('file', payload.file);
formData.append('withCertificate', String(payload.withCertificate));
const response = await fetch(ENDPOINT, {
method: 'POST',
body: formData,
// Do NOT set Content-Type manually — the browser sets it with the boundary
});
if (!response.ok) {
const errorBody = await response.json().catch(() => ({}));
throw new Error(
(errorBody as { message?: string }).message ??
`Request failed with status ${response.status}`,
);
}
return response.json() as Promise<PlagiarismSubmissionResponse>;
}