Compare commits
30 Commits
065360b7a8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c7ede31b68 | |||
| 55ba274346 | |||
| 29cadb83e6 | |||
| 03c7c07a9f | |||
| 666d04ff26 | |||
| 132c8c44ef | |||
| 8abfcc9c2b | |||
| 69908887c1 | |||
| e4ab9d2a12 | |||
| b4e06b641d | |||
| e8eff6c2cb | |||
| a0190bc7ad | |||
| c6b1712486 | |||
| ce6cd6cccc | |||
| 3645d60730 | |||
| 549f6aff86 | |||
| 64b240bf26 | |||
| 870d198cc8 | |||
| ef3eaf1206 | |||
| 177b20e8ea | |||
| f30ea5d395 | |||
| c895b8f44d | |||
| 854f439bf9 | |||
| 215425dede | |||
| 22390592eb | |||
| eb41c8528d | |||
| c673159032 | |||
| 9a217fcd54 | |||
| 993dffb51d | |||
| 35c46ea460 |
106
package-lock.json
generated
106
package-lock.json
generated
@@ -22,7 +22,8 @@
|
||||
"react-router-dom": "^7.13.1",
|
||||
"recharts": "^3.8.1",
|
||||
"sonner": "^2.0.7",
|
||||
"tailwind-merge": "^3.5.0"
|
||||
"tailwind-merge": "^3.5.0",
|
||||
"xlsx": "^0.18.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.1",
|
||||
@@ -2366,6 +2367,15 @@
|
||||
"acorn": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/adler-32": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/adler-32/-/adler-32-1.3.1.tgz",
|
||||
"integrity": "sha512-ynZ4w/nUUv5rrsR8UUGoe1VC9hZj6V5hU9Qw1HlMDJGEJw5S7TfTErWTjMys6M7vr0YWcPqs3qAr4ss0nDfP+A==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/ajv": {
|
||||
"version": "6.14.0",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/ajv/-/ajv-6.14.0.tgz",
|
||||
@@ -2569,6 +2579,19 @@
|
||||
],
|
||||
"license": "CC-BY-4.0"
|
||||
},
|
||||
"node_modules/cfb": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/cfb/-/cfb-1.2.2.tgz",
|
||||
"integrity": "sha512-KfdUZsSOw19/ObEWasvBP/Ac4reZvAGauZhs6S/gqNhXhI7cKwvlH7ulj+dOEYnca4bm4SGo8C1bTAQvnTjgQA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"adler-32": "~1.3.0",
|
||||
"crc-32": "~1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/chalk": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/chalk/-/chalk-4.1.2.tgz",
|
||||
@@ -2607,6 +2630,15 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/codepage": {
|
||||
"version": "1.15.0",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/codepage/-/codepage-1.15.0.tgz",
|
||||
"integrity": "sha512-3g6NUTPd/YtuuGrhMnOMRjFc+LJw/bnMp3+0r/Wcz3IXUuCosKRJvMphm5+Q+bvTVGcJJuRvVLuYba+WojaFaA==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/color-convert": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/color-convert/-/color-convert-2.0.1.tgz",
|
||||
@@ -2666,6 +2698,18 @@
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/crc-32": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/crc-32/-/crc-32-1.2.2.tgz",
|
||||
"integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==",
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"crc32": "bin/crc32.njs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/cross-spawn": {
|
||||
"version": "7.0.6",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||
@@ -3326,6 +3370,15 @@
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/frac": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/frac/-/frac-1.1.2.tgz",
|
||||
"integrity": "sha512-w/XBfkibaTl3YDqASwfDUqkna4Z2p9cFSr1aHDt0WoMTECnRfBOv2WArlZILlqgWlmdIlALXGpM2AOhEk5W3IA==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/fraction.js": {
|
||||
"version": "5.3.4",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/fraction.js/-/fraction.js-5.3.4.tgz",
|
||||
@@ -4548,6 +4601,18 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ssf": {
|
||||
"version": "0.11.2",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/ssf/-/ssf-0.11.2.tgz",
|
||||
"integrity": "sha512-+idbmIXoYET47hH+d7dfm2epdOMUDjqcB4648sTZ+t2JwoyBFL/insLfB/racrDmsKB3diwsDA696pZMieAC5g==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"frac": "~1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-json-comments": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
|
||||
@@ -4870,6 +4935,24 @@
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/wmf": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/wmf/-/wmf-1.0.2.tgz",
|
||||
"integrity": "sha512-/p9K7bEh0Dj6WbXg4JG0xvLQmIadrner1bi45VMJTfnbVHsc7yIajZyoSoK60/dtVBs12Fm6WkUI5/3WAVsNMw==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/word": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/word/-/word-0.3.0.tgz",
|
||||
"integrity": "sha512-OELeY0Q61OXpdUfTp+oweA/vtLVg5VDOXh+3he3PNzLGG/y0oylSOC1xRVj0+l4vQ3tj/bB1HVHv1ocXkQceFA==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/word-wrap": {
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/word-wrap/-/word-wrap-1.2.5.tgz",
|
||||
@@ -4880,6 +4963,27 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/xlsx": {
|
||||
"version": "0.18.5",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/xlsx/-/xlsx-0.18.5.tgz",
|
||||
"integrity": "sha512-dmg3LCjBPHZnQp5/F/+nnTa+miPJxUXB6vtk42YjBBKayDNagxGEeIdWApkYPOf3Z3pm3k62Knjzp7lMeTEtFQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"adler-32": "~1.3.0",
|
||||
"cfb": "~1.2.1",
|
||||
"codepage": "~1.15.0",
|
||||
"crc-32": "~1.2.1",
|
||||
"ssf": "~0.11.2",
|
||||
"wmf": "~1.0.1",
|
||||
"word": "~0.3.0"
|
||||
},
|
||||
"bin": {
|
||||
"xlsx": "bin/xlsx.njs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/yallist": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://package-mirror.liara.ir/repository/npm/yallist/-/yallist-3.1.1.tgz",
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
"react-router-dom": "^7.13.1",
|
||||
"recharts": "^3.8.1",
|
||||
"sonner": "^2.0.7",
|
||||
"tailwind-merge": "^3.5.0"
|
||||
"tailwind-merge": "^3.5.0",
|
||||
"xlsx": "^0.18.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.1",
|
||||
|
||||
BIN
public/qlockify-profile-dark.png
Normal file
BIN
public/qlockify-profile-dark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
BIN
public/qlockify-profile-light.png
Normal file
BIN
public/qlockify-profile-light.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
67
src/App.tsx
67
src/App.tsx
@@ -5,6 +5,7 @@ import { LanguageProvider } from "./components/LanguageProvider"
|
||||
import { Toaster } from "./components/ui/toaster"
|
||||
import { Navbar } from "./components/Navbar"
|
||||
import { Sidebar } from './components/Sidebar';
|
||||
import { AppProvider } from "./context/AppContext"
|
||||
import { NotificationsProvider } from "./context/NotificationsContext"
|
||||
import { WorkspaceProvider } from "./context/WorkspaceContext"
|
||||
import Auth from "./pages/Auth"
|
||||
@@ -17,8 +18,6 @@ import WorkspaceDetail from "./pages/WorkspaceDetail"
|
||||
import EditWorkspace from "./pages/WorkspaceEdit"
|
||||
import Clients from "./pages/Clients"
|
||||
import { Projects } from "./pages/Projects"
|
||||
import ProjectCreate from "./pages/ProjectCreate"
|
||||
import ProjectEdit from "./pages/ProjectEdit"
|
||||
import Tags from "./pages/Tags"
|
||||
import Reports from "./pages/Reports"
|
||||
import Timesheet from "./pages/Timesheet"
|
||||
@@ -26,7 +25,10 @@ import Logs from "./pages/Logs"
|
||||
import NotificationsPage from "./pages/Notifications"
|
||||
import RateLimitPage from "./pages/RateLimit"
|
||||
import Landing from "./pages/Landing"
|
||||
import About from "./pages/About"
|
||||
import NotFound from "./pages/NotFound"
|
||||
import { isRateLimitActive } from "./lib/rateLimit"
|
||||
import { getAccessToken } from "./lib/session"
|
||||
import { AuthFlowProvider } from "./context/AuthFlowContext"
|
||||
import { LoginMobilePage } from "./pages/auth/LoginMobilePage"
|
||||
import { LoginOtpPage } from "./pages/auth/LoginOtpPage"
|
||||
@@ -64,10 +66,18 @@ const AppRedirect = () => {
|
||||
return <Navigate to="/rate-limit" replace />
|
||||
}
|
||||
|
||||
const isAuthenticated = !!localStorage.getItem("accessToken")
|
||||
const isAuthenticated = !!getAccessToken()
|
||||
return isAuthenticated ? <Navigate to="/timesheet" replace /> : <Navigate to="/auth" replace />
|
||||
}
|
||||
|
||||
const AuthenticatedRedirectGuard = () => {
|
||||
return getAccessToken() ? <Navigate to="/timesheet" replace /> : <Outlet />
|
||||
}
|
||||
|
||||
const AuthRequiredGuard = () => {
|
||||
return getAccessToken() ? <Outlet /> : <Navigate to="/auth" replace />
|
||||
}
|
||||
|
||||
const RateLimitGuard = () => {
|
||||
const location = useLocation()
|
||||
|
||||
@@ -78,27 +88,38 @@ const RateLimitGuard = () => {
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
const AuthLayout = () => (
|
||||
<AuthFlowProvider>
|
||||
<Auth />
|
||||
</AuthFlowProvider>
|
||||
)
|
||||
|
||||
const ProtectedAppLayout = () => (
|
||||
<AppProvider>
|
||||
<WorkspaceProvider>
|
||||
<NotificationsProvider>
|
||||
<MainLayout />
|
||||
</NotificationsProvider>
|
||||
</WorkspaceProvider>
|
||||
</AppProvider>
|
||||
)
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{ path: "/", element: <Landing /> },
|
||||
{ path: "/about", element: <About /> },
|
||||
{ path: "/terms", element: <Terms /> },
|
||||
{ path: "/rate-limit", element: <RateLimitPage /> },
|
||||
{
|
||||
element: <RateLimitGuard />,
|
||||
children: [
|
||||
{
|
||||
element: (
|
||||
<WorkspaceProvider>
|
||||
<Outlet />
|
||||
</WorkspaceProvider>
|
||||
),
|
||||
children: [
|
||||
{ path: "/", element: <Landing /> },
|
||||
{ path: "/app", element: <AppRedirect /> },
|
||||
{ path: "/auth/google/callback", element: <GoogleAuthCallback /> },
|
||||
{
|
||||
path: "/auth",
|
||||
element: (
|
||||
<AuthFlowProvider>
|
||||
<Auth />
|
||||
</AuthFlowProvider>
|
||||
),
|
||||
element: <AuthenticatedRedirectGuard />,
|
||||
children: [
|
||||
{
|
||||
element: <AuthLayout />,
|
||||
children: [
|
||||
{ index: true, element: <Navigate to="/auth/login" replace /> },
|
||||
{ path: "login", element: <LoginMobilePage /> },
|
||||
@@ -112,10 +133,13 @@ const router = createBrowserRouter([
|
||||
{ path: "forgot-password/password", element: <ForgotPasswordPasswordPage /> },
|
||||
],
|
||||
},
|
||||
{ path: "/terms", element: <Terms /> },
|
||||
{ path: "/rate-limit", element: <RateLimitPage /> },
|
||||
],
|
||||
},
|
||||
{
|
||||
element: <MainLayout />,
|
||||
element: <AuthRequiredGuard />,
|
||||
children: [
|
||||
{
|
||||
element: <ProtectedAppLayout />,
|
||||
children: [
|
||||
{ path: "/profile", element: <Profile /> },
|
||||
{ path: "/timesheet", element: <Timesheet /> },
|
||||
@@ -129,23 +153,20 @@ const router = createBrowserRouter([
|
||||
{ path: "/workspaces/:id/edit", element: <EditWorkspace /> },
|
||||
{ path: "/clients", element: <Clients /> },
|
||||
{ path: "/projects", element: <Projects /> },
|
||||
{ path: "/projects/create", element: <ProjectCreate /> },
|
||||
{ path: "/projects/:id/edit", element: <ProjectEdit /> },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{ path: "*", element: <NotFound /> },
|
||||
]);
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<ThemeProvider>
|
||||
<LanguageProvider>
|
||||
<NotificationsProvider>
|
||||
<RouterProvider router={router} />
|
||||
</NotificationsProvider>
|
||||
<Toaster />
|
||||
</LanguageProvider>
|
||||
</ThemeProvider>
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
emitSessionChanged,
|
||||
getAccessToken,
|
||||
getRefreshToken,
|
||||
isDemoSession,
|
||||
} from "../lib/session"
|
||||
|
||||
let refreshRequest: Promise<string | null> | null = null
|
||||
@@ -88,9 +89,10 @@ const normalizeJsonResponse = (response: Response) => {
|
||||
}
|
||||
|
||||
const clearSessionAndRedirect = () => {
|
||||
const redirectTarget = isDemoSession() ? "/" : "/auth"
|
||||
clearSessionTokens()
|
||||
if (window.location.pathname !== "/auth") {
|
||||
window.location.href = "/auth"
|
||||
if (window.location.pathname !== redirectTarget) {
|
||||
window.location.href = redirectTarget
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +147,7 @@ const shouldAttemptRefresh = (endpoint: string) => {
|
||||
"/api/users/otp/send/",
|
||||
"/api/users/otp/login/",
|
||||
"/api/users/token/refresh/",
|
||||
"/api/demo/start/",
|
||||
].includes(normalizedEndpoint)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ export interface Client {
|
||||
id: string
|
||||
name: string
|
||||
notes?: string
|
||||
thumbnail?: string | null
|
||||
}
|
||||
|
||||
interface PaginatedResponse<T> {
|
||||
@@ -36,13 +37,35 @@ export const getClients = async (
|
||||
});
|
||||
};
|
||||
|
||||
export const createClient = async (workspaceId: string, data: { name: string; notes: string }) => {
|
||||
const response = await authFetch("/api/clients/", {
|
||||
method: "POST",
|
||||
const buildClientBody = (
|
||||
workspaceId: string | null,
|
||||
data: { name?: string; notes?: string; thumbnail?: File | null; clear_thumbnail?: boolean },
|
||||
) => {
|
||||
const hasFile = data.thumbnail instanceof File;
|
||||
const shouldClear = Boolean(data.clear_thumbnail);
|
||||
if (!hasFile && !shouldClear) {
|
||||
return {
|
||||
body: JSON.stringify({
|
||||
workspace_id: workspaceId,
|
||||
...(workspaceId ? { workspace_id: workspaceId } : {}),
|
||||
...data,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
if (workspaceId) formData.append("workspace_id", workspaceId);
|
||||
if (data.name !== undefined) formData.append("name", data.name);
|
||||
if (data.notes !== undefined) formData.append("notes", data.notes);
|
||||
if (data.thumbnail) formData.append("thumbnail", data.thumbnail);
|
||||
if (shouldClear) formData.append("clear_thumbnail", "true");
|
||||
return { body: formData };
|
||||
};
|
||||
|
||||
export const createClient = async (workspaceId: string, data: { name: string; notes: string; thumbnail?: File | null }) => {
|
||||
const requestBody = buildClientBody(workspaceId, data);
|
||||
const response = await authFetch("/api/clients/", {
|
||||
method: "POST",
|
||||
body: requestBody.body,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -54,10 +77,14 @@ export const createClient = async (workspaceId: string, data: { name: string; no
|
||||
return payload;
|
||||
};
|
||||
|
||||
export const updateClient = async (id: string, data: { name?: string; notes?: string }) => {
|
||||
export const updateClient = async (
|
||||
id: string,
|
||||
data: { name?: string; notes?: string; thumbnail?: File | null; clear_thumbnail?: boolean },
|
||||
) => {
|
||||
const requestBody = buildClientBody(null, data);
|
||||
const response = await authFetch(`/api/clients/${id}/`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(data),
|
||||
body: requestBody.body,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
41
src/api/contact.ts
Normal file
41
src/api/contact.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { buildApiError, buildApiUrl } from "./client"
|
||||
|
||||
const normalizeDigits = (value: string) =>
|
||||
value
|
||||
.replace(/[۰-۹]/g, (digit) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(digit)))
|
||||
.replace(/[٠-٩]/g, (digit) => String("٠١٢٣٤٥٦٧٨٩".indexOf(digit)))
|
||||
|
||||
export interface ContactSubmissionPayload {
|
||||
first_name: string
|
||||
last_name: string
|
||||
email: string
|
||||
mobile: string
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface ContactSubmissionResponse extends ContactSubmissionPayload {
|
||||
id: string
|
||||
status: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export const submitContactForm = async (
|
||||
payload: ContactSubmissionPayload,
|
||||
): Promise<ContactSubmissionResponse> => {
|
||||
const response = await fetch(buildApiUrl("/api/contact/"), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
...payload,
|
||||
mobile: normalizeDigits(payload.mobile),
|
||||
}),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw await buildApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
17
src/api/demo.ts
Normal file
17
src/api/demo.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { authFetch, buildApiError } from "./client"
|
||||
|
||||
export interface DemoStartResponse {
|
||||
access: string
|
||||
refresh: string
|
||||
workspace_id: string
|
||||
expires_at: string
|
||||
demo_environment_id: string
|
||||
}
|
||||
|
||||
export const startDemo = async (): Promise<DemoStartResponse> => {
|
||||
const response = await authFetch("/api/demo/start/", {
|
||||
method: "POST",
|
||||
})
|
||||
if (!response.ok) throw await buildApiError(response)
|
||||
return response.json()
|
||||
}
|
||||
@@ -11,6 +11,14 @@ interface AuditUser {
|
||||
export interface ProjectClient {
|
||||
id: string;
|
||||
name: string;
|
||||
thumbnail?: string | null;
|
||||
}
|
||||
|
||||
export interface ProjectAccessRateValue {
|
||||
id: string;
|
||||
hourly_rate: string;
|
||||
currency: string;
|
||||
effective_from: string | null;
|
||||
}
|
||||
|
||||
export interface Project {
|
||||
@@ -18,6 +26,7 @@ export interface Project {
|
||||
name: string;
|
||||
description: string;
|
||||
color: string;
|
||||
thumbnail?: string | null;
|
||||
created_at?: string;
|
||||
is_archived: boolean;
|
||||
is_deleted?: boolean;
|
||||
@@ -34,14 +43,21 @@ export interface ProjectAccessItem {
|
||||
is_archived: boolean;
|
||||
client: ProjectClient | null;
|
||||
has_access: boolean;
|
||||
workspace_rate: ProjectAccessRateValue | null;
|
||||
project_rate: ProjectAccessRateValue | null;
|
||||
}
|
||||
|
||||
export interface ProjectAccessState {
|
||||
workspace: { id: string; name: string };
|
||||
user: { id: string; name: string; mobile: string; role: "member" | "guest" };
|
||||
user: { id: string; name: string; mobile: string; role: "owner" | "admin" | "member" | "guest" };
|
||||
items: ProjectAccessItem[];
|
||||
}
|
||||
|
||||
interface ProjectAccessRateMutationResponse {
|
||||
removed: boolean;
|
||||
item: ProjectAccessItem;
|
||||
}
|
||||
|
||||
export interface ProjectPayload {
|
||||
name: string;
|
||||
description: string;
|
||||
@@ -49,8 +65,30 @@ export interface ProjectPayload {
|
||||
is_archived: boolean;
|
||||
workspace: string;
|
||||
client: string | null;
|
||||
thumbnail?: File | null;
|
||||
clear_thumbnail?: boolean;
|
||||
}
|
||||
|
||||
const buildProjectBody = (data: Partial<ProjectPayload> & { workspace?: string; name?: string }) => {
|
||||
const hasFile = data.thumbnail instanceof File;
|
||||
const shouldClear = Boolean(data.clear_thumbnail);
|
||||
if (!hasFile && !shouldClear) {
|
||||
return { body: JSON.stringify(data) };
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
Object.entries(data).forEach(([key, value]) => {
|
||||
if (value === undefined || value === null || key === "clear_thumbnail") return;
|
||||
if (key === "thumbnail" && value instanceof File) {
|
||||
formData.append(key, value);
|
||||
return;
|
||||
}
|
||||
formData.append(key, String(value));
|
||||
});
|
||||
if (shouldClear) formData.append("clear_thumbnail", "true");
|
||||
return { body: formData };
|
||||
};
|
||||
|
||||
export const getProjects = async (
|
||||
workspaceId: string,
|
||||
params: {
|
||||
@@ -101,9 +139,10 @@ export const getProject = async (id: string) => {
|
||||
export const createProject = async (
|
||||
data: Partial<ProjectPayload> & { workspace: string; name: string }
|
||||
) => {
|
||||
const requestBody = buildProjectBody(data);
|
||||
const response = await authFetch("/api/projects/", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
body: requestBody.body,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -119,9 +158,10 @@ export const updateProject = async (
|
||||
id: string,
|
||||
data: Partial<ProjectPayload>
|
||||
) => {
|
||||
const requestBody = buildProjectBody(data);
|
||||
const response = await authFetch(`/api/projects/${id}/`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(data),
|
||||
body: requestBody.body,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -199,3 +239,28 @@ export const grantProjectAccess = async (workspaceId: string, userId: string, pr
|
||||
|
||||
export const revokeProjectAccess = async (workspaceId: string, userId: string, projectIds: string[]) =>
|
||||
mutateProjectAccess("/api/projects/access/revoke/", workspaceId, userId, projectIds);
|
||||
|
||||
export const saveProjectAccessRate = async (
|
||||
workspaceId: string,
|
||||
userId: string,
|
||||
projectId: string,
|
||||
hourlyRate: string | null,
|
||||
currency: string,
|
||||
) => {
|
||||
const response = await authFetch("/api/projects/access/rate/", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
workspace: workspaceId,
|
||||
user: userId,
|
||||
project: projectId,
|
||||
hourly_rate: hourlyRate,
|
||||
currency,
|
||||
}),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => null);
|
||||
throw new Error(errorData?.detail || errorData?.message || "Failed to save project user rate");
|
||||
}
|
||||
invalidateApiCache(["projects", "reports"]);
|
||||
return response.json() as Promise<ProjectAccessRateMutationResponse>;
|
||||
};
|
||||
|
||||
@@ -30,6 +30,36 @@ export interface WorkspaceUserRate {
|
||||
effective_from: string;
|
||||
}
|
||||
|
||||
export interface WorkspaceProjectRateView {
|
||||
project: {
|
||||
id: string;
|
||||
name: string;
|
||||
client: { id: string; name: string } | null;
|
||||
};
|
||||
rate: {
|
||||
id: string;
|
||||
hourly_rate: string;
|
||||
currency: string;
|
||||
price_unit?: PriceUnit | null;
|
||||
effective_from: string | null;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MyWorkspaceRatesResponse {
|
||||
workspace: { id: string; name: string };
|
||||
workspace_rate: {
|
||||
id: string;
|
||||
hourly_rate: string;
|
||||
currency: string;
|
||||
price_unit?: PriceUnit | null;
|
||||
effective_from: string | null;
|
||||
} | null;
|
||||
accessible_project_count: number;
|
||||
project_override_count: number;
|
||||
workspace_fallback_project_count: number;
|
||||
project_rates: WorkspaceProjectRateView[];
|
||||
}
|
||||
|
||||
interface PaginatedResponse<T> {
|
||||
count: number;
|
||||
next: string | null;
|
||||
@@ -87,6 +117,15 @@ export const getWorkspaceUserRates = async (workspaceId: string) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const getMyWorkspaceRates = async (workspaceId: string) => {
|
||||
const response = await authFetch(`/api/workspaces/${workspaceId}/my-rates/`);
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => null);
|
||||
throw new Error(errorData?.detail || errorData?.message || "Failed to load your workspace rates");
|
||||
}
|
||||
return response.json() as Promise<MyWorkspaceRatesResponse>;
|
||||
};
|
||||
|
||||
export const createWorkspaceUserRate = async (data: {
|
||||
workspace_id: string;
|
||||
user_id: string;
|
||||
|
||||
@@ -90,7 +90,9 @@ export interface RatePeriodRow {
|
||||
amount: string;
|
||||
currency: string;
|
||||
from_date: string;
|
||||
to_date: string;
|
||||
to_date: string | null;
|
||||
project_name?: string | null;
|
||||
is_current?: boolean;
|
||||
}
|
||||
|
||||
export interface UserReportSummary {
|
||||
@@ -107,6 +109,9 @@ export interface UserReportSummary {
|
||||
project_percentages: PercentageRow[];
|
||||
client_percentages: PercentageRow[];
|
||||
tag_percentages: PercentageRow[];
|
||||
project_income_percentages: PercentageRow[];
|
||||
client_income_percentages: PercentageRow[];
|
||||
tag_income_percentages: PercentageRow[];
|
||||
}
|
||||
|
||||
export interface DayDetailEntry {
|
||||
@@ -143,8 +148,31 @@ export interface TableReportResponse {
|
||||
clients: BreakdownRow[];
|
||||
projects: BreakdownRow[];
|
||||
tags: BreakdownRow[];
|
||||
client_percentages?: PercentageRow[];
|
||||
project_percentages?: PercentageRow[];
|
||||
tag_percentages?: PercentageRow[];
|
||||
client_income_percentages?: PercentageRow[];
|
||||
project_income_percentages?: PercentageRow[];
|
||||
tag_income_percentages?: PercentageRow[];
|
||||
user_summary?: UserReportSummary;
|
||||
user_summaries?: UserReportSummary[];
|
||||
per_user_reports?: UserScopedTableReport[];
|
||||
}
|
||||
|
||||
export interface UserScopedTableReport {
|
||||
scope: ReportScope;
|
||||
summary: ReportSummary;
|
||||
days: DailyReportRow[];
|
||||
clients: BreakdownRow[];
|
||||
projects: BreakdownRow[];
|
||||
tags: BreakdownRow[];
|
||||
client_percentages?: PercentageRow[];
|
||||
project_percentages?: PercentageRow[];
|
||||
tag_percentages?: PercentageRow[];
|
||||
client_income_percentages?: PercentageRow[];
|
||||
project_income_percentages?: PercentageRow[];
|
||||
tag_income_percentages?: PercentageRow[];
|
||||
user_summary: UserReportSummary;
|
||||
}
|
||||
|
||||
export interface ReportExportJob {
|
||||
@@ -211,6 +239,17 @@ export const getDayDetailsReport = async (
|
||||
});
|
||||
};
|
||||
|
||||
export const getUserSummaryReport = async (
|
||||
filters: ReportFilters,
|
||||
userId: string,
|
||||
): Promise<UserScopedTableReport> => {
|
||||
const query = `${toQueryString({ ...filters, user: userId })}`;
|
||||
return cachedGetJson(`/api/reports/user-summary/?${query}`, {
|
||||
ttlMs: 60 * 1000,
|
||||
namespaces: ["reports"],
|
||||
});
|
||||
};
|
||||
|
||||
export const createReportExport = async (
|
||||
filters: ReportFilters,
|
||||
exportType: "excel" | "pdf",
|
||||
|
||||
@@ -23,7 +23,10 @@ export interface TimeEntry {
|
||||
project_details: TimeEntryProjectDetails | null;
|
||||
description: string;
|
||||
start_time: string;
|
||||
start_time_ms: number;
|
||||
end_time: string | null;
|
||||
end_time_ms: number | null;
|
||||
server_now_ms: number;
|
||||
duration: string | null;
|
||||
tags: string[];
|
||||
tag_details: TimeEntryTagDetails[];
|
||||
@@ -56,6 +59,8 @@ interface GroupedTimeEntryResponse {
|
||||
offset: number;
|
||||
next_offset: number | null;
|
||||
has_more: boolean;
|
||||
server_now_ms: number;
|
||||
server_now: string;
|
||||
groups: TimeEntryGroupWeek[];
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,47 @@ export interface WorkspaceMembership {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface WorkspaceMemberImportRowInput {
|
||||
line: number;
|
||||
mobile: string;
|
||||
role?: "admin" | "member" | "guest";
|
||||
hourly_rate?: string;
|
||||
currency?: string;
|
||||
}
|
||||
|
||||
export interface WorkspaceMemberImportResultRow {
|
||||
line: number | null;
|
||||
mobile: string;
|
||||
role: "admin" | "member" | "guest" | "owner" | string;
|
||||
hourly_rate: string;
|
||||
currency: string;
|
||||
status: "valid" | "invalid";
|
||||
action: "add_member" | "none" | string;
|
||||
user: {
|
||||
id: string;
|
||||
full_name: string;
|
||||
mobile: string;
|
||||
} | null;
|
||||
messages: string[];
|
||||
}
|
||||
|
||||
export interface WorkspaceMemberImportValidationResponse {
|
||||
can_commit: boolean;
|
||||
import_token: string | null;
|
||||
summary: {
|
||||
total: number;
|
||||
valid: number;
|
||||
invalid: number;
|
||||
};
|
||||
rows: WorkspaceMemberImportResultRow[];
|
||||
}
|
||||
|
||||
export interface WorkspaceMemberImportCommitResponse {
|
||||
created_memberships: number;
|
||||
created_or_updated_rates: number;
|
||||
memberships: WorkspaceMembership[];
|
||||
}
|
||||
|
||||
|
||||
type QueryValue = string | number | boolean | undefined | null;
|
||||
|
||||
@@ -225,3 +266,36 @@ export const updateWorkspaceMembership = async (membershipId: string | number, d
|
||||
invalidateApiCache(["workspace-memberships", "reports"]);
|
||||
return payload;
|
||||
};
|
||||
|
||||
export const validateWorkspaceMemberImport = async (data: {
|
||||
workspace: string;
|
||||
rows: WorkspaceMemberImportRowInput[];
|
||||
}): Promise<WorkspaceMemberImportValidationResponse> => {
|
||||
const response = await authFetch("/api/workspace-memberships/import/validate/", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
const payload = await response.json().catch(() => null);
|
||||
if (!response.ok) {
|
||||
throw new Error(payload?.detail || payload?.message || "Failed to validate member import");
|
||||
}
|
||||
return payload;
|
||||
};
|
||||
|
||||
export const commitWorkspaceMemberImport = async (data: {
|
||||
workspace: string;
|
||||
import_token: string;
|
||||
}): Promise<WorkspaceMemberImportCommitResponse> => {
|
||||
const response = await authFetch("/api/workspace-memberships/import/commit/", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
const payload = await response.json().catch(() => null);
|
||||
if (!response.ok) {
|
||||
throw new Error(payload?.detail || payload?.message || "Failed to import workspace members");
|
||||
}
|
||||
invalidateApiCache(["workspace-memberships", "workspace-rates", "reports"]);
|
||||
return payload;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState, type FormEvent } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { createClient } from "../api/clients";
|
||||
import { useTranslation } from "../hooks/useTranslation";
|
||||
@@ -18,17 +18,47 @@ export default function CreateClientModal({ isOpen, onClose, onSuccess, workspac
|
||||
const { t } = useTranslation();
|
||||
const [name, setName] = useState("");
|
||||
const [notes, setNotes] = useState("");
|
||||
const [thumbnailFile, setThumbnailFile] = useState<File | null>(null);
|
||||
const [thumbnailPreview, setThumbnailPreview] = useState<string | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
useEffect(() => {
|
||||
if (!thumbnailFile) {
|
||||
setThumbnailPreview(null);
|
||||
return;
|
||||
}
|
||||
const objectUrl = URL.createObjectURL(thumbnailFile);
|
||||
setThumbnailPreview(objectUrl);
|
||||
return () => URL.revokeObjectURL(objectUrl);
|
||||
}, [thumbnailFile]);
|
||||
|
||||
const handleThumbnailChange = (file: File | null) => {
|
||||
if (!file) {
|
||||
setThumbnailFile(null);
|
||||
return;
|
||||
}
|
||||
if (!["image/jpeg", "image/png", "image/webp"].includes(file.type)) {
|
||||
toast.error(t.workspace?.thumbnailInvalidType || "Unsupported image type. Use JPG, PNG, or WebP.");
|
||||
return;
|
||||
}
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
toast.error(t.workspace?.thumbnailMaxSizeError || "Image size must be 2MB or less.");
|
||||
return;
|
||||
}
|
||||
setThumbnailFile(file);
|
||||
};
|
||||
|
||||
const handleSubmit = async (event?: FormEvent<HTMLFormElement>) => {
|
||||
event?.preventDefault();
|
||||
if (!name.trim()) return;
|
||||
setIsLoading(true);
|
||||
try {
|
||||
await createClient(workspaceId, { name, notes });
|
||||
await createClient(workspaceId, { name, notes, thumbnail: thumbnailFile });
|
||||
toast.success(t.clients.createSuccess);
|
||||
onSuccess();
|
||||
setName("");
|
||||
setNotes("");
|
||||
setThumbnailFile(null);
|
||||
onClose();
|
||||
} catch (error) {
|
||||
console.error(t.clients.errors.createFailed, error);
|
||||
@@ -43,7 +73,7 @@ export default function CreateClientModal({ isOpen, onClose, onSuccess, workspac
|
||||
<Button variant="outline" onClick={onClose} disabled={isLoading}>
|
||||
{t.actions?.cancel}
|
||||
</Button>
|
||||
<Button onClick={handleSubmit} disabled={isLoading || !name.trim()}>
|
||||
<Button type="submit" form="create-client-form" disabled={isLoading || !name.trim()}>
|
||||
{isLoading ? "..." : t.clients.create}
|
||||
</Button>
|
||||
</>
|
||||
@@ -51,7 +81,23 @@ export default function CreateClientModal({ isOpen, onClose, onSuccess, workspac
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={onClose} title={t.clients.modalTitle} footer={footer}>
|
||||
<div className="space-y-4">
|
||||
<form id="create-client-form" onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1 text-slate-700 dark:text-slate-300">
|
||||
{t.workspace?.thumbnailLabel || "Thumbnail"}
|
||||
</label>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded-2xl bg-slate-100 text-sm font-semibold text-slate-700 dark:bg-slate-800 dark:text-slate-200">
|
||||
{thumbnailPreview ? <img src={thumbnailPreview} alt="" className="h-full w-full object-cover" /> : name.trim().charAt(0).toUpperCase() || "C"}
|
||||
</div>
|
||||
<Input type="file" accept="image/jpeg,image/png,image/webp" onChange={(event) => handleThumbnailChange(event.target.files?.[0] || null)} />
|
||||
{thumbnailFile ? (
|
||||
<Button type="button" variant="outline" onClick={() => setThumbnailFile(null)}>
|
||||
{t.remove || "Remove"}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1 text-slate-700 dark:text-slate-300">
|
||||
{t.clients.clientName}
|
||||
@@ -72,7 +118,7 @@ export default function CreateClientModal({ isOpen, onClose, onSuccess, workspac
|
||||
placeholder={t.clients.notesPlaceholder}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { type Client } from "../types/client";
|
||||
import { deleteClient } from "../api/clients";
|
||||
@@ -17,7 +17,8 @@ export default function DeleteClientModal({ isOpen, onClose, onSuccess, client }
|
||||
const { t } = useTranslation();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const handleDelete = async () => {
|
||||
const handleDelete = async (event?: FormEvent<HTMLFormElement>) => {
|
||||
event?.preventDefault();
|
||||
if (!client) return;
|
||||
setIsLoading(true);
|
||||
try {
|
||||
@@ -39,8 +40,9 @@ export default function DeleteClientModal({ isOpen, onClose, onSuccess, client }
|
||||
{t.actions?.cancel}
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
form="delete-client-form"
|
||||
variant="destructive"
|
||||
onClick={handleDelete}
|
||||
disabled={isLoading}
|
||||
>
|
||||
{isLoading ? "..." : t.clients.delete}
|
||||
@@ -56,9 +58,11 @@ export default function DeleteClientModal({ isOpen, onClose, onSuccess, client }
|
||||
footer={footer}
|
||||
maxWidth="max-w-sm"
|
||||
>
|
||||
<form id="delete-client-form" onSubmit={handleDelete}>
|
||||
<p className="text-slate-500 dark:text-slate-400">
|
||||
{client ? t.clients.deleteConfirmMessage(client.name) : ""}
|
||||
</p>
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useState, useEffect, type FormEvent } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { type Client } from "../types/client";
|
||||
import { updateClient } from "../api/clients";
|
||||
@@ -19,20 +19,52 @@ export default function EditClientModal({ isOpen, onClose, onSuccess, client }:
|
||||
const { t } = useTranslation();
|
||||
const [name, setName] = useState("");
|
||||
const [notes, setNotes] = useState("");
|
||||
const [thumbnailFile, setThumbnailFile] = useState<File | null>(null);
|
||||
const [thumbnailUrl, setThumbnailUrl] = useState<string | null>(null);
|
||||
const [thumbnailPreview, setThumbnailPreview] = useState<string | null>(null);
|
||||
const [clearThumbnail, setClearThumbnail] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (client) {
|
||||
setName(client.name);
|
||||
setNotes(client.notes || "");
|
||||
setThumbnailUrl(client.thumbnail || null);
|
||||
setThumbnailFile(null);
|
||||
setClearThumbnail(false);
|
||||
}
|
||||
}, [client]);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
useEffect(() => {
|
||||
if (!thumbnailFile) {
|
||||
setThumbnailPreview(null);
|
||||
return;
|
||||
}
|
||||
const objectUrl = URL.createObjectURL(thumbnailFile);
|
||||
setThumbnailPreview(objectUrl);
|
||||
return () => URL.revokeObjectURL(objectUrl);
|
||||
}, [thumbnailFile]);
|
||||
|
||||
const handleThumbnailChange = (file: File | null) => {
|
||||
if (!file) return;
|
||||
if (!["image/jpeg", "image/png", "image/webp"].includes(file.type)) {
|
||||
toast.error(t.workspace?.thumbnailInvalidType || "Unsupported image type. Use JPG, PNG, or WebP.");
|
||||
return;
|
||||
}
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
toast.error(t.workspace?.thumbnailMaxSizeError || "Image size must be 2MB or less.");
|
||||
return;
|
||||
}
|
||||
setThumbnailFile(file);
|
||||
setClearThumbnail(false);
|
||||
};
|
||||
|
||||
const handleSubmit = async (event?: FormEvent<HTMLFormElement>) => {
|
||||
event?.preventDefault();
|
||||
if (!client || !name.trim()) return;
|
||||
setIsLoading(true);
|
||||
try {
|
||||
await updateClient(client.id, { name, notes });
|
||||
await updateClient(client.id, { name, notes, thumbnail: thumbnailFile, clear_thumbnail: clearThumbnail });
|
||||
toast.success(t.clients.updateSuccess);
|
||||
onSuccess();
|
||||
onClose();
|
||||
@@ -49,7 +81,7 @@ export default function EditClientModal({ isOpen, onClose, onSuccess, client }:
|
||||
<Button variant="outline" onClick={onClose} disabled={isLoading}>
|
||||
{t.actions?.cancel}
|
||||
</Button>
|
||||
<Button onClick={handleSubmit} disabled={isLoading || !name.trim()}>
|
||||
<Button type="submit" form="edit-client-form" disabled={isLoading || !name.trim()}>
|
||||
{isLoading ? "..." : t.clients.saveChanges}
|
||||
</Button>
|
||||
</>
|
||||
@@ -57,7 +89,36 @@ export default function EditClientModal({ isOpen, onClose, onSuccess, client }:
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={onClose} title={t.clients.editClient} footer={footer}>
|
||||
<div className="space-y-4">
|
||||
<form id="edit-client-form" onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1 text-slate-700 dark:text-slate-300">
|
||||
{t.workspace?.thumbnailLabel || "Thumbnail"}
|
||||
</label>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded-2xl bg-slate-100 text-sm font-semibold text-slate-700 dark:bg-slate-800 dark:text-slate-200">
|
||||
{thumbnailPreview ? (
|
||||
<img src={thumbnailPreview} alt="" className="h-full w-full object-cover" />
|
||||
) : !clearThumbnail && thumbnailUrl ? (
|
||||
<img src={thumbnailUrl} alt="" className="h-full w-full object-cover" />
|
||||
) : (
|
||||
name.trim().charAt(0).toUpperCase() || "C"
|
||||
)}
|
||||
</div>
|
||||
<Input type="file" accept="image/jpeg,image/png,image/webp" onChange={(event) => handleThumbnailChange(event.target.files?.[0] || null)} />
|
||||
{(thumbnailFile || (!clearThumbnail && thumbnailUrl)) ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setThumbnailFile(null);
|
||||
setClearThumbnail(true);
|
||||
}}
|
||||
>
|
||||
{t.remove || "Remove"}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1 text-slate-700 dark:text-slate-300">
|
||||
{t.clients.clientName}
|
||||
@@ -78,7 +139,7 @@ export default function EditClientModal({ isOpen, onClose, onSuccess, client }:
|
||||
placeholder={t.clients.notesPlaceholder}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect } from "react";
|
||||
import React, { useEffect, useRef } from "react";
|
||||
import { X } from "lucide-react";
|
||||
import { Card } from "./ui/card";
|
||||
import { Button } from "./ui/button";
|
||||
@@ -23,15 +23,43 @@ export const Modal: React.FC<ModalProps> = ({
|
||||
footer,
|
||||
maxWidth = "max-w-lg",
|
||||
}) => {
|
||||
const cardRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
|
||||
if (isOpen) {
|
||||
document.body.style.overflow = "hidden";
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
} else {
|
||||
document.body.style.overflow = "unset";
|
||||
}
|
||||
return () => {
|
||||
document.body.style.overflow = "unset";
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
};
|
||||
}, [isOpen, onClose]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
|
||||
const focusTimer = window.setTimeout(() => {
|
||||
const activeElement = document.activeElement;
|
||||
if (activeElement instanceof HTMLElement && cardRef.current?.contains(activeElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const firstTextInput = cardRef.current?.querySelector<HTMLElement>(
|
||||
'input:not([type]), input[type="text"], input[type="search"], input[type="email"], input[type="tel"], input[type="password"], input[type="number"], textarea',
|
||||
);
|
||||
firstTextInput?.focus();
|
||||
}, 0);
|
||||
|
||||
return () => window.clearTimeout(focusTimer);
|
||||
}, [isOpen]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
@@ -42,6 +70,7 @@ export const Modal: React.FC<ModalProps> = ({
|
||||
onClick={onClose}
|
||||
>
|
||||
<Card
|
||||
ref={cardRef}
|
||||
className={`flex max-h-[calc(100vh-2rem)] w-full flex-col ${maxWidth} bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-100 border-0 shadow-xl overflow-hidden rounded-2xl`}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
|
||||
@@ -3,13 +3,14 @@ import { useNavigate } from "react-router-dom"
|
||||
import { useTranslation } from "../hooks/useTranslation"
|
||||
import { Button } from "./ui/button"
|
||||
import { SettingsMenu } from "./SettingsMenu"
|
||||
import { LogOut, User, Moon, Sun, Globe, Command, Menu } from "lucide-react"
|
||||
import { FlaskConical, LogOut, User, Moon, Sun, Globe, Command, Menu, RefreshCcw } from "lucide-react"
|
||||
import { useTheme } from "./ThemeProvider"
|
||||
import { logoutUser, getUserProfile } from "../api/users"
|
||||
import { WorkspaceSelector } from "./WorkspaceSelector"
|
||||
import { toast } from "sonner"
|
||||
import { NotificationBell } from "./notifications/NotificationBell"
|
||||
import { clearSessionTokens, getAccessToken, getRefreshToken } from "../lib/session"
|
||||
import { clearSessionTokens, getAccessToken, getRefreshToken, setDemoSessionMeta, setSessionTokens } from "../lib/session"
|
||||
import { startDemo } from "../api/demo"
|
||||
|
||||
type NavbarProps = {
|
||||
onOpenSidebar?: () => void
|
||||
@@ -22,6 +23,7 @@ export function Navbar({ onOpenSidebar }: NavbarProps) {
|
||||
|
||||
const [showLogoutModal, setShowLogoutModal] = useState(false)
|
||||
const [isDropdownOpen, setIsDropdownOpen] = useState(false)
|
||||
const [isResettingDemo, setIsResettingDemo] = useState(false)
|
||||
const [user, setUser] = useState<any>(null)
|
||||
|
||||
const dropdownRef = useRef<HTMLDivElement>(null)
|
||||
@@ -30,6 +32,13 @@ export function Navbar({ onOpenSidebar }: NavbarProps) {
|
||||
const isDarkMode =
|
||||
theme === "dark" ||
|
||||
(theme === "system" && document.documentElement.classList.contains("dark"))
|
||||
const isDemoUser = Boolean(user?.is_demo)
|
||||
const demoExpiryLabel = user?.demo_expires_at
|
||||
? new Intl.DateTimeFormat(isFa ? "fa-IR" : "en-US", {
|
||||
dateStyle: "medium",
|
||||
timeStyle: "short",
|
||||
}).format(new Date(user.demo_expires_at))
|
||||
: null
|
||||
|
||||
useEffect(() => {
|
||||
const handleProfileUpdated = ((e: CustomEvent) => {
|
||||
@@ -86,6 +95,23 @@ export function Navbar({ onOpenSidebar }: NavbarProps) {
|
||||
}
|
||||
}
|
||||
|
||||
const handleResetDemo = async () => {
|
||||
if (isResettingDemo) return
|
||||
setIsResettingDemo(true)
|
||||
try {
|
||||
const demo = await startDemo()
|
||||
setSessionTokens(demo.access, demo.refresh)
|
||||
setDemoSessionMeta(demo.expires_at)
|
||||
toast.success(t.demo?.reset || "Fresh demo environment is ready.")
|
||||
window.location.href = "/timesheet"
|
||||
} catch (error) {
|
||||
console.error("Demo reset failed:", error)
|
||||
toast.error(t.demo?.startError || "Could not start the demo environment.")
|
||||
} finally {
|
||||
setIsResettingDemo(false)
|
||||
}
|
||||
}
|
||||
|
||||
const toggleTheme = () => {
|
||||
setTheme(isDarkMode ? "light" : "dark")
|
||||
}
|
||||
@@ -142,6 +168,12 @@ export function Navbar({ onOpenSidebar }: NavbarProps) {
|
||||
{/* Desktop navbar: keep the old controls here */}
|
||||
<div className="hidden items-center gap-4 md:flex">
|
||||
{user && <WorkspaceSelector />}
|
||||
{isDemoUser && (
|
||||
<div className="inline-flex items-center gap-2 rounded-full border border-cyan-200 bg-cyan-50 px-3 py-2 text-xs font-semibold text-cyan-800 dark:border-cyan-500/20 dark:bg-cyan-500/10 dark:text-cyan-100">
|
||||
<FlaskConical className="h-4 w-4" />
|
||||
<span>{t.demo?.badge || "Demo environment"}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{user ? (
|
||||
<>
|
||||
@@ -178,8 +210,24 @@ export function Navbar({ onOpenSidebar }: NavbarProps) {
|
||||
? `${user.first_name || ""} ${user.last_name || ""}`.trim()
|
||||
: user.email}
|
||||
</p>
|
||||
{isDemoUser && demoExpiryLabel && (
|
||||
<p className="mt-1 text-xs text-cyan-700 dark:text-cyan-300">
|
||||
{(t.demo?.expiresAt || "Expires at")}: {demoExpiryLabel}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isDemoUser && (
|
||||
<button
|
||||
onClick={handleResetDemo}
|
||||
disabled={isResettingDemo}
|
||||
className="flex w-full items-center gap-3 px-4 py-2.5 text-sm text-cyan-700 transition-colors hover:bg-cyan-50 disabled:cursor-not-allowed disabled:opacity-70 dark:text-cyan-300 dark:hover:bg-cyan-950/40"
|
||||
>
|
||||
<RefreshCcw className="h-4 w-4" />
|
||||
<span>{isResettingDemo ? t.demo?.starting || "Preparing demo..." : t.demo?.resetAction || "Reset demo"}</span>
|
||||
</button>
|
||||
)}
|
||||
|
||||
<button
|
||||
onClick={() => {
|
||||
navigate("/profile")
|
||||
|
||||
@@ -63,8 +63,8 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
}, [currentPage, totalPages]);
|
||||
|
||||
return (
|
||||
<div className="sticky bottom-0 left-0 right-0 z-10 mt-auto -mx-4 border-t border-slate-200/80 bg-white/90 px-4 py-4 backdrop-blur-xl dark:border-slate-800/80 dark:bg-slate-950/90 sm:mx-0 sm:rounded-3xl sm:border sm:px-5">
|
||||
<div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
|
||||
<div className="sticky bottom-0 left-0 right-0 z-10 mt-auto -mx-4 border-t border-slate-200/80 bg-white/95 px-4 py-3 shadow-[0_-10px_30px_rgba(15,23,42,0.06)] backdrop-blur-xl dark:border-slate-800/80 dark:bg-slate-950/95 dark:shadow-[0_-10px_30px_rgba(0,0,0,0.24)] md:-mx-6 md:px-6">
|
||||
<div className="mx-auto flex w-full max-w-7xl gap-3 flex-row items-center justify-between">
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between lg:justify-start">
|
||||
<div className="flex items-center gap-3">
|
||||
<Select
|
||||
@@ -78,9 +78,9 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
label: String(toPersianNum(option)),
|
||||
}))}
|
||||
className="w-24 shrink-0"
|
||||
buttonClassName="h-10 rounded-2xl border-slate-200 bg-slate-50 font-medium text-slate-700 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200"
|
||||
buttonClassName="h-9 rounded-lg border-slate-200 bg-slate-50 font-medium text-slate-700 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200"
|
||||
/>
|
||||
<span className="inline-flex h-10 items-center rounded-2xl border border-slate-200 bg-slate-50 px-4 text-sm font-medium text-slate-600 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300 sm:hidden">
|
||||
<span className="inline-flex h-9 items-center rounded-lg border border-slate-200 bg-slate-50 px-3 text-sm font-medium text-slate-600 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300 sm:hidden">
|
||||
{toPersianNum(currentPage)} / {toPersianNum(totalPages)}
|
||||
</span>
|
||||
</div>
|
||||
@@ -98,7 +98,7 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
type="button"
|
||||
onClick={() => onPageChange(pageItem)}
|
||||
className={cn(
|
||||
'inline-flex h-10 min-w-10 items-center justify-center rounded-2xl border px-3 text-sm font-semibold transition-colors',
|
||||
'inline-flex h-9 min-w-9 items-center justify-center rounded-lg border px-3 text-sm font-semibold transition-colors',
|
||||
pageItem === currentPage
|
||||
? 'border-sky-500 bg-sky-500 text-white shadow-sm'
|
||||
: 'border-slate-200 bg-slate-50 text-slate-600 hover:border-slate-300 hover:bg-slate-100 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300 dark:hover:border-slate-600 dark:hover:bg-slate-800',
|
||||
@@ -109,7 +109,7 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
) : (
|
||||
<span
|
||||
key={`${pageItem}-${index}`}
|
||||
className="inline-flex h-10 min-w-10 items-center justify-center rounded-2xl text-slate-400 dark:text-slate-500"
|
||||
className="inline-flex h-9 min-w-9 items-center justify-center rounded-lg text-slate-400 dark:text-slate-500"
|
||||
>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</span>
|
||||
@@ -123,7 +123,7 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
size="sm"
|
||||
onClick={() => onPageChange(currentPage - 1)}
|
||||
disabled={currentPage === 1}
|
||||
className="h-10 rounded-2xl border-slate-200 bg-slate-50 px-4 text-slate-700 hover:bg-slate-100 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200 dark:hover:bg-slate-800"
|
||||
className="h-9 rounded-lg border-slate-200 bg-slate-50 px-3 text-slate-700 hover:bg-slate-100 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200 dark:hover:bg-slate-800"
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4 rtl:rotate-180" />
|
||||
{t.pagination?.previous || 'Previous'}
|
||||
@@ -138,7 +138,7 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
size="sm"
|
||||
onClick={() => onPageChange(currentPage + 1)}
|
||||
disabled={currentPage >= totalPages}
|
||||
className="h-10 rounded-2xl border-slate-200 bg-slate-50 px-4 text-slate-700 hover:bg-slate-100 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200 dark:hover:bg-slate-800"
|
||||
className="h-9 rounded-lg border-slate-200 bg-slate-50 px-3 text-slate-700 hover:bg-slate-100 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200 dark:hover:bg-slate-800"
|
||||
>
|
||||
{t.pagination?.next || 'Next'}
|
||||
<ChevronRight className="h-4 w-4 rtl:rotate-180" />
|
||||
|
||||
@@ -17,6 +17,8 @@ import {
|
||||
Globe,
|
||||
LogOut,
|
||||
LogIn,
|
||||
FlaskConical,
|
||||
RefreshCcw,
|
||||
} from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
@@ -27,7 +29,8 @@ import { WorkspaceSelector } from "./WorkspaceSelector"
|
||||
import { SettingsMenu } from "./SettingsMenu"
|
||||
import { Button } from "./ui/button"
|
||||
import { getUserProfile, logoutUser } from "../api/users"
|
||||
import { clearSessionTokens, getAccessToken, getRefreshToken } from "../lib/session"
|
||||
import { clearSessionTokens, getAccessToken, getRefreshToken, setDemoSessionMeta, setSessionTokens } from "../lib/session"
|
||||
import { startDemo } from "../api/demo"
|
||||
|
||||
type SidebarProps = {
|
||||
mobileOpen?: boolean
|
||||
@@ -37,6 +40,7 @@ type SidebarProps = {
|
||||
export const Sidebar = ({ mobileOpen = false, onMobileClose }: SidebarProps) => {
|
||||
const [isCollapsed, setIsCollapsed] = useState(false)
|
||||
const [showLogoutModal, setShowLogoutModal] = useState(false)
|
||||
const [isResettingDemo, setIsResettingDemo] = useState(false)
|
||||
const [user, setUser] = useState<any>(null)
|
||||
|
||||
const navigate = useNavigate()
|
||||
@@ -47,6 +51,13 @@ export const Sidebar = ({ mobileOpen = false, onMobileClose }: SidebarProps) =>
|
||||
|
||||
const isRtl = lang === "fa"
|
||||
const canViewLogs = canWorkspace(activeWorkspace?.my_role, WORKSPACE_LOGS_VIEW)
|
||||
const isDemoUser = Boolean(user?.is_demo)
|
||||
const demoExpiryLabel = user?.demo_expires_at
|
||||
? new Intl.DateTimeFormat(isRtl ? "fa-IR" : "en-US", {
|
||||
dateStyle: "medium",
|
||||
timeStyle: "short",
|
||||
}).format(new Date(user.demo_expires_at))
|
||||
: null
|
||||
|
||||
const ToggleIcon = isRtl
|
||||
? isCollapsed
|
||||
@@ -101,6 +112,23 @@ export const Sidebar = ({ mobileOpen = false, onMobileClose }: SidebarProps) =>
|
||||
}
|
||||
}
|
||||
|
||||
const handleResetDemo = async () => {
|
||||
if (isResettingDemo) return
|
||||
setIsResettingDemo(true)
|
||||
try {
|
||||
const demo = await startDemo()
|
||||
setSessionTokens(demo.access, demo.refresh)
|
||||
setDemoSessionMeta(demo.expires_at)
|
||||
toast.success(t.demo?.reset || "Fresh demo environment is ready.")
|
||||
window.location.href = "/timesheet"
|
||||
} catch (error) {
|
||||
console.error("Demo reset failed:", error)
|
||||
toast.error(t.demo?.startError || "Could not start the demo environment.")
|
||||
} finally {
|
||||
setIsResettingDemo(false)
|
||||
}
|
||||
}
|
||||
|
||||
const toggleLanguage = () => {
|
||||
const newLang = isRtl ? "en" : "fa"
|
||||
|
||||
@@ -199,6 +227,19 @@ export const Sidebar = ({ mobileOpen = false, onMobileClose }: SidebarProps) =>
|
||||
<div className="w-full">
|
||||
<WorkspaceSelector className="w-full" />
|
||||
</div>
|
||||
{isDemoUser && (
|
||||
<div className="mt-3 rounded-2xl border border-cyan-200 bg-cyan-50 p-3 text-xs font-medium text-cyan-800 dark:border-cyan-500/20 dark:bg-cyan-500/10 dark:text-cyan-100">
|
||||
<div className="flex items-center gap-2 font-semibold">
|
||||
<FlaskConical className="h-4 w-4" />
|
||||
{t.demo?.badge || "Demo environment"}
|
||||
</div>
|
||||
{demoExpiryLabel && (
|
||||
<div className="mt-1 text-cyan-700 dark:text-cyan-300">
|
||||
{(t.demo?.expiresAt || "Expires at")}: {demoExpiryLabel}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -256,6 +297,19 @@ export const Sidebar = ({ mobileOpen = false, onMobileClose }: SidebarProps) =>
|
||||
</span>
|
||||
</button>
|
||||
|
||||
{isDemoUser && (
|
||||
<button
|
||||
onClick={handleResetDemo}
|
||||
disabled={isResettingDemo}
|
||||
className="flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm font-medium text-cyan-700 transition-colors hover:bg-cyan-50 disabled:cursor-not-allowed disabled:opacity-70 dark:text-cyan-300 dark:hover:bg-cyan-950/40"
|
||||
>
|
||||
<RefreshCcw size={20} className="shrink-0" />
|
||||
<span className="truncate whitespace-nowrap">
|
||||
{isResettingDemo ? t.demo?.starting || "Preparing demo..." : t.demo?.resetAction || "Reset demo"}
|
||||
</span>
|
||||
</button>
|
||||
)}
|
||||
|
||||
<button
|
||||
onClick={() => setShowLogoutModal(true)}
|
||||
className="flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm font-medium text-red-600 transition-colors hover:bg-red-50 dark:text-red-500 dark:hover:bg-red-950/50"
|
||||
@@ -300,6 +354,28 @@ export const Sidebar = ({ mobileOpen = false, onMobileClose }: SidebarProps) =>
|
||||
</div>
|
||||
|
||||
<nav className="flex-1 space-y-1 overflow-y-auto overflow-x-hidden p-4">
|
||||
{isDemoUser && !isCollapsed && (
|
||||
<div className="mb-3 rounded-2xl border border-cyan-200 bg-cyan-50 p-3 text-xs font-medium text-cyan-800 dark:border-cyan-500/20 dark:bg-cyan-500/10 dark:text-cyan-100">
|
||||
<div className="flex items-center gap-2 font-semibold">
|
||||
<FlaskConical className="h-4 w-4" />
|
||||
{t.demo?.badge || "Demo environment"}
|
||||
</div>
|
||||
{demoExpiryLabel && (
|
||||
<div className="mt-1 text-cyan-700 dark:text-cyan-300">
|
||||
{(t.demo?.expiresAt || "Expires at")}: {demoExpiryLabel}
|
||||
</div>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleResetDemo}
|
||||
disabled={isResettingDemo}
|
||||
className="mt-2 inline-flex items-center gap-2 rounded-full bg-cyan-600 px-3 py-1.5 text-white transition hover:bg-cyan-700 disabled:cursor-not-allowed disabled:opacity-70 dark:bg-cyan-400 dark:text-slate-950 dark:hover:bg-cyan-300"
|
||||
>
|
||||
<RefreshCcw className="h-3.5 w-3.5" />
|
||||
{isResettingDemo ? t.demo?.starting || "Preparing demo..." : t.demo?.resetAction || "Reset demo"}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{renderNavItems(false)}
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
@@ -20,9 +20,14 @@ import {
|
||||
getProjectAccessState,
|
||||
grantProjectAccess,
|
||||
revokeProjectAccess,
|
||||
saveProjectAccessRate,
|
||||
type ProjectAccessItem,
|
||||
type ProjectAccessRateValue,
|
||||
} from "../../api/projects";
|
||||
import { getPriceUnits, type PriceUnit } from "../../api/rates";
|
||||
import { fetchWorkspaceMemberships, type WorkspaceMembership } from "../../api/workspaces";
|
||||
import { useTranslation } from "../../hooks/useTranslation";
|
||||
import { formatRateDisplay } from "../../lib/money";
|
||||
import { Modal } from "../Modal";
|
||||
import { Button } from "../ui/button";
|
||||
import { Input } from "../ui/input";
|
||||
@@ -53,9 +58,24 @@ type Labels = {
|
||||
accessOff: string;
|
||||
loadError: string;
|
||||
saveError: string;
|
||||
workspaceRate: string;
|
||||
projectOverride: string;
|
||||
inheritsWorkspaceRate: string;
|
||||
noRate: string;
|
||||
hourlyRatePlaceholder: string;
|
||||
currencyPlaceholder: string;
|
||||
removeRate: string;
|
||||
projectRateSaved: string;
|
||||
projectRateRemoved: string;
|
||||
projectRateSaveError: string;
|
||||
projectRateRemoveError: string;
|
||||
implicitAccessHint: string;
|
||||
};
|
||||
|
||||
const MANAGEABLE_ROLES = new Set(["member", "guest"]);
|
||||
type RateDraft = {
|
||||
hourlyRate: string;
|
||||
currency: string;
|
||||
};
|
||||
|
||||
function getMemberName(member: WorkspaceMembership) {
|
||||
return (
|
||||
@@ -66,6 +86,25 @@ function getMemberName(member: WorkspaceMembership) {
|
||||
);
|
||||
}
|
||||
|
||||
function getPreferredCurrency(
|
||||
item: Pick<ProjectAccessItem, "project_rate" | "workspace_rate">,
|
||||
defaultCurrency: string,
|
||||
) {
|
||||
return item.project_rate?.currency || item.workspace_rate?.currency || defaultCurrency;
|
||||
}
|
||||
|
||||
function getDraftFromItem(item: ProjectAccessItem, defaultCurrency: string): RateDraft {
|
||||
return {
|
||||
hourlyRate: item.project_rate?.hourly_rate || "",
|
||||
currency: getPreferredCurrency(item, defaultCurrency),
|
||||
};
|
||||
}
|
||||
|
||||
function formatRate(rate: ProjectAccessRateValue | null, labels: Labels, lang: "en" | "fa") {
|
||||
if (!rate) return labels.noRate;
|
||||
return formatRateDisplay(rate, lang);
|
||||
}
|
||||
|
||||
export function ProjectAccessModal({
|
||||
isOpen,
|
||||
onClose,
|
||||
@@ -89,19 +128,26 @@ export function ProjectAccessModal({
|
||||
const [selectedClientId, setSelectedClientId] = useState("");
|
||||
const [selectedProjectIds, setSelectedProjectIds] = useState<string[]>([]);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [savingRateProjectId, setSavingRateProjectId] = useState<string | null>(null);
|
||||
const [priceUnits, setPriceUnits] = useState<PriceUnit[]>([]);
|
||||
const [rateDrafts, setRateDrafts] = useState<Record<string, RateDraft>>({});
|
||||
const [selectedUserRole, setSelectedUserRole] = useState<"owner" | "admin" | "member" | "guest" | "">("");
|
||||
const { lang } = useTranslation();
|
||||
const isRtl =
|
||||
typeof document !== "undefined" && document.documentElement.dir === "rtl";
|
||||
|
||||
const manageableMembers = useMemo(
|
||||
() => members.filter((member) => member.is_active && MANAGEABLE_ROLES.has(member.role)),
|
||||
const defaultCurrency = priceUnits[0]?.code || "USD";
|
||||
|
||||
const activeMembers = useMemo(
|
||||
() => members.filter((member) => member.is_active),
|
||||
[members],
|
||||
);
|
||||
|
||||
const filteredMembers = useMemo(() => {
|
||||
const normalizedSearch = memberSearchQuery.trim().toLowerCase();
|
||||
const baseMembers = !normalizedSearch
|
||||
? manageableMembers
|
||||
: manageableMembers.filter((member) => {
|
||||
? activeMembers
|
||||
: activeMembers.filter((member) => {
|
||||
const memberName = getMemberName(member).toLowerCase();
|
||||
const memberMobile = member.user?.mobile?.toLowerCase() ?? "";
|
||||
return memberName.includes(normalizedSearch) || memberMobile.includes(normalizedSearch);
|
||||
@@ -112,7 +158,9 @@ export function ProjectAccessModal({
|
||||
if (b.user.id === selectedUserId) return 1;
|
||||
return 0;
|
||||
});
|
||||
}, [manageableMembers, memberSearchQuery, selectedUserId]);
|
||||
}, [activeMembers, memberSearchQuery, selectedUserId]);
|
||||
|
||||
const canManageExplicitAccess = selectedUserRole === "member" || selectedUserRole === "guest";
|
||||
|
||||
const clientOptions = useMemo(() => {
|
||||
const map = new Map<string, string>();
|
||||
@@ -143,40 +191,71 @@ export function ProjectAccessModal({
|
||||
[selectedProjectIds, visibleProjectIds],
|
||||
);
|
||||
|
||||
const currencyOptions = useMemo(() => {
|
||||
if (priceUnits.length) {
|
||||
return priceUnits.map((unit) => ({
|
||||
value: unit.code,
|
||||
label: unit.local_name ? `${unit.local_name} (${unit.code})` : `${unit.code} (${unit.name})`,
|
||||
}));
|
||||
}
|
||||
|
||||
const fallbackCurrencies = Array.from(
|
||||
new Set(
|
||||
projectItems.flatMap((item) => [
|
||||
item.project_rate?.currency,
|
||||
item.workspace_rate?.currency,
|
||||
defaultCurrency,
|
||||
]).filter(Boolean) as string[],
|
||||
),
|
||||
);
|
||||
return fallbackCurrencies.map((code) => ({ value: code, label: code }));
|
||||
}, [defaultCurrency, priceUnits, projectItems]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) {
|
||||
setSearchQuery("");
|
||||
setMemberSearchQuery("");
|
||||
setSelectedClientId("");
|
||||
setSelectedProjectIds([]);
|
||||
setRateDrafts({});
|
||||
return;
|
||||
}
|
||||
|
||||
const loadMembers = async () => {
|
||||
const loadDependencies = async () => {
|
||||
setLoadingMembers(true);
|
||||
try {
|
||||
const response = await fetchWorkspaceMemberships({ workspace: workspaceId, limit: 200, offset: 0 });
|
||||
setMembers(response.results || []);
|
||||
} catch {
|
||||
const [membersResult, priceUnitsResult] = await Promise.allSettled([
|
||||
fetchWorkspaceMemberships({ workspace: workspaceId, limit: 200, offset: 0 }),
|
||||
getPriceUnits(),
|
||||
]);
|
||||
|
||||
if (membersResult.status === "fulfilled") {
|
||||
setMembers(membersResult.value.results || []);
|
||||
} else {
|
||||
toast.error(labels.loadError);
|
||||
setMembers([]);
|
||||
} finally {
|
||||
setLoadingMembers(false);
|
||||
}
|
||||
|
||||
if (priceUnitsResult.status === "fulfilled") {
|
||||
setPriceUnits(priceUnitsResult.value.results || []);
|
||||
} else {
|
||||
setPriceUnits([]);
|
||||
}
|
||||
|
||||
setLoadingMembers(false);
|
||||
};
|
||||
|
||||
void loadMembers();
|
||||
void loadDependencies();
|
||||
}, [isOpen, labels.loadError, workspaceId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!manageableMembers.length) {
|
||||
if (!activeMembers.length) {
|
||||
setSelectedUserId("");
|
||||
return;
|
||||
}
|
||||
if (!manageableMembers.some((member) => member.user.id === selectedUserId)) {
|
||||
setSelectedUserId(manageableMembers[0].user.id);
|
||||
if (!activeMembers.some((member) => member.user.id === selectedUserId)) {
|
||||
setSelectedUserId(activeMembers[0].user.id);
|
||||
}
|
||||
}, [manageableMembers, selectedUserId]);
|
||||
}, [activeMembers, selectedUserId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen || !selectedUserId) {
|
||||
@@ -188,10 +267,12 @@ export function ProjectAccessModal({
|
||||
setLoadingProjects(true);
|
||||
try {
|
||||
const response = await getProjectAccessState(workspaceId, selectedUserId);
|
||||
setSelectedUserRole(response.user.role);
|
||||
setProjectItems(response.items);
|
||||
setSelectedProjectIds([]);
|
||||
} catch {
|
||||
toast.error(labels.loadError);
|
||||
setSelectedUserRole("");
|
||||
setProjectItems([]);
|
||||
} finally {
|
||||
setLoadingProjects(false);
|
||||
@@ -201,7 +282,34 @@ export function ProjectAccessModal({
|
||||
void loadAccessState();
|
||||
}, [isOpen, labels.loadError, selectedUserId, workspaceId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!projectItems.length) {
|
||||
setRateDrafts({});
|
||||
return;
|
||||
}
|
||||
|
||||
const nextDrafts: Record<string, RateDraft> = {};
|
||||
projectItems.forEach((item) => {
|
||||
nextDrafts[item.id] = getDraftFromItem(item, defaultCurrency);
|
||||
});
|
||||
setRateDrafts(nextDrafts);
|
||||
}, [defaultCurrency, projectItems]);
|
||||
|
||||
const replaceProjectItem = (nextItem: ProjectAccessItem) => {
|
||||
setProjectItems((current) =>
|
||||
current.map((item) => (item.id === nextItem.id ? nextItem : item)),
|
||||
);
|
||||
};
|
||||
|
||||
const syncRateDraftFromItem = (item: ProjectAccessItem) => {
|
||||
setRateDrafts((current) => ({
|
||||
...current,
|
||||
[item.id]: getDraftFromItem(item, defaultCurrency),
|
||||
}));
|
||||
};
|
||||
|
||||
const toggleProjectSelection = (projectId: string) => {
|
||||
if (!canManageExplicitAccess) return;
|
||||
setSelectedProjectIds((current) =>
|
||||
current.includes(projectId)
|
||||
? current.filter((id) => id !== projectId)
|
||||
@@ -210,11 +318,12 @@ export function ProjectAccessModal({
|
||||
};
|
||||
|
||||
const handleSelectAllVisible = () => {
|
||||
if (!canManageExplicitAccess) return;
|
||||
setSelectedProjectIds((current) => Array.from(new Set([...current, ...visibleProjectIds])));
|
||||
};
|
||||
|
||||
const handleSelectClientProjects = () => {
|
||||
if (!selectedClientId) return;
|
||||
if (!selectedClientId || !canManageExplicitAccess) return;
|
||||
const clientProjectIds = visibleProjects
|
||||
.filter((item) => item.client?.id === selectedClientId)
|
||||
.map((item) => item.id);
|
||||
@@ -248,6 +357,85 @@ export function ProjectAccessModal({
|
||||
}
|
||||
};
|
||||
|
||||
const handleRateDraftChange = (projectId: string, patch: Partial<RateDraft>) => {
|
||||
setRateDrafts((current) => ({
|
||||
...current,
|
||||
[projectId]: {
|
||||
hourlyRate: current[projectId]?.hourlyRate || "",
|
||||
currency: current[projectId]?.currency || defaultCurrency,
|
||||
...patch,
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
const persistProjectRate = async (
|
||||
item: ProjectAccessItem,
|
||||
nextDraft?: Partial<RateDraft>,
|
||||
) => {
|
||||
if (!selectedUserId || !item.has_access || savingRateProjectId) return;
|
||||
|
||||
const draft = {
|
||||
...(rateDrafts[item.id] || getDraftFromItem(item, defaultCurrency)),
|
||||
...nextDraft,
|
||||
};
|
||||
const trimmedRate = draft.hourlyRate.trim();
|
||||
const normalizedCurrency = (draft.currency || getPreferredCurrency(item, defaultCurrency)).toUpperCase();
|
||||
const currentRate = item.project_rate;
|
||||
|
||||
if (!trimmedRate) {
|
||||
if (!currentRate) {
|
||||
syncRateDraftFromItem(item);
|
||||
return;
|
||||
}
|
||||
|
||||
setSavingRateProjectId(item.id);
|
||||
try {
|
||||
const response = await saveProjectAccessRate(
|
||||
workspaceId,
|
||||
selectedUserId,
|
||||
item.id,
|
||||
null,
|
||||
normalizedCurrency,
|
||||
);
|
||||
replaceProjectItem(response.item);
|
||||
syncRateDraftFromItem(response.item);
|
||||
toast.success(labels.projectRateRemoved);
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : labels.projectRateRemoveError);
|
||||
syncRateDraftFromItem(item);
|
||||
} finally {
|
||||
setSavingRateProjectId(null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
currentRate?.hourly_rate === trimmedRate &&
|
||||
currentRate?.currency === normalizedCurrency
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSavingRateProjectId(item.id);
|
||||
try {
|
||||
const response = await saveProjectAccessRate(
|
||||
workspaceId,
|
||||
selectedUserId,
|
||||
item.id,
|
||||
trimmedRate,
|
||||
normalizedCurrency,
|
||||
);
|
||||
replaceProjectItem(response.item);
|
||||
syncRateDraftFromItem(response.item);
|
||||
toast.success(labels.projectRateSaved);
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : labels.projectRateSaveError);
|
||||
syncRateDraftFromItem(item);
|
||||
} finally {
|
||||
setSavingRateProjectId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const footer = (
|
||||
<>
|
||||
<div className="flex items-center gap-2 text-sm text-slate-500 dark:text-slate-400">
|
||||
@@ -260,7 +448,7 @@ export function ProjectAccessModal({
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => void handleMutation("grant")}
|
||||
disabled={!selectedProjectIds.length || isSaving}
|
||||
disabled={!canManageExplicitAccess || !selectedProjectIds.length || isSaving}
|
||||
className="gap-2"
|
||||
>
|
||||
{isSaving ? <Loader2 className="h-4 w-4 animate-spin" /> : <ShieldCheck className="h-4 w-4" />}
|
||||
@@ -270,7 +458,7 @@ export function ProjectAccessModal({
|
||||
type="button"
|
||||
variant="destructive"
|
||||
onClick={() => void handleMutation("revoke")}
|
||||
disabled={!selectedProjectIds.length || isSaving}
|
||||
disabled={!canManageExplicitAccess || !selectedProjectIds.length || isSaving}
|
||||
className="gap-2"
|
||||
>
|
||||
{isSaving ? <Loader2 className="h-4 w-4 animate-spin" /> : <ShieldAlert className="h-4 w-4" />}
|
||||
@@ -291,28 +479,17 @@ export function ProjectAccessModal({
|
||||
<p className="max-w-3xl text-sm text-slate-600 dark:text-slate-400">
|
||||
{labels.description}
|
||||
</p>
|
||||
{!canManageExplicitAccess && selectedUserRole ? (
|
||||
<div className="rounded-2xl border border-sky-200 bg-sky-50 px-4 py-3 text-sm text-sky-800 dark:border-sky-500/30 dark:bg-sky-500/10 dark:text-sky-100">
|
||||
{labels.implicitAccessHint}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="grid w-full grid-cols-1 gap-4 lg:grid-cols-12" dir="ltr">
|
||||
{/* LEFT SIDE */}
|
||||
<section
|
||||
dir={isRtl ? "rtl" : "ltr"}
|
||||
className="
|
||||
flex
|
||||
min-w-0
|
||||
min-h-[640px]
|
||||
flex-col
|
||||
overflow-hidden
|
||||
rounded-3xl
|
||||
border
|
||||
border-slate-200
|
||||
bg-slate-50/40
|
||||
dark:border-slate-800
|
||||
dark:bg-slate-950/30
|
||||
lg:col-span-8
|
||||
w-full
|
||||
"
|
||||
className="flex min-h-[640px] min-w-0 flex-col overflow-hidden rounded-3xl border border-slate-200 bg-slate-50/40 dark:border-slate-800 dark:bg-slate-950/30 lg:col-span-8"
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="border-b border-slate-200 bg-slate-50/80 p-4 dark:border-slate-800 dark:bg-slate-950/40">
|
||||
<div className="mb-3 flex items-center gap-2 text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
<Briefcase className="h-4 w-4" />
|
||||
@@ -320,14 +497,13 @@ export function ProjectAccessModal({
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-3 xl:items-center">
|
||||
<div className="w-full relative min-w-0 flex-1">
|
||||
<Search className="absolute left-3 rtl:left-auto rtl:right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400" />
|
||||
|
||||
<div className="relative min-w-0 flex-1 w-full">
|
||||
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400 rtl:left-auto rtl:right-3" />
|
||||
<Input
|
||||
value={searchQuery}
|
||||
onChange={(event) => setSearchQuery(event.target.value)}
|
||||
placeholder={labels.searchPlaceholder}
|
||||
className="w-full pl-10 pr-4 rtl:pl-4 rtl:pr-10 py-2.5 rounded-xl border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-slate-900 dark:text-white outline-none focus:ring-2 focus:ring-blue-500 transition-shadow"
|
||||
className="w-full rounded-xl border border-slate-200 bg-white py-2.5 pl-10 pr-4 text-slate-900 outline-none transition-shadow focus:ring-2 focus:ring-blue-500 dark:border-slate-700 dark:bg-slate-800 dark:text-white rtl:pl-4 rtl:pr-10"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -347,14 +523,13 @@ export function ProjectAccessModal({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex flex-wrap items-center gap-2 border-b border-slate-200 bg-white px-4 py-3 dark:border-slate-800 dark:bg-slate-900">
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
onClick={handleSelectAllVisible}
|
||||
disabled={!visibleProjects.length}
|
||||
disabled={!canManageExplicitAccess || !visibleProjects.length}
|
||||
title={labels.selectAllVisible}
|
||||
aria-label={labels.selectAllVisible}
|
||||
>
|
||||
@@ -378,7 +553,7 @@ export function ProjectAccessModal({
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
onClick={handleSelectClientProjects}
|
||||
disabled={!selectedClientId}
|
||||
disabled={!canManageExplicitAccess || !selectedClientId}
|
||||
title={labels.selectClientProjects}
|
||||
aria-label={labels.selectClientProjects}
|
||||
>
|
||||
@@ -390,9 +565,7 @@ export function ProjectAccessModal({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Projects */}
|
||||
<div className="min-h-0 flex-1 overflow-y-auto p-4">
|
||||
<div className="h-full">
|
||||
{loadingProjects ? (
|
||||
<div className="flex items-center gap-2 p-4 text-sm text-slate-500 dark:text-slate-400">
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
@@ -406,19 +579,23 @@ export function ProjectAccessModal({
|
||||
<div className="grid gap-3">
|
||||
{visibleProjects.map((item) => {
|
||||
const isChecked = selectedProjectIds.includes(item.id);
|
||||
const isRateSaving = savingRateProjectId === item.id;
|
||||
const draft = rateDrafts[item.id] || getDraftFromItem(item, defaultCurrency);
|
||||
|
||||
return (
|
||||
<button
|
||||
<div
|
||||
key={item.id}
|
||||
type="button"
|
||||
onClick={() => toggleProjectSelection(item.id)}
|
||||
className={`flex w-full items-start gap-3 rounded-2xl border px-4 py-3 text-start transition ${
|
||||
className={`rounded-2xl border px-4 py-3 transition ${
|
||||
isChecked
|
||||
? "border-sky-200 bg-sky-50/60 shadow-sm dark:border-sky-500/30 dark:bg-sky-500/10"
|
||||
: "border-slate-200 bg-white hover:border-slate-300 hover:bg-slate-50/70 dark:border-slate-800 dark:bg-slate-900 dark:hover:border-slate-700 dark:hover:bg-slate-800/40"
|
||||
: "border-slate-200 bg-white dark:border-slate-800 dark:bg-slate-900"
|
||||
}`}
|
||||
>
|
||||
{/* Checkbox */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => toggleProjectSelection(item.id)}
|
||||
className={`flex w-full items-start gap-3 text-start ${!canManageExplicitAccess ? "cursor-default" : ""}`}
|
||||
>
|
||||
<div
|
||||
className={`mt-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-md border transition ${
|
||||
isChecked
|
||||
@@ -434,34 +611,19 @@ export function ProjectAccessModal({
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="truncate font-medium text-slate-900 dark:text-slate-100">
|
||||
{item.name}
|
||||
</span>
|
||||
|
||||
{/* Better dark mode badge */}
|
||||
<span
|
||||
className={`inline-flex items-center rounded-full px-2 py-1 text-[11px] font-medium ${
|
||||
item.has_access
|
||||
? `
|
||||
bg-emerald-100 text-emerald-700
|
||||
dark:bg-emerald-500/15
|
||||
dark:text-emerald-200
|
||||
dark:ring-1 dark:ring-emerald-400/25
|
||||
`
|
||||
: `
|
||||
bg-slate-100 text-slate-600
|
||||
dark:bg-slate-800
|
||||
dark:text-slate-200
|
||||
dark:ring-1 dark:ring-slate-700
|
||||
`
|
||||
? "bg-emerald-100 text-emerald-700 dark:bg-emerald-500/15 dark:text-emerald-200 dark:ring-1 dark:ring-emerald-400/25"
|
||||
: "bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-200 dark:ring-1 dark:ring-slate-700"
|
||||
}`}
|
||||
>
|
||||
{item.has_access
|
||||
? labels.accessOn
|
||||
: labels.accessOff}
|
||||
{item.has_access ? labels.accessOn : labels.accessOff}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -476,35 +638,95 @@ export function ProjectAccessModal({
|
||||
) : null}
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<div className="mt-3 border-t border-slate-200 pt-3 dark:border-slate-800">
|
||||
<div className="grid gap-2 md:grid-cols-2">
|
||||
<div className="rounded-xl bg-slate-100/70 px-3 py-2 dark:bg-slate-800/70">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-[0.12em] text-slate-500 dark:text-slate-400">
|
||||
{labels.workspaceRate}
|
||||
</div>
|
||||
<div className="mt-1 text-sm font-medium text-slate-800 dark:text-slate-100">
|
||||
{formatRate(item.workspace_rate, labels, lang)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rounded-xl bg-slate-100/70 px-3 py-2 dark:bg-slate-800/70">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-[0.12em] text-slate-500 dark:text-slate-400">
|
||||
{labels.projectOverride}
|
||||
</div>
|
||||
<div className="mt-1 text-sm font-medium text-slate-800 dark:text-slate-100">
|
||||
{item.project_rate
|
||||
? formatRate(item.project_rate, labels, lang)
|
||||
: labels.inheritsWorkspaceRate}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-3 flex flex-col gap-2 lg:flex-row lg:items-center">
|
||||
<div className="grid flex-1 gap-2 sm:grid-cols-[minmax(0,1fr)_200px]">
|
||||
<Input
|
||||
value={draft.hourlyRate}
|
||||
onChange={(event) =>
|
||||
handleRateDraftChange(item.id, { hourlyRate: event.target.value })
|
||||
}
|
||||
onBlur={() => void persistProjectRate(item)}
|
||||
inputMode="decimal"
|
||||
placeholder={labels.hourlyRatePlaceholder}
|
||||
disabled={!item.has_access || isRateSaving}
|
||||
className="h-10"
|
||||
/>
|
||||
<Select
|
||||
value={draft.currency}
|
||||
onChange={(value) => {
|
||||
handleRateDraftChange(item.id, { currency: value });
|
||||
if (draft.hourlyRate.trim()) {
|
||||
void persistProjectRate(item, { currency: value });
|
||||
}
|
||||
}}
|
||||
options={currencyOptions}
|
||||
disabled={!item.has_access || isRateSaving}
|
||||
className="w-full"
|
||||
buttonClassName="h-10 w-full rounded-xl"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
disabled={!item.has_access || !item.project_rate || isRateSaving}
|
||||
title={labels.removeRate}
|
||||
aria-label={labels.removeRate}
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={() => {
|
||||
handleRateDraftChange(item.id, { hourlyRate: "" });
|
||||
void persistProjectRate(item, { hourlyRate: "" });
|
||||
}}
|
||||
>
|
||||
{isRateSaving ? <Loader2 className="h-4 w-4 animate-spin" /> : <X className="h-4 w-4" />}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!item.has_access && item.project_rate ? (
|
||||
<div className="mt-2 text-xs text-slate-500 dark:text-slate-400">
|
||||
{labels.projectOverride}: {formatRate(item.project_rate, labels, lang)}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* RIGHT SIDEBAR */}
|
||||
<aside
|
||||
dir={isRtl ? "rtl" : "ltr"}
|
||||
className="
|
||||
flex
|
||||
min-w-0
|
||||
min-h-[640px]
|
||||
flex-col
|
||||
overflow-hidden
|
||||
rounded-3xl
|
||||
border
|
||||
border-slate-200
|
||||
bg-white
|
||||
dark:border-slate-800
|
||||
dark:bg-slate-900
|
||||
lg:col-span-4
|
||||
lg:min-w-[320px]
|
||||
w-full
|
||||
"
|
||||
className="flex min-h-[640px] min-w-0 flex-col overflow-hidden rounded-3xl border border-slate-200 bg-white dark:border-slate-800 dark:bg-slate-900 lg:col-span-4"
|
||||
>
|
||||
{/* Sidebar Header */}
|
||||
<div className="border-b border-slate-200 bg-slate-50/80 p-4 dark:border-slate-800 dark:bg-slate-950/40">
|
||||
<div className="mb-3 flex items-center gap-2 text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
<Users className="h-4 w-4" />
|
||||
@@ -512,20 +734,16 @@ export function ProjectAccessModal({
|
||||
</div>
|
||||
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 rtl:left-auto rtl:right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400" />
|
||||
|
||||
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400 rtl:left-auto rtl:right-3" />
|
||||
<Input
|
||||
value={memberSearchQuery}
|
||||
onChange={(event) =>
|
||||
setMemberSearchQuery(event.target.value)
|
||||
}
|
||||
onChange={(event) => setMemberSearchQuery(event.target.value)}
|
||||
placeholder={labels.member}
|
||||
className="w-full pl-10 pr-4 rtl:pl-4 rtl:pr-10 py-2.5 rounded-xl border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-slate-900 dark:text-white outline-none focus:ring-2 focus:ring-blue-500 transition-shadow"
|
||||
className="w-full rounded-xl border border-slate-200 bg-white py-2.5 pl-10 pr-4 text-slate-900 outline-none transition-shadow focus:ring-2 focus:ring-blue-500 dark:border-slate-700 dark:bg-slate-800 dark:text-white rtl:pl-4 rtl:pr-10"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Users List */}
|
||||
<div className="min-h-0 flex-1 overflow-y-auto p-3">
|
||||
<div className="grid gap-2">
|
||||
{loadingMembers ? (
|
||||
@@ -538,18 +756,15 @@ export function ProjectAccessModal({
|
||||
{labels.noMembers}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{filteredMembers.map((member) => {
|
||||
const isActive =
|
||||
member.user.id === selectedUserId;
|
||||
filteredMembers.map((member) => {
|
||||
const isActive = member.user.id === selectedUserId;
|
||||
const isImplicitUser = member.role === "owner" || member.role === "admin";
|
||||
|
||||
return (
|
||||
<button
|
||||
key={member.id}
|
||||
type="button"
|
||||
onClick={() =>
|
||||
setSelectedUserId(member.user.id)
|
||||
}
|
||||
onClick={() => setSelectedUserId(member.user.id)}
|
||||
className={`flex w-full items-start gap-3 rounded-2xl px-4 py-3 text-start transition ${
|
||||
isActive
|
||||
? "bg-sky-50/80 dark:bg-sky-500/10"
|
||||
@@ -576,6 +791,11 @@ export function ProjectAccessModal({
|
||||
<span className="shrink-0 rounded-full bg-slate-100 px-2 py-1 text-[11px] font-medium capitalize text-slate-600 dark:bg-slate-800 dark:text-slate-300">
|
||||
{member.role}
|
||||
</span>
|
||||
{isImplicitUser ? (
|
||||
<span className="shrink-0 rounded-full bg-sky-100 px-2 py-1 text-[11px] font-medium text-sky-700 dark:bg-sky-500/15 dark:text-sky-200">
|
||||
{labels.accessOn}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{isActive ? (
|
||||
@@ -589,8 +809,7 @@ export function ProjectAccessModal({
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -27,8 +27,36 @@ export const ProjectCreateModal: React.FC<ProjectCreateModalProps> = ({ isOpen,
|
||||
color: "#3B82F6",
|
||||
client: "",
|
||||
});
|
||||
const [thumbnailFile, setThumbnailFile] = useState<File | null>(null);
|
||||
const [thumbnailPreview, setThumbnailPreview] = useState<string | null>(null);
|
||||
const [loadingClients, setLoadingClients] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!thumbnailFile) {
|
||||
setThumbnailPreview(null);
|
||||
return;
|
||||
}
|
||||
const objectUrl = URL.createObjectURL(thumbnailFile);
|
||||
setThumbnailPreview(objectUrl);
|
||||
return () => URL.revokeObjectURL(objectUrl);
|
||||
}, [thumbnailFile]);
|
||||
|
||||
const handleThumbnailChange = (file: File | null) => {
|
||||
if (!file) {
|
||||
setThumbnailFile(null);
|
||||
return;
|
||||
}
|
||||
if (!["image/jpeg", "image/png", "image/webp"].includes(file.type)) {
|
||||
toast.error(t.workspace?.thumbnailInvalidType || "Unsupported image type. Use JPG, PNG, or WebP.");
|
||||
return;
|
||||
}
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
toast.error(t.workspace?.thumbnailMaxSizeError || "Image size must be 2MB or less.");
|
||||
return;
|
||||
}
|
||||
setThumbnailFile(file);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen && activeWorkspace) {
|
||||
setLoadingClients(true);
|
||||
@@ -51,12 +79,14 @@ export const ProjectCreateModal: React.FC<ProjectCreateModalProps> = ({ isOpen,
|
||||
description: formData.description,
|
||||
color: formData.color,
|
||||
client: formData.client || null,
|
||||
thumbnail: thumbnailFile,
|
||||
});
|
||||
|
||||
toast.success(t.projects?.createSuccess || "Project created successfully.");
|
||||
window.dispatchEvent(new CustomEvent("project_created", { detail: newProject }));
|
||||
onClose();
|
||||
setFormData({ name: "", description: "", color: "#3B82F6", client: "" });
|
||||
setThumbnailFile(null);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error(t.projects?.createError || "Failed to create project.");
|
||||
@@ -70,7 +100,7 @@ export const ProjectCreateModal: React.FC<ProjectCreateModalProps> = ({ isOpen,
|
||||
<button onClick={onClose} type="button" className="px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-lg hover:bg-slate-50 dark:bg-slate-800 dark:text-slate-300 dark:border-slate-600 dark:hover:bg-slate-700">
|
||||
{t.actions?.cancel || "Cancel"}
|
||||
</button>
|
||||
<button onClick={handleSubmit} disabled={loading || !formData.name} type="button" className="px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 disabled:opacity-50">
|
||||
<button form="create-project-form" disabled={loading || !formData.name} type="submit" className="px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 disabled:opacity-50">
|
||||
{loading ? "..." : t.projects?.create}
|
||||
</button>
|
||||
</>
|
||||
@@ -80,7 +110,7 @@ export const ProjectCreateModal: React.FC<ProjectCreateModalProps> = ({ isOpen,
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={onClose} title={t.projects?.createProject} footer={footer}>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<form id="create-project-form" onSubmit={handleSubmit} className="space-y-4">
|
||||
{/* ردیف اول: عنوان و انتخاب رنگ */}
|
||||
<div className="flex items-end gap-3">
|
||||
<div className="flex-1">
|
||||
@@ -114,6 +144,23 @@ export const ProjectCreateModal: React.FC<ProjectCreateModalProps> = ({ isOpen,
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block mb-1 text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
{t.workspace?.thumbnailLabel || "Thumbnail"}
|
||||
</label>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded-2xl text-sm font-semibold text-white" style={{ backgroundColor: formData.color || "#3B82F6" }}>
|
||||
{thumbnailPreview ? <img src={thumbnailPreview} alt="" className="h-full w-full object-cover" /> : formData.name.trim().charAt(0).toUpperCase() || "P"}
|
||||
</div>
|
||||
<Input type="file" accept="image/jpeg,image/png,image/webp" onChange={(event) => handleThumbnailChange(event.target.files?.[0] || null)} />
|
||||
{thumbnailFile ? (
|
||||
<button type="button" onClick={() => setThumbnailFile(null)} className="rounded-lg border border-slate-300 px-3 py-2 text-sm dark:border-slate-600">
|
||||
{t.remove || "Remove"}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block mb-1 text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
{t.projects?.descriptionLabel || 'Description'}
|
||||
|
||||
@@ -30,6 +30,10 @@ export const ProjectEditModal: React.FC<ProjectEditModalProps> = ({ isOpen, onCl
|
||||
color: "#3B82F6",
|
||||
client: "",
|
||||
});
|
||||
const [thumbnailFile, setThumbnailFile] = useState<File | null>(null);
|
||||
const [thumbnailUrl, setThumbnailUrl] = useState<string | null>(null);
|
||||
const [thumbnailPreview, setThumbnailPreview] = useState<string | null>(null);
|
||||
const [clearThumbnail, setClearThumbnail] = useState(false);
|
||||
const [loadingClients, setLoadingClients] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -50,9 +54,36 @@ export const ProjectEditModal: React.FC<ProjectEditModalProps> = ({ isOpen, onCl
|
||||
color: project.color || "#3B82F6",
|
||||
client: project.client ? project.client.id : "",
|
||||
});
|
||||
setThumbnailUrl(project.thumbnail || null);
|
||||
setThumbnailFile(null);
|
||||
setClearThumbnail(false);
|
||||
}
|
||||
}, [project]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!thumbnailFile) {
|
||||
setThumbnailPreview(null);
|
||||
return;
|
||||
}
|
||||
const objectUrl = URL.createObjectURL(thumbnailFile);
|
||||
setThumbnailPreview(objectUrl);
|
||||
return () => URL.revokeObjectURL(objectUrl);
|
||||
}, [thumbnailFile]);
|
||||
|
||||
const handleThumbnailChange = (file: File | null) => {
|
||||
if (!file) return;
|
||||
if (!["image/jpeg", "image/png", "image/webp"].includes(file.type)) {
|
||||
toast.error(t.workspace?.thumbnailInvalidType || "Unsupported image type. Use JPG, PNG, or WebP.");
|
||||
return;
|
||||
}
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
toast.error(t.workspace?.thumbnailMaxSizeError || "Image size must be 2MB or less.");
|
||||
return;
|
||||
}
|
||||
setThumbnailFile(file);
|
||||
setClearThumbnail(false);
|
||||
};
|
||||
|
||||
const handleSubmit = async (e?: React.FormEvent) => {
|
||||
e?.preventDefault();
|
||||
if (!project || !formData.name) return;
|
||||
@@ -64,6 +95,8 @@ export const ProjectEditModal: React.FC<ProjectEditModalProps> = ({ isOpen, onCl
|
||||
description: formData.description,
|
||||
color: formData.color,
|
||||
client: formData.client || null,
|
||||
thumbnail: thumbnailFile,
|
||||
clear_thumbnail: clearThumbnail,
|
||||
});
|
||||
|
||||
toast.success(t.projects?.updateSuccess || "Project updated successfully.");
|
||||
@@ -121,7 +154,7 @@ export const ProjectEditModal: React.FC<ProjectEditModalProps> = ({ isOpen, onCl
|
||||
<button onClick={onClose} type="button" className="px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-lg hover:bg-slate-50 dark:bg-slate-800 dark:text-slate-300 dark:border-slate-600">
|
||||
{t.actions?.cancel || "Cancel"}
|
||||
</button>
|
||||
<button onClick={handleSubmit} disabled={loading || !formData.name} type="button" className="px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 disabled:opacity-50">
|
||||
<button form="edit-project-form" disabled={loading || !formData.name} type="submit" className="px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 disabled:opacity-50">
|
||||
{loading ? "..." : t.save || "Save"}
|
||||
</button>
|
||||
</div>
|
||||
@@ -132,7 +165,7 @@ export const ProjectEditModal: React.FC<ProjectEditModalProps> = ({ isOpen, onCl
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={onClose} title={t.projects.editProject} footer={footer}>
|
||||
<form onSubmit={handleSubmit} className="space-y-4 mb-6">
|
||||
<form id="edit-project-form" onSubmit={handleSubmit} className="space-y-4 mb-6">
|
||||
<div className="flex items-end gap-3">
|
||||
<div className="flex-1">
|
||||
<label className="block mb-1 text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
@@ -164,6 +197,36 @@ export const ProjectEditModal: React.FC<ProjectEditModalProps> = ({ isOpen, onCl
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block mb-1 text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
{t.workspace?.thumbnailLabel || "Thumbnail"}
|
||||
</label>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded-2xl text-sm font-semibold text-white" style={{ backgroundColor: formData.color || "#3B82F6" }}>
|
||||
{thumbnailPreview ? (
|
||||
<img src={thumbnailPreview} alt="" className="h-full w-full object-cover" />
|
||||
) : !clearThumbnail && thumbnailUrl ? (
|
||||
<img src={thumbnailUrl} alt="" className="h-full w-full object-cover" />
|
||||
) : (
|
||||
formData.name.trim().charAt(0).toUpperCase() || "P"
|
||||
)}
|
||||
</div>
|
||||
<Input type="file" accept="image/jpeg,image/png,image/webp" onChange={(event) => handleThumbnailChange(event.target.files?.[0] || null)} />
|
||||
{(thumbnailFile || (!clearThumbnail && thumbnailUrl)) ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setThumbnailFile(null);
|
||||
setClearThumbnail(true);
|
||||
}}
|
||||
className="rounded-lg border border-slate-300 px-3 py-2 text-sm dark:border-slate-600"
|
||||
>
|
||||
{t.remove || "Remove"}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block mb-1 text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
{t.projects?.descriptionLabel || 'Description'}
|
||||
|
||||
205
src/components/rates/WorkspaceRatesPanel.tsx
Normal file
205
src/components/rates/WorkspaceRatesPanel.tsx
Normal file
@@ -0,0 +1,205 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Banknote, BriefcaseBusiness, FolderKanban, X } from "lucide-react";
|
||||
|
||||
import type { MyWorkspaceRatesResponse } from "../../api/rates";
|
||||
import { useTranslation } from "../../hooks/useTranslation";
|
||||
import { formatRateDisplay } from "../../lib/money";
|
||||
import { Button } from "../ui/button";
|
||||
|
||||
export function WorkspaceRatesPanel({
|
||||
open,
|
||||
data,
|
||||
isLoading,
|
||||
onClose,
|
||||
}: {
|
||||
open: boolean;
|
||||
data: MyWorkspaceRatesResponse | null;
|
||||
isLoading: boolean;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const { t, lang } = useTranslation();
|
||||
const [shouldRender, setShouldRender] = useState(open);
|
||||
const [isVisible, setIsVisible] = useState(open);
|
||||
const isRtl = lang === "fa";
|
||||
|
||||
useEffect(() => {
|
||||
let timeoutId: ReturnType<typeof setTimeout> | null = null;
|
||||
let frameId: number | null = null;
|
||||
|
||||
if (open) {
|
||||
setShouldRender(true);
|
||||
frameId = window.requestAnimationFrame(() => setIsVisible(true));
|
||||
} else {
|
||||
setIsVisible(false);
|
||||
timeoutId = setTimeout(() => setShouldRender(false), 300);
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (timeoutId) clearTimeout(timeoutId);
|
||||
if (frameId) window.cancelAnimationFrame(frameId);
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
if (!shouldRender) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`fixed inset-0 z-[80] flex items-end lg:items-stretch ${
|
||||
isRtl ? "lg:justify-start" : "lg:justify-end"
|
||||
}`}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className={`absolute inset-0 cursor-pointer bg-slate-950/40 backdrop-blur-[2px] transition-opacity duration-300 ${
|
||||
isVisible ? "opacity-100" : "opacity-0"
|
||||
}`}
|
||||
onClick={onClose}
|
||||
aria-label="Close rates panel"
|
||||
/>
|
||||
<aside
|
||||
className={`relative z-10 flex max-h-[88vh] w-full flex-col rounded-t-[2rem] bg-white shadow-2xl transition-transform duration-300 ease-out dark:bg-slate-950 lg:h-full lg:max-h-none lg:w-[34rem] lg:rounded-none ${
|
||||
isRtl ? "lg:border-r lg:border-slate-800" : "lg:border-l lg:border-slate-800"
|
||||
} ${
|
||||
isVisible
|
||||
? "translate-y-0 lg:translate-x-0"
|
||||
: `translate-y-full lg:translate-y-0 ${!isRtl ? "lg:-translate-x-full" : "lg:translate-x-full"}`
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center justify-between border-b border-slate-200 px-5 py-4 dark:border-slate-800">
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold text-slate-900 dark:text-white">
|
||||
{t.rates?.myRatesTitle || "My rates"}
|
||||
</h2>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400">
|
||||
{t.rates?.myRatesHint || "Project-specific rates override your workspace rate in this workspace."}
|
||||
</p>
|
||||
</div>
|
||||
<Button type="button" variant="ghost" size="icon" onClick={onClose} className="rounded-xl">
|
||||
<X className="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-y-auto px-5 py-5">
|
||||
{isLoading ? (
|
||||
<div className="rounded-2xl border border-slate-200 bg-slate-50 p-4 text-sm text-slate-500 dark:border-slate-800 dark:bg-slate-900 dark:text-slate-400">
|
||||
{t.loading || "Loading..."}
|
||||
</div>
|
||||
) : !data ? (
|
||||
<div className="rounded-2xl border border-dashed border-slate-300 p-6 text-center text-sm text-slate-500 dark:border-slate-700 dark:text-slate-400">
|
||||
{t.rates?.myRatesEmpty || "No rates are available for this workspace yet."}
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-5">
|
||||
<div className="rounded-3xl border border-slate-200 bg-slate-50 p-4 dark:border-slate-800 dark:bg-slate-900">
|
||||
<div className="flex items-start gap-4">
|
||||
<div className="flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-emerald-100 text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-300">
|
||||
<Banknote className="h-5 w-5" />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-base font-semibold text-slate-900 dark:text-white">
|
||||
{t.rates?.workspaceRate || "Workspace rate"}
|
||||
</p>
|
||||
<p className="mt-1 text-sm text-slate-500 dark:text-slate-400">
|
||||
{t.rates?.workspaceRateHint || "This is your default rate unless a project-specific rate overrides it."}
|
||||
</p>
|
||||
<div className="mt-3 text-lg font-bold text-slate-900 dark:text-white">
|
||||
{data.workspace_rate
|
||||
? formatRateDisplay(
|
||||
{
|
||||
hourly_rate: data.workspace_rate.hourly_rate,
|
||||
currency: data.workspace_rate.currency,
|
||||
price_unit: data.workspace_rate.price_unit,
|
||||
},
|
||||
lang,
|
||||
)
|
||||
: (t.rates?.noRate || "No rate")}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-3 sm:grid-cols-3">
|
||||
<div className="rounded-2xl border border-slate-200 bg-white p-4 dark:border-slate-800 dark:bg-slate-900">
|
||||
<div className="text-xs font-semibold uppercase tracking-[0.16em] text-slate-500 dark:text-slate-400">
|
||||
{t.rates?.accessibleProjects || "Accessible projects"}
|
||||
</div>
|
||||
<div className="mt-2 text-2xl font-bold text-slate-900 dark:text-white">
|
||||
{data.accessible_project_count}
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-2xl border border-slate-200 bg-white p-4 dark:border-slate-800 dark:bg-slate-900">
|
||||
<div className="text-xs font-semibold uppercase tracking-[0.16em] text-slate-500 dark:text-slate-400">
|
||||
{t.rates?.projectOverrides || "Project overrides"}
|
||||
</div>
|
||||
<div className="mt-2 text-2xl font-bold text-slate-900 dark:text-white">
|
||||
{data.project_override_count}
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-2xl border border-slate-200 bg-white p-4 dark:border-slate-800 dark:bg-slate-900">
|
||||
<div className="text-xs font-semibold uppercase tracking-[0.16em] text-slate-500 dark:text-slate-400">
|
||||
{t.rates?.workspaceFallbackProjects || "Using workspace rate"}
|
||||
</div>
|
||||
<div className="mt-2 text-2xl font-bold text-slate-900 dark:text-white">
|
||||
{data.workspace_fallback_project_count}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rounded-3xl border border-slate-200 bg-white dark:border-slate-800 dark:bg-slate-900">
|
||||
<div className="border-b border-slate-100 px-5 py-4 dark:border-slate-800">
|
||||
<h3 className="text-base font-semibold text-slate-900 dark:text-white">
|
||||
{t.rates?.projectSectionTitle || "Project user rates"}
|
||||
</h3>
|
||||
<p className="mt-1 text-sm text-slate-500 dark:text-slate-400">
|
||||
{t.rates?.projectOverrideHint || "Only projects with custom overrides are listed here. Other accessible projects use your workspace rate."}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{data.project_rates.length ? (
|
||||
<div className="divide-y divide-slate-100 dark:divide-slate-800">
|
||||
{data.project_rates.map((projectRate) => (
|
||||
<div key={projectRate.project.id} className="flex items-start gap-4 px-5 py-4">
|
||||
<div className="flex h-11 w-11 shrink-0 items-center justify-center rounded-2xl bg-sky-100 text-sky-700 dark:bg-sky-500/10 dark:text-sky-300">
|
||||
<FolderKanban className="h-5 w-5" />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<p className="text-sm font-semibold text-slate-900 dark:text-white">
|
||||
{projectRate.project.name}
|
||||
</p>
|
||||
{projectRate.project.client ? (
|
||||
<span className="inline-flex items-center gap-1 rounded-full bg-slate-100 px-2 py-1 text-[11px] font-medium text-slate-600 dark:bg-slate-800 dark:text-slate-300">
|
||||
<BriefcaseBusiness className="h-3 w-3" />
|
||||
{projectRate.project.client.name}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<p className="mt-2 text-sm font-semibold text-slate-900 dark:text-white">
|
||||
{formatRateDisplay(
|
||||
{
|
||||
hourly_rate: projectRate.rate.hourly_rate,
|
||||
currency: projectRate.rate.currency,
|
||||
price_unit: projectRate.rate.price_unit,
|
||||
},
|
||||
lang,
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="px-5 py-6 text-sm text-slate-500 dark:text-slate-400">
|
||||
{t.rates?.projectOverrideEmpty || "You do not have any project-specific rate overrides in this workspace."}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -25,7 +25,12 @@ type ChartRow = {
|
||||
const localizeDigits = (value: string, lang: "en" | "fa") =>
|
||||
lang === "fa" ? value.replace(/\d/g, (digit) => PERSIAN_DIGITS[Number(digit)] || digit) : value
|
||||
|
||||
const formatAmount = (value: string, lang: "en" | "fa") => {
|
||||
const shouldTrimCurrencyDecimals = (currency?: string | null) => {
|
||||
const normalized = (currency || "").toUpperCase()
|
||||
return normalized === "IRR" || normalized === "IRT"
|
||||
}
|
||||
|
||||
const formatAmount = (value: string, lang: "en" | "fa", currency?: string | null) => {
|
||||
const numeric = Number(value.replace(/,/g, ""))
|
||||
if (Number.isNaN(numeric)) {
|
||||
return localizeDigits(value, lang)
|
||||
@@ -34,7 +39,9 @@ const formatAmount = (value: string, lang: "en" | "fa") => {
|
||||
const [integerPart, fractionalPart] = value.replace(/,/g, "").split(".")
|
||||
const grouped = Math.abs(Number(integerPart)).toLocaleString("en-US")
|
||||
const signed = value.startsWith("-") ? `-${grouped}` : grouped
|
||||
const formatted = fractionalPart ? `${signed}.${fractionalPart}` : signed
|
||||
const normalizedFraction =
|
||||
fractionalPart && !shouldTrimCurrencyDecimals(currency) ? fractionalPart.replace(/0+$/, "") : ""
|
||||
const formatted = normalizedFraction ? `${signed}.${normalizedFraction}` : signed
|
||||
return localizeDigits(formatted, lang)
|
||||
}
|
||||
|
||||
@@ -58,10 +65,10 @@ const currencyLabel = (currency: string, lang: "en" | "fa") => {
|
||||
|
||||
const formatMoneyTotals = (totals: CurrencyTotal[], lang: "en" | "fa") => {
|
||||
if (!totals.length) {
|
||||
return "-"
|
||||
return localizeDigits("0", lang)
|
||||
}
|
||||
|
||||
return totals.map((item) => `${formatAmount(item.amount, lang)} ${currencyLabel(item.currency, lang)}`).join(" | ")
|
||||
return totals.map((item) => `${formatAmount(item.amount, lang, item.currency)} ${currencyLabel(item.currency, lang)}`).join(" | ")
|
||||
}
|
||||
|
||||
const formatSecondsTick = (value: number, lang: "en" | "fa") => {
|
||||
@@ -187,13 +194,24 @@ const buildSeriesBuckets = (
|
||||
|
||||
const createSeriesKey = (series: ChartReportSeries, index: number) => series.user?.id ?? `series_${index}`
|
||||
|
||||
const effectiveSeries = (data: ChartReportResponse): ChartReportSeries[] =>
|
||||
data.series.length
|
||||
? data.series
|
||||
: [
|
||||
{
|
||||
user: null,
|
||||
buckets: [],
|
||||
},
|
||||
]
|
||||
|
||||
const buildChartRows = (data: ChartReportResponse, lang: "en" | "fa") => {
|
||||
const useMonthlyBuckets =
|
||||
data.scope.period === "this_year" ||
|
||||
data.scope.period === "half_year_first" ||
|
||||
data.scope.period === "half_year_second"
|
||||
|
||||
const normalizedSeries = data.series.map((series) => buildSeriesBuckets(series, data, lang, useMonthlyBuckets))
|
||||
const seriesList = effectiveSeries(data)
|
||||
const normalizedSeries = seriesList.map((series) => buildSeriesBuckets(series, data, lang, useMonthlyBuckets))
|
||||
const baseBuckets = normalizedSeries[0] ?? []
|
||||
|
||||
const rows: ChartRow[] = baseBuckets.map((bucket, bucketIndex) => {
|
||||
@@ -207,7 +225,7 @@ const buildChartRows = (data: ChartReportResponse, lang: "en" | "fa") => {
|
||||
tooltip_label: tooltipLabel,
|
||||
}
|
||||
|
||||
data.series.forEach((series, seriesIndex) => {
|
||||
seriesList.forEach((series, seriesIndex) => {
|
||||
const seriesKey = createSeriesKey(series, seriesIndex)
|
||||
row[seriesKey] = normalizedSeries[seriesIndex]?.[bucketIndex]?.total_seconds ?? 0
|
||||
})
|
||||
@@ -215,7 +233,7 @@ const buildChartRows = (data: ChartReportResponse, lang: "en" | "fa") => {
|
||||
return row
|
||||
})
|
||||
|
||||
return { rows, useMonthlyBuckets }
|
||||
return { rows, seriesList, useMonthlyBuckets }
|
||||
}
|
||||
|
||||
function ChartTooltip({
|
||||
@@ -260,20 +278,47 @@ function ChartTooltip({
|
||||
export function ReportsChartPanel({
|
||||
data,
|
||||
labels,
|
||||
isLoading,
|
||||
}: {
|
||||
data: ChartReportResponse | null
|
||||
labels: Record<string, string>
|
||||
isLoading: boolean
|
||||
}) {
|
||||
const { lang } = useTranslation()
|
||||
|
||||
if (!data || data.series.length === 0) {
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-3 xl:grid-cols-4">
|
||||
{Array.from({ length: 4 }).map((_, index) => (
|
||||
<div key={index} className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900">
|
||||
<div className="mb-3 text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500 dark:text-slate-400">
|
||||
{labels.loading}
|
||||
</div>
|
||||
<div className="h-8 animate-pulse rounded-xl bg-slate-200/80 dark:bg-slate-800/80" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-5">
|
||||
<div className="mb-4 flex items-center justify-between gap-3">
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-white">{labels.chart}</div>
|
||||
<div className="text-xs text-slate-500 dark:text-slate-400">{labels.loading}</div>
|
||||
</div>
|
||||
<div className="h-[320px] animate-pulse rounded-2xl bg-slate-200/80 dark:bg-slate-800/80 sm:h-[360px]" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return null
|
||||
}
|
||||
|
||||
const { rows, useMonthlyBuckets } = buildChartRows(data, lang)
|
||||
const { rows, seriesList, useMonthlyBuckets } = buildChartRows(data, lang)
|
||||
const interval = useMonthlyBuckets ? 0 : rows.length > 20 ? Math.ceil(rows.length / 10) - 1 : 0
|
||||
const chartMinWidth = Math.max(640, rows.length * (useMonthlyBuckets ? 110 : 52))
|
||||
const isMultiSeries = data.series.length > 1
|
||||
const isMultiSeries = seriesList.length > 1
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-3 xl:grid-cols-4">
|
||||
@@ -351,7 +396,7 @@ export function ReportsChartPanel({
|
||||
wrapperStyle={{ paddingBottom: "16px", fontSize: "12px" }}
|
||||
/>
|
||||
) : null}
|
||||
{data.series.map((series, index) => {
|
||||
{seriesList.map((series, index) => {
|
||||
const dataKey = createSeriesKey(series, index)
|
||||
return (
|
||||
<Bar
|
||||
|
||||
@@ -1,31 +1,49 @@
|
||||
import { Fragment, useState } from "react";
|
||||
import { ChevronDown, ChevronUp, FileSpreadsheet, FileText } from "lucide-react";
|
||||
import { Fragment, useMemo, useState } from "react";
|
||||
import { ChevronDown, ChevronUp, Eye, FileSpreadsheet, FileText } from "lucide-react";
|
||||
|
||||
import type { BreakdownRow, DayDetailsResponse, TableReportResponse, UserReportSummary } from "../../api/reports";
|
||||
import { Modal } from "../Modal";
|
||||
import type {
|
||||
BreakdownRow,
|
||||
DayDetailsResponse,
|
||||
PercentageRow,
|
||||
TableReportResponse,
|
||||
UserReportSummary,
|
||||
UserScopedTableReport,
|
||||
} from "../../api/reports";
|
||||
import { useTranslation } from "../../hooks/useTranslation";
|
||||
import { Modal } from "../Modal";
|
||||
|
||||
const PERSIAN_DIGITS = "۰۱۲۳۴۵۶۷۸۹";
|
||||
|
||||
const toPersianDigits = (value: string) =>
|
||||
value.replace(/\d/g, (digit) => "۰۱۲۳۴۵۶۷۸۹"[Number(digit)] || digit);
|
||||
value.replace(/\d/g, (digit) => PERSIAN_DIGITS[Number(digit)] || digit);
|
||||
|
||||
const localizeDigits = (value: string, lang: "en" | "fa") => (lang === "fa" ? toPersianDigits(value) : value);
|
||||
|
||||
const formatAmount = (value: string, lang: "en" | "fa") => {
|
||||
const shouldTrimCurrencyDecimals = (currency?: string | null) => {
|
||||
const normalized = (currency || "").toUpperCase();
|
||||
return normalized === "IRR" || normalized === "IRT";
|
||||
};
|
||||
|
||||
const formatAmount = (value: string, lang: "en" | "fa", currency?: string | null) => {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) return trimmed;
|
||||
|
||||
const numeric = Number(trimmed.replace(/,/g, ""));
|
||||
if (Number.isNaN(numeric)) return localizeDigits(trimmed, lang);
|
||||
|
||||
const [integerPart, fractionalPart] = trimmed.replace(/,/g, "").split(".");
|
||||
const grouped = Math.abs(Number(integerPart)).toLocaleString("en-US");
|
||||
const signed = trimmed.startsWith("-") ? `-${grouped}` : grouped;
|
||||
const normalized = fractionalPart ? `${signed}.${fractionalPart}` : signed;
|
||||
const normalizedFraction =
|
||||
fractionalPart && !shouldTrimCurrencyDecimals(currency) ? fractionalPart.replace(/0+$/, "") : "";
|
||||
const normalized = normalizedFraction ? `${signed}.${normalizedFraction}` : signed;
|
||||
return localizeDigits(normalized, lang);
|
||||
};
|
||||
|
||||
const currencyLabel = (currency: string, lang: "en" | "fa") => {
|
||||
const normalized = currency.toUpperCase();
|
||||
if (lang !== "fa") return normalized;
|
||||
|
||||
return (
|
||||
{
|
||||
USD: "دلار آمریکا",
|
||||
@@ -40,16 +58,15 @@ const currencyLabel = (currency: string, lang: "en" | "fa") => {
|
||||
};
|
||||
|
||||
const formatMoneyTotals = (totals: { currency: string; amount: string }[], lang: "en" | "fa") => {
|
||||
if (!totals.length) return "-";
|
||||
return totals.map((item) => `${formatAmount(item.amount, lang)} ${currencyLabel(item.currency, lang)}`).join(" | ");
|
||||
if (!totals.length) return localizeDigits("0", lang);
|
||||
return totals
|
||||
.map((item) => `${formatAmount(item.amount, lang, item.currency)} ${currencyLabel(item.currency, lang)}`)
|
||||
.join(" | ");
|
||||
};
|
||||
|
||||
const formatHourlyRate = (
|
||||
rate: { currency: string; amount: string } | null,
|
||||
lang: "en" | "fa",
|
||||
) => {
|
||||
if (!rate) return "-";
|
||||
return `${formatAmount(rate.amount, lang)} ${currencyLabel(rate.currency, lang)}`;
|
||||
const formatHourlyRate = (rate: { currency: string; amount: string } | null, lang: "en" | "fa") => {
|
||||
if (!rate) return localizeDigits("0", lang);
|
||||
return `${formatAmount(rate.amount, lang, rate.currency)} ${currencyLabel(rate.currency, lang)}`;
|
||||
};
|
||||
|
||||
const formatDisplayDate = (value: string, lang: "en" | "fa") => {
|
||||
@@ -59,6 +76,11 @@ const formatDisplayDate = (value: string, lang: "en" | "fa") => {
|
||||
}).format(parsed);
|
||||
};
|
||||
|
||||
const formatRateToLabel = (value: string | null | undefined, lang: "en" | "fa", nowLabel: string) => {
|
||||
if (!value) return nowLabel;
|
||||
return formatDisplayDate(value, lang);
|
||||
};
|
||||
|
||||
const formatDisplayDateTime = (value: string, lang: "en" | "fa") => {
|
||||
const parsed = new Date(value);
|
||||
return new Intl.DateTimeFormat(lang === "fa" ? "fa-IR" : "en-US", {
|
||||
@@ -67,110 +89,276 @@ const formatDisplayDateTime = (value: string, lang: "en" | "fa") => {
|
||||
}).format(parsed);
|
||||
};
|
||||
|
||||
function PercentageBreakdownSection({
|
||||
title,
|
||||
rows,
|
||||
lang,
|
||||
emptyLabel,
|
||||
}: {
|
||||
title: string;
|
||||
rows: { id: string; name: string; percentage: string }[];
|
||||
lang: "en" | "fa";
|
||||
emptyLabel: string;
|
||||
}) {
|
||||
const percentageMap = (rows?: PercentageRow[]) =>
|
||||
new Map((rows || []).map((row) => [row.id, `${formatAmount(row.percentage, "en")}%`]));
|
||||
|
||||
const numericPercentageMap = (rows?: PercentageRow[]) =>
|
||||
new Map((rows || []).map((row) => [row.id, Number(row.percentage) || 0]));
|
||||
|
||||
function LoadingBlock({ className }: { className: string }) {
|
||||
return <div className={`animate-pulse rounded-2xl bg-slate-200/80 dark:bg-slate-800/80 ${className}`} />;
|
||||
}
|
||||
|
||||
function ReportsTableSkeleton({ labels }: { labels: Record<string, string> }) {
|
||||
return (
|
||||
<section className="space-y-3">
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-white">{title}</div>
|
||||
{rows.length ? (
|
||||
<div className="space-y-3">
|
||||
{rows.map((row) => {
|
||||
const width = Math.max(Math.min(Number(row.percentage) || 0, 100), 0);
|
||||
return (
|
||||
<div key={row.id} className="rounded-2xl border border-slate-200 bg-slate-50/80 p-3 dark:border-slate-800 dark:bg-slate-950/70">
|
||||
<div className="mb-2 flex items-center justify-between gap-3 text-sm">
|
||||
<span className="font-medium text-slate-900 dark:text-slate-100">{row.name}</span>
|
||||
<span className="text-slate-500 dark:text-slate-400">{formatAmount(row.percentage, lang)}%</span>
|
||||
<div className="space-y-4">
|
||||
<div className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-5">
|
||||
<div className="mb-4 flex items-center justify-between gap-3">
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-white">{labels.userSummaryTitle}</div>
|
||||
<div className="text-xs text-slate-500 dark:text-slate-400">{labels.loading}</div>
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
<LoadingBlock className="h-11 w-full" />
|
||||
<LoadingBlock className="h-11 w-full" />
|
||||
<LoadingBlock className="h-11 w-full" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:justify-end">
|
||||
<LoadingBlock className="h-11 w-full sm:w-40" />
|
||||
<LoadingBlock className="h-11 w-full sm:w-40" />
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 xl:grid-cols-3">
|
||||
<div className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-5">
|
||||
<LoadingBlock className="mb-4 h-5 w-36" />
|
||||
<LoadingBlock className="h-44 w-full" />
|
||||
</div>
|
||||
<div className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-5">
|
||||
<LoadingBlock className="mb-4 h-5 w-36" />
|
||||
<LoadingBlock className="h-44 w-full" />
|
||||
</div>
|
||||
<div className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-5">
|
||||
<LoadingBlock className="mb-4 h-5 w-36" />
|
||||
<LoadingBlock className="h-44 w-full" />
|
||||
</div>
|
||||
<div className="h-2 overflow-hidden rounded-full bg-slate-200 dark:bg-slate-800">
|
||||
<div className="h-full rounded-full bg-sky-500" style={{ width: `${width}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
}
|
||||
|
||||
function BreakdownTable({
|
||||
title,
|
||||
rows,
|
||||
hourPercentages,
|
||||
incomePercentages,
|
||||
labels,
|
||||
lang,
|
||||
financialOnly,
|
||||
}: {
|
||||
title: string;
|
||||
rows: BreakdownRow[];
|
||||
hourPercentages?: PercentageRow[];
|
||||
incomePercentages?: PercentageRow[];
|
||||
labels: Record<string, string>;
|
||||
lang: "en" | "fa";
|
||||
financialOnly: boolean;
|
||||
}) {
|
||||
const hourPercentageById = useMemo(() => percentageMap(hourPercentages), [hourPercentages]);
|
||||
const hourPercentageNumberById = useMemo(() => numericPercentageMap(hourPercentages), [hourPercentages]);
|
||||
const incomePercentageById = useMemo(() => percentageMap(incomePercentages), [incomePercentages]);
|
||||
const sortedRows = useMemo(
|
||||
() =>
|
||||
[...rows].sort((left, right) => {
|
||||
const percentageDelta =
|
||||
(hourPercentageNumberById.get(right.id) || 0) - (hourPercentageNumberById.get(left.id) || 0);
|
||||
if (percentageDelta !== 0) return percentageDelta;
|
||||
if (right.billable_seconds !== left.billable_seconds) {
|
||||
return right.billable_seconds - left.billable_seconds;
|
||||
}
|
||||
return left.name.localeCompare(right.name);
|
||||
}),
|
||||
[hourPercentageNumberById, rows],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-5">
|
||||
<div className="mb-4 text-sm font-semibold text-slate-900 dark:text-white">{title}</div>
|
||||
|
||||
<div className="space-y-3 sm:hidden">
|
||||
{sortedRows.map((row) => (
|
||||
<div key={row.id} className="rounded-2xl border border-slate-200 bg-slate-50/80 p-3 dark:border-slate-800 dark:bg-slate-950/70">
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-white">{row.name}</div>
|
||||
<div className="mt-3 grid grid-cols-2 gap-3 text-xs text-slate-600 dark:text-slate-300">
|
||||
<div>
|
||||
<div className="mb-1 text-[11px] uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.workingHours}</div>
|
||||
<div className="font-medium">{localizeDigits(row.billable_duration, lang)}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="mb-1 text-[11px] uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.hourPercentage}</div>
|
||||
<div className="font-medium">{localizeDigits(hourPercentageById.get(row.id) || "0%", lang)}</div>
|
||||
</div>
|
||||
{!financialOnly ? (
|
||||
<>
|
||||
<div>
|
||||
<div className="mb-1 text-[11px] uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.nonWorkingHours}</div>
|
||||
<div className="font-medium">{localizeDigits(row.non_billable_duration, lang)}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="mb-1 text-[11px] uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.totalHours}</div>
|
||||
<div className="font-medium">{localizeDigits(row.total_duration, lang)}</div>
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
<div className={financialOnly ? "" : "col-span-2"}>
|
||||
<div className="mb-1 text-[11px] uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.totalIncome}</div>
|
||||
<div className="font-medium">{formatMoneyTotals(row.income_totals, lang)}</div>
|
||||
</div>
|
||||
<div className={financialOnly ? "" : "col-span-2"}>
|
||||
<div className="mb-1 text-[11px] uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.incomePercentage}</div>
|
||||
<div className="font-medium">{localizeDigits(incomePercentageById.get(row.id) || "-", lang)}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="hidden overflow-x-auto sm:block">
|
||||
<table className="min-w-full table-auto text-sm">
|
||||
{financialOnly ? (
|
||||
<colgroup>
|
||||
<col />
|
||||
<col style={{ width: "8rem" }} />
|
||||
<col style={{ width: "6.5rem" }} />
|
||||
<col style={{ width: "15rem" }} />
|
||||
<col style={{ width: "7rem" }} />
|
||||
</colgroup>
|
||||
) : (
|
||||
<div className="rounded-2xl border border-dashed border-slate-200 px-4 py-5 text-sm text-slate-500 dark:border-slate-800 dark:text-slate-400">
|
||||
{emptyLabel}
|
||||
</div>
|
||||
<colgroup>
|
||||
<col />
|
||||
<col style={{ width: "8rem" }} />
|
||||
<col style={{ width: "6.5rem" }} />
|
||||
<col style={{ width: "8rem" }} />
|
||||
<col style={{ width: "8rem" }} />
|
||||
<col style={{ width: "15rem" }} />
|
||||
<col style={{ width: "7rem" }} />
|
||||
</colgroup>
|
||||
)}
|
||||
</section>
|
||||
<thead>
|
||||
<tr className="border-b border-slate-200 text-slate-500 dark:border-slate-800 dark:text-slate-400">
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.name}</th>
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.workingHours}</th>
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.hourPercentage}</th>
|
||||
{!financialOnly ? <th className="px-3 py-3 text-start font-medium">{labels.nonWorkingHours}</th> : null}
|
||||
{!financialOnly ? <th className="px-3 py-3 text-start font-medium">{labels.totalHours}</th> : null}
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.totalIncome}</th>
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.incomePercentage}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{sortedRows.map((row) => (
|
||||
<tr key={row.id} className="border-b border-slate-100 last:border-b-0 dark:border-slate-800/80">
|
||||
<td className="px-3 py-3 font-medium text-slate-900 dark:text-slate-100">{row.name}</td>
|
||||
<td className="px-3 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(row.billable_duration, lang)}</td>
|
||||
<td className="px-3 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(hourPercentageById.get(row.id) || "0%", lang)}</td>
|
||||
{!financialOnly ? <td className="px-3 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(row.non_billable_duration, lang)}</td> : null}
|
||||
{!financialOnly ? <td className="px-3 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(row.total_duration, lang)}</td> : null}
|
||||
<td className="px-3 py-3 text-slate-700 dark:text-slate-300">{formatMoneyTotals(row.income_totals, lang)}</td>
|
||||
<td className="px-3 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(incomePercentageById.get(row.id) || "-", lang)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function UserSummaryDetailsModal({
|
||||
summary,
|
||||
report,
|
||||
isLoading,
|
||||
errorMessage,
|
||||
labels,
|
||||
lang,
|
||||
onClose,
|
||||
}: {
|
||||
summary: UserReportSummary | null;
|
||||
report: UserScopedTableReport | null;
|
||||
isLoading: boolean;
|
||||
errorMessage: string | null;
|
||||
labels: Record<string, string>;
|
||||
lang: "en" | "fa";
|
||||
onClose: () => void;
|
||||
}) {
|
||||
if (!summary) return null;
|
||||
|
||||
const activeSummary = report?.user_summary || summary;
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen
|
||||
onClose={onClose}
|
||||
title={labels.userSummaryDetailsTitle.replace("{name}", summary.user.name)}
|
||||
description={labels.userSummaryDetailsDescription}
|
||||
maxWidth="max-w-4xl"
|
||||
maxWidth="max-w-6xl"
|
||||
>
|
||||
<div className="space-y-6">
|
||||
<div className="grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<div className="grid gap-3 sm:grid-cols-3">
|
||||
<div className="rounded-2xl border border-slate-200 bg-slate-50/80 p-4 dark:border-slate-800 dark:bg-slate-950/70">
|
||||
<div className="mb-1 text-xs uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.mobile}</div>
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-slate-100">{localizeDigits(summary.user.mobile, lang)}</div>
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-slate-100">{localizeDigits(activeSummary.user.mobile, lang)}</div>
|
||||
</div>
|
||||
<div className="rounded-2xl border border-slate-200 bg-slate-50/80 p-4 dark:border-slate-800 dark:bg-slate-950/70">
|
||||
<div className="mb-1 text-xs uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.workingHours}</div>
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-slate-100">{localizeDigits(summary.billable_duration, lang)}</div>
|
||||
</div>
|
||||
<div className="rounded-2xl border border-slate-200 bg-slate-50/80 p-4 dark:border-slate-800 dark:bg-slate-950/70">
|
||||
<div className="mb-1 text-xs uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.nonWorkingHours}</div>
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-slate-100">{localizeDigits(summary.non_billable_duration, lang)}</div>
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-slate-100">{localizeDigits(activeSummary.billable_duration, lang)}</div>
|
||||
</div>
|
||||
<div className="rounded-2xl border border-slate-200 bg-slate-50/80 p-4 dark:border-slate-800 dark:bg-slate-950/70">
|
||||
<div className="mb-1 text-xs uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.totalIncome}</div>
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-slate-100">{formatMoneyTotals(summary.income_totals, lang)}</div>
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-slate-100">{formatMoneyTotals(activeSummary.income_totals, lang)}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{errorMessage ? (
|
||||
<div className="rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700 dark:border-rose-500/30 dark:bg-rose-500/10 dark:text-rose-200">
|
||||
{errorMessage}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<section className="space-y-3">
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-white">{labels.rateHistory}</div>
|
||||
<div className="overflow-x-auto rounded-2xl border border-slate-200 dark:border-slate-800">
|
||||
<table className="min-w-full text-sm">
|
||||
<table className="min-w-full table-fixed text-sm">
|
||||
<colgroup>
|
||||
<col />
|
||||
<col style={{ width: "12rem" }} />
|
||||
<col style={{ width: "12rem" }} />
|
||||
<col style={{ width: "10rem" }} />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr className="border-b border-slate-200 bg-slate-50 text-slate-500 dark:border-slate-800 dark:bg-slate-950/70 dark:text-slate-400">
|
||||
<th className="px-4 py-3 text-start font-medium">{labels.hourlyRate}</th>
|
||||
<th className="px-4 py-3 text-start font-medium">{labels.fromDate}</th>
|
||||
<th className="px-4 py-3 text-start font-medium">{labels.toDate}</th>
|
||||
<th className="px-4 py-3 text-start font-medium">{labels.project}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{summary.rate_periods.length ? (
|
||||
summary.rate_periods.map((row, index) => (
|
||||
<tr key={`${row.amount}-${row.currency}-${row.from_date}-${index}`} className="border-b border-slate-100 last:border-b-0 dark:border-slate-800/80">
|
||||
<td className="px-4 py-3 text-slate-700 dark:text-slate-300">{`${formatAmount(row.amount, lang)} ${currencyLabel(row.currency, lang)}`}</td>
|
||||
<td className="px-4 py-3 text-slate-700 dark:text-slate-300">{formatDisplayDate(row.from_date, lang)}</td>
|
||||
<td className="px-4 py-3 text-slate-700 dark:text-slate-300">{formatDisplayDate(row.to_date, lang)}</td>
|
||||
{isLoading ? (
|
||||
Array.from({ length: 3 }).map((_, index) => (
|
||||
<tr key={index} className="border-b border-slate-100 last:border-b-0 dark:border-slate-800/80">
|
||||
<td className="px-4 py-3" colSpan={4}>
|
||||
<LoadingBlock className="h-5 w-full" />
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
) : activeSummary.rate_periods.length ? (
|
||||
activeSummary.rate_periods.map((row, index) => (
|
||||
<tr
|
||||
key={`${row.amount}-${row.currency}-${row.from_date}-${index}`}
|
||||
className="border-b border-slate-100 last:border-b-0 dark:border-slate-800/80"
|
||||
>
|
||||
<td className="px-4 py-3 text-slate-700 dark:text-slate-300">
|
||||
{`${formatAmount(row.amount, lang, row.currency)} ${currencyLabel(row.currency, lang)}`}
|
||||
</td>
|
||||
<td className="whitespace-nowrap px-4 py-3 text-slate-700 dark:text-slate-300">{formatDisplayDate(row.from_date, lang)}</td>
|
||||
<td className="whitespace-nowrap px-4 py-3 text-slate-700 dark:text-slate-300">{formatRateToLabel(row.to_date, lang, labels.now)}</td>
|
||||
<td className="px-4 py-3 text-slate-700 dark:text-slate-300">{row.project_name || "-"}</td>
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td colSpan={3} className="px-4 py-5 text-center text-slate-500 dark:text-slate-400">
|
||||
<td colSpan={4} className="px-4 py-5 text-center text-slate-500 dark:text-slate-400">
|
||||
{labels.noData}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -180,92 +368,135 @@ function UserSummaryDetailsModal({
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div className="grid gap-4 xl:grid-cols-3">
|
||||
<PercentageBreakdownSection title={labels.projectPercentages} rows={summary.project_percentages} lang={lang} emptyLabel={labels.noData} />
|
||||
<PercentageBreakdownSection title={labels.clientPercentages} rows={summary.client_percentages} lang={lang} emptyLabel={labels.noData} />
|
||||
<PercentageBreakdownSection title={labels.tagPercentages} rows={summary.tag_percentages} lang={lang} emptyLabel={labels.noData} />
|
||||
<section className="space-y-3">
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-white">{labels.details}</div>
|
||||
{isLoading ? (
|
||||
<div className="rounded-2xl border border-slate-200 bg-white p-4 dark:border-slate-800 dark:bg-slate-900">
|
||||
<LoadingBlock className="h-44 w-full" />
|
||||
</div>
|
||||
) : report ? (
|
||||
<div className="overflow-x-auto rounded-2xl border border-slate-200 dark:border-slate-800">
|
||||
<table className="min-w-full table-auto text-sm">
|
||||
<colgroup>
|
||||
<col />
|
||||
<col style={{ width: "8rem" }} />
|
||||
<col style={{ width: "8rem" }} />
|
||||
<col style={{ width: "8rem" }} />
|
||||
<col style={{ width: "10rem" }} />
|
||||
<col />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr className="border-b border-slate-200 bg-slate-50 text-slate-500 dark:border-slate-800 dark:bg-slate-950/70 dark:text-slate-400">
|
||||
<th className="px-4 py-3 text-start font-medium">{labels.date}</th>
|
||||
<th className="px-4 py-3 text-start font-medium">{labels.billableHours}</th>
|
||||
<th className="px-4 py-3 text-start font-medium">{labels.nonBillableHours}</th>
|
||||
<th className="px-4 py-3 text-start font-medium">{labels.totalHours}</th>
|
||||
<th className="px-4 py-3 text-start font-medium">{labels.hourlyRate}</th>
|
||||
<th className="px-4 py-3 text-start font-medium">{labels.totalIncome}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{report.days.length ? (
|
||||
report.days.map((day) => (
|
||||
<tr key={day.date} className="border-b border-slate-100 last:border-b-0 dark:border-slate-800/80">
|
||||
<td className="px-4 py-3 text-slate-700 dark:text-slate-300">{formatDisplayDate(day.date, lang)}</td>
|
||||
<td className="px-4 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(day.billable_duration, lang)}</td>
|
||||
<td className="px-4 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(day.non_billable_duration, lang)}</td>
|
||||
<td className="px-4 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(day.total_duration, lang)}</td>
|
||||
<td className="px-4 py-3 text-slate-700 dark:text-slate-300">{formatHourlyRate(day.latest_hourly_rate, lang)}</td>
|
||||
<td className="px-4 py-3 text-slate-700 dark:text-slate-300">{formatMoneyTotals(day.income_totals, lang)}</td>
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td colSpan={6} className="px-4 py-5 text-center text-slate-500 dark:text-slate-400">
|
||||
{labels.noData}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
|
||||
<div className="grid gap-4">
|
||||
<BreakdownTable
|
||||
title={labels.clientsTable}
|
||||
rows={report?.clients || []}
|
||||
hourPercentages={activeSummary.client_percentages}
|
||||
incomePercentages={activeSummary.client_income_percentages}
|
||||
labels={labels}
|
||||
lang={lang}
|
||||
financialOnly
|
||||
/>
|
||||
<BreakdownTable
|
||||
title={labels.projectsTable}
|
||||
rows={report?.projects || []}
|
||||
hourPercentages={activeSummary.project_percentages}
|
||||
incomePercentages={activeSummary.project_income_percentages}
|
||||
labels={labels}
|
||||
lang={lang}
|
||||
financialOnly
|
||||
/>
|
||||
<BreakdownTable
|
||||
title={labels.tagsTable}
|
||||
rows={report?.tags || []}
|
||||
hourPercentages={activeSummary.tag_percentages}
|
||||
incomePercentages={activeSummary.tag_income_percentages}
|
||||
labels={labels}
|
||||
lang={lang}
|
||||
financialOnly
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function BreakdownCards({
|
||||
title,
|
||||
rows,
|
||||
labels,
|
||||
lang,
|
||||
}: {
|
||||
title: string;
|
||||
rows: BreakdownRow[];
|
||||
labels: Record<string, string>;
|
||||
lang: "en" | "fa";
|
||||
}) {
|
||||
return (
|
||||
<div className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-5">
|
||||
<div className="mb-4 text-sm font-semibold text-slate-900 dark:text-white">{title}</div>
|
||||
|
||||
<div className="space-y-3 sm:hidden">
|
||||
{rows.map((row) => (
|
||||
<div key={row.id} className="rounded-2xl border border-slate-200 bg-slate-50/80 p-3 dark:border-slate-800 dark:bg-slate-950/70">
|
||||
<div className="text-sm font-semibold text-slate-900 dark:text-white">{row.name}</div>
|
||||
<div className="mt-3 grid grid-cols-2 gap-3 text-xs text-slate-600 dark:text-slate-300">
|
||||
<div>
|
||||
<div className="mb-1 text-[11px] uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.billableHours}</div>
|
||||
<div className="font-medium">{localizeDigits(row.billable_duration, lang)}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="mb-1 text-[11px] uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.nonBillableHours}</div>
|
||||
<div className="font-medium">{localizeDigits(row.non_billable_duration, lang)}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="mb-1 text-[11px] uppercase tracking-[0.12em] text-slate-400 dark:text-slate-500">{labels.totalIncome}</div>
|
||||
<div className="font-medium">{formatMoneyTotals(row.income_totals, lang)}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="hidden overflow-x-auto sm:block">
|
||||
<table className="min-w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-slate-200 text-slate-500 dark:border-slate-800 dark:text-slate-400">
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.name}</th>
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.billableHours}</th>
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.nonBillableHours}</th>
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.totalIncome}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((row) => (
|
||||
<tr key={row.id} className="border-b border-slate-100 last:border-b-0 dark:border-slate-800/80">
|
||||
<td className="px-3 py-3 font-medium text-slate-900 dark:text-slate-100">{row.name}</td>
|
||||
<td className="px-3 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(row.billable_duration, lang)}</td>
|
||||
<td className="px-3 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(row.non_billable_duration, lang)}</td>
|
||||
<td className="px-3 py-3 text-slate-700 dark:text-slate-300">{formatMoneyTotals(row.income_totals, lang)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function UserSummarySection({
|
||||
rows,
|
||||
onLoadUserSummaryReport,
|
||||
labels,
|
||||
lang,
|
||||
financialOnly,
|
||||
}: {
|
||||
rows: UserReportSummary[];
|
||||
onLoadUserSummaryReport: (userId: string) => Promise<UserScopedTableReport>;
|
||||
labels: Record<string, string>;
|
||||
lang: "en" | "fa";
|
||||
financialOnly: boolean;
|
||||
}) {
|
||||
const [selectedSummary, setSelectedSummary] = useState<UserReportSummary | null>(null);
|
||||
const [reportCache, setReportCache] = useState<Record<string, UserScopedTableReport>>({});
|
||||
const [selectedReport, setSelectedReport] = useState<UserScopedTableReport | null>(null);
|
||||
const [isLoadingDetails, setIsLoadingDetails] = useState(false);
|
||||
const [detailsError, setDetailsError] = useState<string | null>(null);
|
||||
|
||||
if (!rows.length) return null;
|
||||
|
||||
const openSummaryDetails = async (summary: UserReportSummary) => {
|
||||
setSelectedSummary(summary);
|
||||
setDetailsError(null);
|
||||
const cached = reportCache[summary.user.id];
|
||||
if (cached) {
|
||||
setSelectedReport(cached);
|
||||
setIsLoadingDetails(false);
|
||||
return;
|
||||
}
|
||||
setSelectedReport(null);
|
||||
setIsLoadingDetails(true);
|
||||
try {
|
||||
const nextReport = await onLoadUserSummaryReport(summary.user.id);
|
||||
setReportCache((current) => ({ ...current, [summary.user.id]: nextReport }));
|
||||
setSelectedReport(nextReport);
|
||||
} catch {
|
||||
setDetailsError(labels.loadDetailsError);
|
||||
} finally {
|
||||
setIsLoadingDetails(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-5">
|
||||
@@ -277,102 +508,100 @@ function UserSummarySection({
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.name}</th>
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.mobile}</th>
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.workingHours}</th>
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.nonWorkingHours}</th>
|
||||
{!financialOnly ? <th className="px-3 py-3 text-start font-medium">{labels.nonWorkingHours}</th> : null}
|
||||
<th className="px-3 py-3 text-start font-medium">{labels.totalIncome}</th>
|
||||
<th className="px-3 py-3 text-center font-medium">{labels.details}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((row) => (
|
||||
<tr
|
||||
key={row.user.id}
|
||||
className="cursor-pointer border-b border-slate-100 transition hover:bg-slate-50 last:border-b-0 dark:border-slate-800/80 dark:hover:bg-slate-800/40"
|
||||
onClick={() => setSelectedSummary(row)}
|
||||
>
|
||||
<tr key={row.user.id} className="border-b border-slate-100 last:border-b-0 dark:border-slate-800/80">
|
||||
<td className="px-3 py-3 font-medium text-slate-900 dark:text-slate-100">{row.user.name}</td>
|
||||
<td className="px-3 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(row.user.mobile, lang)}</td>
|
||||
<td className="px-3 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(row.billable_duration, lang)}</td>
|
||||
<td className="px-3 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(row.non_billable_duration, lang)}</td>
|
||||
{!financialOnly ? <td className="px-3 py-3 text-slate-700 dark:text-slate-300">{localizeDigits(row.non_billable_duration, lang)}</td> : null}
|
||||
<td className="px-3 py-3 text-slate-700 dark:text-slate-300">{formatMoneyTotals(row.income_totals, lang)}</td>
|
||||
<td className="px-3 py-3 text-center">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void openSummaryDetails(row)}
|
||||
className="inline-flex h-9 w-9 items-center justify-center rounded-xl border border-sky-200 bg-sky-50 text-sky-700 transition hover:bg-sky-100 dark:border-sky-500/30 dark:bg-sky-500/10 dark:text-sky-300 dark:hover:bg-sky-500/20"
|
||||
title={labels.details}
|
||||
>
|
||||
<Eye className="h-4 w-4" />
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<UserSummaryDetailsModal summary={selectedSummary} labels={labels} lang={lang} onClose={() => setSelectedSummary(null)} />
|
||||
<UserSummaryDetailsModal
|
||||
summary={selectedSummary}
|
||||
report={selectedReport}
|
||||
isLoading={isLoadingDetails}
|
||||
errorMessage={detailsError}
|
||||
labels={labels}
|
||||
lang={lang}
|
||||
onClose={() => {
|
||||
setSelectedSummary(null);
|
||||
setSelectedReport(null);
|
||||
setDetailsError(null);
|
||||
setIsLoadingDetails(false);
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function ReportsTablePanel({
|
||||
function SummaryCards({
|
||||
summary,
|
||||
labels,
|
||||
lang,
|
||||
}: {
|
||||
summary: TableReportResponse["summary"];
|
||||
labels: Record<string, string>;
|
||||
lang: "en" | "fa";
|
||||
}) {
|
||||
return (
|
||||
<div className="grid gap-3 sm:grid-cols-3">
|
||||
<div className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500 dark:text-slate-400">{labels.workingHours}</div>
|
||||
<div className="mt-2 text-xl font-bold text-slate-900 dark:text-white sm:text-2xl">{localizeDigits(summary.billable_duration, lang)}</div>
|
||||
</div>
|
||||
<div className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500 dark:text-slate-400">{labels.nonWorkingHours}</div>
|
||||
<div className="mt-2 text-xl font-bold text-slate-900 dark:text-white sm:text-2xl">{localizeDigits(summary.non_billable_duration, lang)}</div>
|
||||
</div>
|
||||
<div className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500 dark:text-slate-400">{labels.totalIncome}</div>
|
||||
<div className="mt-2 text-sm font-semibold leading-6 text-slate-900 dark:text-white sm:text-base">{formatMoneyTotals(summary.income_totals, lang)}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function DailyDetailsSection({
|
||||
data,
|
||||
dayDetails,
|
||||
openDay,
|
||||
onToggleDay,
|
||||
onExport,
|
||||
exportState,
|
||||
labels,
|
||||
lang,
|
||||
}: {
|
||||
data: TableReportResponse | null;
|
||||
data: TableReportResponse;
|
||||
dayDetails: DayDetailsResponse | null;
|
||||
openDay: string | null;
|
||||
onToggleDay: (day: string) => void;
|
||||
onExport: (type: "excel" | "pdf") => void;
|
||||
exportState: {
|
||||
excel: { pending: boolean; cooldownSeconds: number };
|
||||
pdf: { pending: boolean; cooldownSeconds: number };
|
||||
};
|
||||
labels: Record<string, string>;
|
||||
lang: "en" | "fa";
|
||||
}) {
|
||||
const { lang } = useTranslation();
|
||||
|
||||
if (!data) return null;
|
||||
|
||||
const days = Array.isArray(data.days) ? data.days : [];
|
||||
const clients = Array.isArray(data.clients) ? data.clients : [];
|
||||
const projects = Array.isArray(data.projects) ? data.projects : [];
|
||||
const tags = Array.isArray(data.tags) ? data.tags : [];
|
||||
const userSummaries = Array.isArray(data.user_summaries) ? data.user_summaries : [];
|
||||
const entries = Array.isArray(dayDetails?.entries) ? dayDetails.entries : [];
|
||||
const summary = data.summary ?? {
|
||||
billable_duration: "00:00:00",
|
||||
non_billable_duration: "00:00:00",
|
||||
income_totals: [],
|
||||
};
|
||||
const summary = data.summary;
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<UserSummarySection rows={userSummaries} labels={labels} lang={lang} />
|
||||
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:justify-end">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onExport("excel")}
|
||||
disabled={exportState.excel.pending || exportState.excel.cooldownSeconds > 0}
|
||||
className="inline-flex h-11 items-center justify-center gap-2 rounded-2xl border border-emerald-200 bg-emerald-50 px-4 text-sm font-medium text-emerald-700 transition hover:bg-emerald-100 disabled:cursor-not-allowed disabled:opacity-60 dark:border-emerald-500/30 dark:bg-emerald-500/10 dark:text-emerald-300"
|
||||
>
|
||||
<FileSpreadsheet className="h-4 w-4" />
|
||||
{exportState.excel.pending
|
||||
? labels.exportExcel
|
||||
: exportState.excel.cooldownSeconds > 0
|
||||
? `${labels.exportExcel} (${localizeDigits(String(exportState.excel.cooldownSeconds), lang)})`
|
||||
: labels.exportExcel}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onExport("pdf")}
|
||||
disabled={exportState.pdf.pending || exportState.pdf.cooldownSeconds > 0}
|
||||
className="inline-flex h-11 items-center justify-center gap-2 rounded-2xl border border-rose-200 bg-rose-50 px-4 text-sm font-medium text-rose-700 transition hover:bg-rose-100 disabled:cursor-not-allowed disabled:opacity-60 dark:border-rose-500/30 dark:bg-rose-500/10 dark:text-rose-300"
|
||||
>
|
||||
<FileText className="h-4 w-4" />
|
||||
{exportState.pdf.pending
|
||||
? labels.exportPdf
|
||||
: exportState.pdf.cooldownSeconds > 0
|
||||
? `${labels.exportPdf} (${localizeDigits(String(exportState.pdf.cooldownSeconds), lang)})`
|
||||
: labels.exportPdf}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-5">
|
||||
<div className="mb-4 text-sm font-semibold text-slate-900 dark:text-white">{labels.details}</div>
|
||||
|
||||
@@ -420,9 +649,7 @@ export function ReportsTablePanel({
|
||||
<div className="mt-3 space-y-2 border-t border-slate-200 pt-3 dark:border-slate-800">
|
||||
{entries.map((entry) => (
|
||||
<div key={entry.id} className="rounded-xl border border-slate-200 bg-white p-3 dark:border-slate-700 dark:bg-slate-900">
|
||||
<div className="text-sm font-medium text-slate-900 dark:text-slate-100">
|
||||
{entry.description || labels.noDescription}
|
||||
</div>
|
||||
<div className="text-sm font-medium text-slate-900 dark:text-slate-100">{entry.description || labels.noDescription}</div>
|
||||
<div className="mt-1 text-xs text-slate-500 dark:text-slate-400">
|
||||
{entry.project?.name || "-"} • {localizeDigits(entry.duration, lang)}
|
||||
</div>
|
||||
@@ -440,7 +667,7 @@ export function ReportsTablePanel({
|
||||
<div className="mt-3 grid grid-cols-2 gap-3 text-xs text-slate-700 dark:text-slate-300">
|
||||
<div>{labels.billableHours}: {localizeDigits(summary.billable_duration, lang)}</div>
|
||||
<div>{labels.nonBillableHours}: {localizeDigits(summary.non_billable_duration, lang)}</div>
|
||||
<div>{labels.totalIncome}: {formatMoneyTotals(summary.income_totals, lang)}</div>
|
||||
<div className="col-span-2">{labels.totalIncome}: {formatMoneyTotals(summary.income_totals, lang)}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -503,7 +730,7 @@ export function ReportsTablePanel({
|
||||
<td className="px-3 py-3">{labels.total}</td>
|
||||
<td className="px-3 py-3">{localizeDigits(summary.billable_duration, lang)}</td>
|
||||
<td className="px-3 py-3">{localizeDigits(summary.non_billable_duration, lang)}</td>
|
||||
<td className="px-3 py-3">-</td>
|
||||
<td className="px-3 py-3">{localizeDigits("0", lang)}</td>
|
||||
<td className="px-3 py-3">{formatMoneyTotals(summary.income_totals, lang)}</td>
|
||||
<td className="px-3 py-3" />
|
||||
</tr>
|
||||
@@ -511,10 +738,126 @@ export function ReportsTablePanel({
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
<BreakdownCards title={labels.clientsTable} rows={clients} labels={labels} lang={lang} />
|
||||
<BreakdownCards title={labels.projectsTable} rows={projects} labels={labels} lang={lang} />
|
||||
<BreakdownCards title={labels.tagsTable} rows={tags} labels={labels} lang={lang} />
|
||||
export function ReportsTablePanel({
|
||||
data,
|
||||
dayDetails,
|
||||
openDay,
|
||||
onToggleDay,
|
||||
onLoadUserSummaryReport,
|
||||
onExport,
|
||||
exportState,
|
||||
labels,
|
||||
isLoading,
|
||||
}: {
|
||||
data: TableReportResponse | null;
|
||||
dayDetails: DayDetailsResponse | null;
|
||||
openDay: string | null;
|
||||
onToggleDay: (day: string) => void;
|
||||
onLoadUserSummaryReport: (userId: string) => Promise<UserScopedTableReport>;
|
||||
onExport: (type: "excel" | "pdf") => void;
|
||||
exportState: {
|
||||
excel: { pending: boolean; cooldownSeconds: number };
|
||||
pdf: { pending: boolean; cooldownSeconds: number };
|
||||
};
|
||||
labels: Record<string, string>;
|
||||
isLoading: boolean;
|
||||
}) {
|
||||
const { lang } = useTranslation();
|
||||
|
||||
if (isLoading) {
|
||||
return <ReportsTableSkeleton labels={labels} />;
|
||||
}
|
||||
|
||||
if (!data) return null;
|
||||
|
||||
const clients = Array.isArray(data.clients) ? data.clients : [];
|
||||
const projects = Array.isArray(data.projects) ? data.projects : [];
|
||||
const tags = Array.isArray(data.tags) ? data.tags : [];
|
||||
const userSummaries = Array.isArray(data.user_summaries) ? data.user_summaries : [];
|
||||
const isAllUsersScope = Boolean(data.scope?.is_workspace_scope && !data.scope?.user);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<UserSummarySection
|
||||
rows={userSummaries}
|
||||
onLoadUserSummaryReport={onLoadUserSummaryReport}
|
||||
labels={labels}
|
||||
lang={lang}
|
||||
financialOnly={isAllUsersScope}
|
||||
/>
|
||||
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:justify-end">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onExport("excel")}
|
||||
disabled={exportState.excel.pending || exportState.excel.cooldownSeconds > 0}
|
||||
className="inline-flex h-11 items-center justify-center gap-2 rounded-2xl border border-emerald-200 bg-emerald-50 px-4 text-sm font-medium text-emerald-700 transition hover:bg-emerald-100 disabled:cursor-not-allowed disabled:opacity-60 dark:border-emerald-500/30 dark:bg-emerald-500/10 dark:text-emerald-300"
|
||||
>
|
||||
<FileSpreadsheet className="h-4 w-4" />
|
||||
{exportState.excel.pending
|
||||
? labels.exportExcel
|
||||
: exportState.excel.cooldownSeconds > 0
|
||||
? `${labels.exportExcel} (${localizeDigits(String(exportState.excel.cooldownSeconds), lang)})`
|
||||
: labels.exportExcel}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onExport("pdf")}
|
||||
disabled={exportState.pdf.pending || exportState.pdf.cooldownSeconds > 0}
|
||||
className="inline-flex h-11 items-center justify-center gap-2 rounded-2xl border border-rose-200 bg-rose-50 px-4 text-sm font-medium text-rose-700 transition hover:bg-rose-100 disabled:cursor-not-allowed disabled:opacity-60 dark:border-rose-500/30 dark:bg-rose-500/10 dark:text-rose-300"
|
||||
>
|
||||
<FileText className="h-4 w-4" />
|
||||
{exportState.pdf.pending
|
||||
? labels.exportPdf
|
||||
: exportState.pdf.cooldownSeconds > 0
|
||||
? `${labels.exportPdf} (${localizeDigits(String(exportState.pdf.cooldownSeconds), lang)})`
|
||||
: labels.exportPdf}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<SummaryCards summary={data.summary} labels={labels} lang={lang} />
|
||||
|
||||
{!isAllUsersScope ? (
|
||||
<DailyDetailsSection
|
||||
data={data}
|
||||
dayDetails={dayDetails}
|
||||
openDay={openDay}
|
||||
onToggleDay={onToggleDay}
|
||||
labels={labels}
|
||||
lang={lang}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<BreakdownTable
|
||||
title={labels.clientsTable}
|
||||
rows={clients}
|
||||
hourPercentages={data.client_percentages}
|
||||
incomePercentages={data.client_income_percentages}
|
||||
labels={labels}
|
||||
lang={lang}
|
||||
financialOnly={isAllUsersScope}
|
||||
/>
|
||||
<BreakdownTable
|
||||
title={labels.projectsTable}
|
||||
rows={projects}
|
||||
hourPercentages={data.project_percentages}
|
||||
incomePercentages={data.project_income_percentages}
|
||||
labels={labels}
|
||||
lang={lang}
|
||||
financialOnly={isAllUsersScope}
|
||||
/>
|
||||
<BreakdownTable
|
||||
title={labels.tagsTable}
|
||||
rows={tags}
|
||||
hourPercentages={data.tag_percentages}
|
||||
incomePercentages={data.tag_income_percentages}
|
||||
labels={labels}
|
||||
lang={lang}
|
||||
financialOnly={isAllUsersScope}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useState } from "react"
|
||||
import React, { useEffect, useRef, useState } from "react"
|
||||
import DatePicker, { DateObject } from "react-multi-date-picker"
|
||||
import persian from "react-date-object/calendars/persian"
|
||||
import persian_fa from "react-date-object/locales/persian_fa"
|
||||
@@ -18,6 +18,8 @@ interface JalaliDatePickerProps {
|
||||
export default function JalaliDatePicker({ value, onChange, label, disabled, inputClassName = "", placeholder }: JalaliDatePickerProps) {
|
||||
const isFa = document.documentElement.dir === 'rtl'
|
||||
const [isDark, setIsDark] = useState(document.documentElement.classList.contains('dark'))
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const [calendarPosition, setCalendarPosition] = useState("bottom-right")
|
||||
|
||||
// Listen for dark mode changes dynamically (optional but good for UX)
|
||||
useEffect(() => {
|
||||
@@ -37,8 +39,19 @@ export default function JalaliDatePicker({ value, onChange, label, disabled, inp
|
||||
}
|
||||
}
|
||||
|
||||
const updateCalendarPosition = () => {
|
||||
const rect = containerRef.current?.getBoundingClientRect()
|
||||
if (!rect) return
|
||||
|
||||
const estimatedHeight = 340
|
||||
const hasMoreSpaceAbove = rect.top > window.innerHeight - rect.bottom
|
||||
const shouldOpenTop = window.innerHeight - rect.bottom < estimatedHeight && hasMoreSpaceAbove
|
||||
const horizontal = isFa ? "left" : "right"
|
||||
setCalendarPosition(`${shouldOpenTop ? "top" : "bottom"}-${horizontal}`)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
<div ref={containerRef} className="w-full">
|
||||
{label && (
|
||||
<label className="text-sm font-medium dark:text-slate-300 mb-1 block">
|
||||
{label}
|
||||
@@ -52,10 +65,11 @@ export default function JalaliDatePicker({ value, onChange, label, disabled, inp
|
||||
format="YYYY/MM/DD"
|
||||
placeholder={placeholder || "YYYY/MM/DD"}
|
||||
onOpenPickNewDate={false}
|
||||
onOpen={updateCalendarPosition}
|
||||
inputClass={`w-full rounded-md border border-slate-300 bg-transparent px-3 py-2 text-sm dark:border-slate-700 dark:text-white focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed ${inputClassName}`}
|
||||
containerClassName="w-full"
|
||||
className={isDark ? "bg-dark" : ""}
|
||||
calendarPosition="bottom-right"
|
||||
calendarPosition={calendarPosition}
|
||||
fixMainPosition
|
||||
disabled={disabled}
|
||||
/>
|
||||
|
||||
185
src/components/ui/MultiSearchableSelect.tsx
Normal file
185
src/components/ui/MultiSearchableSelect.tsx
Normal file
@@ -0,0 +1,185 @@
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { Check, ChevronDown, Search } from "lucide-react";
|
||||
|
||||
import { Input } from "./input";
|
||||
|
||||
export interface MultiSearchableSelectOption {
|
||||
value: string;
|
||||
label: string;
|
||||
searchText?: string;
|
||||
}
|
||||
|
||||
interface MultiSearchableSelectProps {
|
||||
values: string[];
|
||||
onChange: (values: string[]) => void;
|
||||
options: MultiSearchableSelectOption[];
|
||||
placeholder?: string;
|
||||
searchPlaceholder?: string;
|
||||
emptyLabel?: string;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
buttonClassName?: string;
|
||||
renderValue?: (selectedOptions: MultiSearchableSelectOption[]) => string;
|
||||
}
|
||||
|
||||
export function MultiSearchableSelect({
|
||||
values,
|
||||
onChange,
|
||||
options,
|
||||
placeholder = "",
|
||||
searchPlaceholder,
|
||||
emptyLabel,
|
||||
disabled = false,
|
||||
className = "",
|
||||
buttonClassName = "",
|
||||
renderValue,
|
||||
}: MultiSearchableSelectProps) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [query, setQuery] = useState("");
|
||||
const [dropdownStyle, setDropdownStyle] = useState<React.CSSProperties>({});
|
||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const selectedOptions = useMemo(
|
||||
() => options.filter((option) => values.includes(option.value)),
|
||||
[options, values],
|
||||
);
|
||||
|
||||
const filteredOptions = useMemo(() => {
|
||||
const needle = query.trim().toLowerCase();
|
||||
if (!needle) return options;
|
||||
return options.filter((option) =>
|
||||
`${option.label} ${option.searchText || ""}`.toLowerCase().includes(needle),
|
||||
);
|
||||
}, [options, query]);
|
||||
|
||||
const displayValue = useMemo(() => {
|
||||
if (!selectedOptions.length) return placeholder;
|
||||
if (renderValue) return renderValue(selectedOptions);
|
||||
return selectedOptions.map((option) => option.label).join(", ");
|
||||
}, [placeholder, renderValue, selectedOptions]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (
|
||||
buttonRef.current &&
|
||||
!buttonRef.current.contains(event.target as Node) &&
|
||||
dropdownRef.current &&
|
||||
!dropdownRef.current.contains(event.target as Node)
|
||||
) {
|
||||
setIsOpen(false);
|
||||
setQuery("");
|
||||
}
|
||||
};
|
||||
|
||||
if (isOpen) {
|
||||
document.addEventListener("mousedown", handleClickOutside);
|
||||
}
|
||||
|
||||
return () => document.removeEventListener("mousedown", handleClickOutside);
|
||||
}, [isOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen || !buttonRef.current) return;
|
||||
|
||||
const rect = buttonRef.current.getBoundingClientRect();
|
||||
const spaceBelow = window.innerHeight - rect.bottom;
|
||||
const dropdownHeight = 320;
|
||||
const shouldOpenUp = spaceBelow < dropdownHeight && rect.top > spaceBelow;
|
||||
|
||||
setDropdownStyle({
|
||||
position: "fixed",
|
||||
top: shouldOpenUp ? `${rect.top - 4}px` : `${rect.bottom + 4}px`,
|
||||
left: `${rect.left}px`,
|
||||
width: `${rect.width}px`,
|
||||
transform: shouldOpenUp ? "translateY(-100%)" : "none",
|
||||
zIndex: 99999,
|
||||
});
|
||||
}, [isOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleScrollOrResize = () => setIsOpen(false);
|
||||
if (isOpen) {
|
||||
window.addEventListener("resize", handleScrollOrResize);
|
||||
window.addEventListener("scroll", handleScrollOrResize, true);
|
||||
}
|
||||
return () => {
|
||||
window.removeEventListener("resize", handleScrollOrResize);
|
||||
window.removeEventListener("scroll", handleScrollOrResize, true);
|
||||
};
|
||||
}, [isOpen]);
|
||||
|
||||
const toggleValue = (value: string) => {
|
||||
if (values.includes(value)) {
|
||||
onChange(values.filter((item) => item !== value));
|
||||
return;
|
||||
}
|
||||
onChange([...values, value]);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`relative ${className}`}>
|
||||
<button
|
||||
ref={buttonRef}
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={() => !disabled && setIsOpen((current) => !current)}
|
||||
className={`flex w-full items-center justify-between rounded-md border border-slate-300 bg-white px-3 py-2 text-sm text-slate-700 outline-none transition focus:ring-2 focus:ring-blue-500 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-300 ${buttonClassName}`}
|
||||
>
|
||||
<span className="truncate text-start">{displayValue}</span>
|
||||
<ChevronDown className={`h-4 w-4 shrink-0 transition-transform ${isOpen ? "rotate-180" : ""}`} />
|
||||
</button>
|
||||
|
||||
{isOpen &&
|
||||
createPortal(
|
||||
<div
|
||||
ref={dropdownRef}
|
||||
style={dropdownStyle}
|
||||
className="overflow-hidden rounded-md border border-slate-200 bg-white shadow-lg dark:border-slate-700 dark:bg-slate-800"
|
||||
>
|
||||
<div className="border-b border-slate-100 p-2 dark:border-slate-700">
|
||||
<div className="relative">
|
||||
<Search className="pointer-events-none absolute inset-y-0 left-3 my-auto h-4 w-4 text-slate-400 rtl:left-auto rtl:right-3" />
|
||||
<Input
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder={searchPlaceholder || "Search..."}
|
||||
className="h-9 pl-9 rtl:pl-3 rtl:pr-9"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="max-h-64 overflow-y-auto py-1">
|
||||
{filteredOptions.map((option) => {
|
||||
const isSelected = values.includes(option.value);
|
||||
return (
|
||||
<button
|
||||
key={option.value}
|
||||
type="button"
|
||||
onClick={() => toggleValue(option.value)}
|
||||
className={`flex w-full items-center justify-between px-3 py-2 text-left text-sm transition hover:bg-slate-100 dark:hover:bg-slate-700 ${
|
||||
isSelected
|
||||
? "bg-blue-50 font-medium text-blue-600 dark:bg-blue-900/30 dark:text-blue-300"
|
||||
: "text-slate-700 dark:text-slate-300"
|
||||
}`}
|
||||
>
|
||||
<span className="truncate">{option.label}</span>
|
||||
{isSelected ? <Check className="h-4 w-4 shrink-0" /> : <span className="h-4 w-4 shrink-0" />}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
|
||||
{filteredOptions.length === 0 && (
|
||||
<div className="px-3 py-3 text-sm text-slate-500 dark:text-slate-400">
|
||||
{emptyLabel || "No results"}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>,
|
||||
document.body,
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
595
src/components/workspaces/WorkspaceMemberImportModal.tsx
Normal file
595
src/components/workspaces/WorkspaceMemberImportModal.tsx
Normal file
@@ -0,0 +1,595 @@
|
||||
import { Fragment, useMemo, useRef, useState } from "react";
|
||||
import { Dialog, Transition } from "@headlessui/react";
|
||||
import { AlertCircle, CheckCircle2, Download, FileSpreadsheet, UploadCloud, XCircle } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import * as XLSX from "xlsx";
|
||||
|
||||
import {
|
||||
commitWorkspaceMemberImport,
|
||||
validateWorkspaceMemberImport,
|
||||
type WorkspaceMemberImportResultRow,
|
||||
type WorkspaceMemberImportRowInput,
|
||||
type WorkspaceMemberImportValidationResponse,
|
||||
} from "../../api/workspaces";
|
||||
import type { PriceUnit } from "../../api/rates";
|
||||
import { Button } from "../ui/button";
|
||||
|
||||
type ImportLabels = {
|
||||
title?: string;
|
||||
description?: string;
|
||||
uploadTitle?: string;
|
||||
uploadDescription?: string;
|
||||
sampleCsv?: string;
|
||||
sampleTsv?: string;
|
||||
sampleTxt?: string;
|
||||
sampleXlsx?: string;
|
||||
validate?: string;
|
||||
validating?: string;
|
||||
import?: string;
|
||||
importing?: string;
|
||||
close?: string;
|
||||
chooseFile?: string;
|
||||
selectedFile?: string;
|
||||
validRows?: string;
|
||||
invalidRows?: string;
|
||||
totalRows?: string;
|
||||
line?: string;
|
||||
mobile?: string;
|
||||
user?: string;
|
||||
role?: string;
|
||||
hourlyRate?: string;
|
||||
currency?: string;
|
||||
status?: string;
|
||||
messages?: string;
|
||||
valid?: string;
|
||||
invalid?: string;
|
||||
noRows?: string;
|
||||
localErrors?: string;
|
||||
success?: string;
|
||||
parseFailed?: string;
|
||||
missingMobile?: string;
|
||||
duplicateMobile?: string;
|
||||
invalidRole?: string;
|
||||
invalidRate?: string;
|
||||
rateCurrencyPair?: string;
|
||||
tooManyRows?: string;
|
||||
};
|
||||
|
||||
type ParsedRow = WorkspaceMemberImportRowInput & {
|
||||
local_messages: string[];
|
||||
};
|
||||
|
||||
type Props = {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
workspaceId: string;
|
||||
priceUnits: PriceUnit[];
|
||||
labels: ImportLabels;
|
||||
onImported: () => void | Promise<void>;
|
||||
};
|
||||
|
||||
const MAX_ROWS = 500;
|
||||
const ROLE_VALUES = new Set(["admin", "member", "guest"]);
|
||||
const DIGIT_MAP: Record<string, string> = {
|
||||
"۰": "0",
|
||||
"۱": "1",
|
||||
"۲": "2",
|
||||
"۳": "3",
|
||||
"۴": "4",
|
||||
"۵": "5",
|
||||
"۶": "6",
|
||||
"۷": "7",
|
||||
"۸": "8",
|
||||
"۹": "9",
|
||||
"٠": "0",
|
||||
"١": "1",
|
||||
"٢": "2",
|
||||
"٣": "3",
|
||||
"٤": "4",
|
||||
"٥": "5",
|
||||
"٦": "6",
|
||||
"٧": "7",
|
||||
"٨": "8",
|
||||
"٩": "9",
|
||||
};
|
||||
|
||||
const normalizeDigits = (value: unknown) =>
|
||||
String(value ?? "")
|
||||
.replace(/[۰-۹٠-٩]/g, (digit) => DIGIT_MAP[digit] || digit)
|
||||
.trim();
|
||||
|
||||
const normalizeHeader = (value: unknown) =>
|
||||
String(value ?? "")
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/[\s-]+/g, "_");
|
||||
|
||||
const parseDelimited = (text: string, delimiter: string) => {
|
||||
const rows: string[][] = [];
|
||||
let row: string[] = [];
|
||||
let cell = "";
|
||||
let inQuotes = false;
|
||||
|
||||
for (let index = 0; index < text.length; index += 1) {
|
||||
const char = text[index];
|
||||
const next = text[index + 1];
|
||||
|
||||
if (char === '"' && inQuotes && next === '"') {
|
||||
cell += '"';
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (char === '"') {
|
||||
inQuotes = !inQuotes;
|
||||
continue;
|
||||
}
|
||||
if (char === delimiter && !inQuotes) {
|
||||
row.push(cell.trim());
|
||||
cell = "";
|
||||
continue;
|
||||
}
|
||||
if ((char === "\n" || char === "\r") && !inQuotes) {
|
||||
if (char === "\r" && next === "\n") {
|
||||
index += 1;
|
||||
}
|
||||
row.push(cell.trim());
|
||||
if (row.some((item) => item !== "")) {
|
||||
rows.push(row);
|
||||
}
|
||||
row = [];
|
||||
cell = "";
|
||||
continue;
|
||||
}
|
||||
cell += char;
|
||||
}
|
||||
|
||||
row.push(cell.trim());
|
||||
if (row.some((item) => item !== "")) {
|
||||
rows.push(row);
|
||||
}
|
||||
return rows;
|
||||
};
|
||||
|
||||
const detectDelimiter = (text: string, extension: string) => {
|
||||
if (extension === "tsv") return "\t";
|
||||
const firstLine = text.split(/\r?\n/).find((line) => line.trim()) || "";
|
||||
const candidates = [",", ";", "\t", "|"];
|
||||
return candidates
|
||||
.map((delimiter) => ({
|
||||
delimiter,
|
||||
count: firstLine.split(delimiter).length,
|
||||
}))
|
||||
.sort((a, b) => b.count - a.count)[0]?.delimiter || ",";
|
||||
};
|
||||
|
||||
const tableRowsToObjects = (rows: string[][]) => {
|
||||
const [headers = [], ...body] = rows;
|
||||
const normalizedHeaders = headers.map(normalizeHeader);
|
||||
return body.map((row, index) => {
|
||||
const record: Record<string, string> = {};
|
||||
normalizedHeaders.forEach((header, headerIndex) => {
|
||||
if (header) {
|
||||
record[header] = row[headerIndex] || "";
|
||||
}
|
||||
});
|
||||
return { line: index + 2, record };
|
||||
});
|
||||
};
|
||||
|
||||
const buildParsedRows = (records: Array<{ line: number; record: Record<string, string> }>, labels: ImportLabels) => {
|
||||
const seenMobiles = new Set<string>();
|
||||
return records
|
||||
.filter(({ record }) => Object.values(record).some((value) => String(value || "").trim()))
|
||||
.map(({ line, record }) => {
|
||||
const mobile = normalizeDigits(record.mobile);
|
||||
const role = normalizeDigits(record.role || "member").toLowerCase() as ParsedRow["role"];
|
||||
const hourlyRate = normalizeDigits(record.hourly_rate);
|
||||
const currency = normalizeDigits(record.currency).toUpperCase();
|
||||
const localMessages: string[] = [];
|
||||
|
||||
if (!mobile) {
|
||||
localMessages.push(labels.missingMobile || "Mobile is required.");
|
||||
} else if (seenMobiles.has(mobile)) {
|
||||
localMessages.push(labels.duplicateMobile || "This mobile appears more than once.");
|
||||
} else {
|
||||
seenMobiles.add(mobile);
|
||||
}
|
||||
|
||||
if (!ROLE_VALUES.has(role || "member")) {
|
||||
localMessages.push(labels.invalidRole || "Role must be admin, member, or guest.");
|
||||
}
|
||||
|
||||
if (hourlyRate && Number.isNaN(Number(hourlyRate.replace(/,/g, "")))) {
|
||||
localMessages.push(labels.invalidRate || "Hourly rate must be a valid number.");
|
||||
}
|
||||
if (hourlyRate && Number(hourlyRate.replace(/,/g, "")) <= 0) {
|
||||
localMessages.push(labels.invalidRate || "Hourly rate must be greater than zero.");
|
||||
}
|
||||
if (Boolean(hourlyRate) !== Boolean(currency)) {
|
||||
localMessages.push(labels.rateCurrencyPair || "Hourly rate and currency must be provided together.");
|
||||
}
|
||||
|
||||
return {
|
||||
line,
|
||||
mobile,
|
||||
role: ROLE_VALUES.has(role || "") ? role : "member",
|
||||
hourly_rate: hourlyRate ? hourlyRate.replace(/,/g, "") : "",
|
||||
currency,
|
||||
local_messages: localMessages,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const downloadBlob = (blob: Blob, filename: string) => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const sampleRows = [
|
||||
["mobile", "role", "hourly_rate", "currency"],
|
||||
["09999999999", "member", "150000", "IRT"],
|
||||
["09999999998", "guest", "", ""],
|
||||
];
|
||||
|
||||
export function WorkspaceMemberImportModal({
|
||||
isOpen,
|
||||
onClose,
|
||||
workspaceId,
|
||||
priceUnits,
|
||||
labels,
|
||||
onImported,
|
||||
}: Props) {
|
||||
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const [fileName, setFileName] = useState("");
|
||||
const [parsedRows, setParsedRows] = useState<ParsedRow[]>([]);
|
||||
const [parseError, setParseError] = useState("");
|
||||
const [validation, setValidation] = useState<WorkspaceMemberImportValidationResponse | null>(null);
|
||||
const [isValidating, setIsValidating] = useState(false);
|
||||
const [isImporting, setIsImporting] = useState(false);
|
||||
|
||||
const localInvalidCount = parsedRows.filter((row) => row.local_messages.length > 0).length;
|
||||
const canValidate = parsedRows.length > 0 && localInvalidCount === 0 && !isValidating;
|
||||
const canCommit = Boolean(validation?.can_commit && validation.import_token) && !isImporting;
|
||||
|
||||
const currencyCodes = useMemo(
|
||||
() => priceUnits.map((unit) => unit.code).filter(Boolean).join(", "),
|
||||
[priceUnits],
|
||||
);
|
||||
|
||||
const reset = () => {
|
||||
setFileName("");
|
||||
setParsedRows([]);
|
||||
setParseError("");
|
||||
setValidation(null);
|
||||
setIsValidating(false);
|
||||
setIsImporting(false);
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = "";
|
||||
}
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
reset();
|
||||
onClose();
|
||||
};
|
||||
|
||||
const parseFile = async (file: File) => {
|
||||
setParseError("");
|
||||
setValidation(null);
|
||||
setFileName(file.name);
|
||||
const extension = file.name.split(".").pop()?.toLowerCase() || "";
|
||||
try {
|
||||
let records: Array<{ line: number; record: Record<string, string> }> = [];
|
||||
if (extension === "xlsx") {
|
||||
const buffer = await file.arrayBuffer();
|
||||
const workbook = XLSX.read(buffer, { type: "array" });
|
||||
const sheet = workbook.Sheets[workbook.SheetNames[0]];
|
||||
const rows = XLSX.utils.sheet_to_json<string[]>(sheet, { header: 1, defval: "" });
|
||||
records = tableRowsToObjects(rows);
|
||||
} else if (["csv", "tsv", "txt"].includes(extension)) {
|
||||
const text = await file.text();
|
||||
const delimiter = detectDelimiter(text, extension);
|
||||
records = tableRowsToObjects(parseDelimited(text, delimiter));
|
||||
} else {
|
||||
throw new Error("Unsupported file type.");
|
||||
}
|
||||
|
||||
const hasMobileHeader = records.length > 0 && Object.prototype.hasOwnProperty.call(records[0].record, "mobile");
|
||||
if (!hasMobileHeader && records.length === 0) {
|
||||
throw new Error(labels.noRows || "No rows were found in this file.");
|
||||
}
|
||||
if (!hasMobileHeader) {
|
||||
throw new Error(labels.missingMobile || "The file must include a mobile column.");
|
||||
}
|
||||
|
||||
const nextRows = buildParsedRows(records, labels);
|
||||
if (nextRows.length > MAX_ROWS) {
|
||||
setParseError(labels.tooManyRows || `Import is limited to ${MAX_ROWS} rows.`);
|
||||
setParsedRows([]);
|
||||
return;
|
||||
}
|
||||
setParsedRows(nextRows);
|
||||
} catch (error) {
|
||||
setParsedRows([]);
|
||||
setParseError(error instanceof Error ? error.message : labels.parseFailed || "Failed to parse the file.");
|
||||
}
|
||||
};
|
||||
|
||||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = event.target.files?.[0];
|
||||
if (file) {
|
||||
void parseFile(file);
|
||||
}
|
||||
};
|
||||
|
||||
const handleValidate = async () => {
|
||||
setIsValidating(true);
|
||||
setValidation(null);
|
||||
try {
|
||||
const response = await validateWorkspaceMemberImport({
|
||||
workspace: workspaceId,
|
||||
rows: parsedRows.map(({ local_messages: _localMessages, ...row }) => row),
|
||||
});
|
||||
setValidation(response);
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : labels.parseFailed || "Failed to validate member import");
|
||||
} finally {
|
||||
setIsValidating(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleImport = async () => {
|
||||
if (!validation?.import_token) return;
|
||||
setIsImporting(true);
|
||||
try {
|
||||
await commitWorkspaceMemberImport({
|
||||
workspace: workspaceId,
|
||||
import_token: validation.import_token,
|
||||
});
|
||||
toast.success(labels.success || "Members imported successfully.");
|
||||
await onImported();
|
||||
handleClose();
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : "Failed to import members");
|
||||
} finally {
|
||||
setIsImporting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const downloadSample = (format: "csv" | "tsv" | "txt" | "xlsx") => {
|
||||
if (format === "xlsx") {
|
||||
const worksheet = XLSX.utils.aoa_to_sheet(sampleRows);
|
||||
const workbook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, "members");
|
||||
const output = XLSX.write(workbook, { bookType: "xlsx", type: "array" });
|
||||
downloadBlob(
|
||||
new Blob([output], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }),
|
||||
"workspace-members-sample.xlsx",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const delimiter = format === "tsv" ? "\t" : ",";
|
||||
const content = sampleRows.map((row) => row.join(delimiter)).join("\n");
|
||||
downloadBlob(new Blob([content], { type: "text/plain;charset=utf-8" }), `workspace-members-sample.${format}`);
|
||||
};
|
||||
|
||||
const displayedRows: WorkspaceMemberImportResultRow[] =
|
||||
validation?.rows ||
|
||||
parsedRows.map((row) => ({
|
||||
line: row.line,
|
||||
mobile: row.mobile,
|
||||
role: row.role || "member",
|
||||
hourly_rate: row.hourly_rate || "",
|
||||
currency: row.currency || "",
|
||||
status: row.local_messages.length ? "invalid" : "valid",
|
||||
action: row.local_messages.length ? "none" : "add_member",
|
||||
user: null,
|
||||
messages: row.local_messages,
|
||||
}));
|
||||
|
||||
return (
|
||||
<Transition appear show={isOpen} as={Fragment}>
|
||||
<Dialog as="div" className="relative z-50" onClose={handleClose}>
|
||||
<Transition.Child
|
||||
as={Fragment}
|
||||
enter="ease-out duration-200"
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leave="ease-in duration-150"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<div className="fixed inset-0 bg-slate-950/50 backdrop-blur-sm" />
|
||||
</Transition.Child>
|
||||
|
||||
<div className="fixed inset-0 overflow-y-auto">
|
||||
<div className="flex min-h-full items-center justify-center p-4">
|
||||
<Transition.Child
|
||||
as={Fragment}
|
||||
enter="ease-out duration-200"
|
||||
enterFrom="opacity-0 scale-95"
|
||||
enterTo="opacity-100 scale-100"
|
||||
leave="ease-in duration-150"
|
||||
leaveFrom="opacity-100 scale-100"
|
||||
leaveTo="opacity-0 scale-95"
|
||||
>
|
||||
<Dialog.Panel className="w-full max-w-5xl overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-2xl dark:border-slate-800 dark:bg-slate-950">
|
||||
<div className="border-b border-slate-200 px-6 py-5 dark:border-slate-800">
|
||||
<Dialog.Title className="text-lg font-semibold text-slate-950 dark:text-white">
|
||||
{labels.title || "Import members"}
|
||||
</Dialog.Title>
|
||||
<p className="mt-1 text-sm text-slate-500 dark:text-slate-400">
|
||||
{labels.description ||
|
||||
"Upload a file with mobile, role, hourly_rate, and currency columns. Mobile is required; role defaults to member."}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-5 p-6 lg:grid-cols-[320px_minmax(0,1fr)]">
|
||||
<div className="space-y-4">
|
||||
<div className="rounded-2xl border border-dashed border-slate-300 bg-slate-50 p-5 text-center dark:border-slate-700 dark:bg-slate-900/60">
|
||||
<UploadCloud className="mx-auto h-9 w-9 text-blue-500" />
|
||||
<h3 className="mt-3 text-sm font-semibold text-slate-900 dark:text-white">
|
||||
{labels.uploadTitle || "Upload file"}
|
||||
</h3>
|
||||
<p className="mt-1 text-xs leading-5 text-slate-500 dark:text-slate-400">
|
||||
{labels.uploadDescription || "CSV, TSV, TXT, or XLSX. The first row must be headers."}
|
||||
</p>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept=".csv,.tsv,.txt,.xlsx"
|
||||
className="hidden"
|
||||
onChange={handleFileChange}
|
||||
/>
|
||||
<Button type="button" className="mt-4 gap-2" onClick={() => fileInputRef.current?.click()}>
|
||||
<FileSpreadsheet className="h-4 w-4" />
|
||||
{labels.chooseFile || "Choose file"}
|
||||
</Button>
|
||||
{fileName ? (
|
||||
<p className="mt-3 truncate text-xs text-slate-500 dark:text-slate-400">
|
||||
{(labels.selectedFile || "Selected file")}: {fileName}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="rounded-2xl border border-slate-200 p-4 dark:border-slate-800">
|
||||
<p className="text-xs font-medium uppercase tracking-wide text-slate-500 dark:text-slate-400">
|
||||
{labels.currency || "Currency"}: {currencyCodes || "-"}
|
||||
</p>
|
||||
<div className="mt-3 grid grid-cols-2 gap-2">
|
||||
<Button type="button" variant="secondary" size="sm" className="gap-1" onClick={() => downloadSample("csv")}>
|
||||
<Download className="h-3.5 w-3.5" />
|
||||
{labels.sampleCsv || "CSV sample"}
|
||||
</Button>
|
||||
<Button type="button" variant="secondary" size="sm" className="gap-1" onClick={() => downloadSample("tsv")}>
|
||||
<Download className="h-3.5 w-3.5" />
|
||||
{labels.sampleTsv || "TSV sample"}
|
||||
</Button>
|
||||
<Button type="button" variant="secondary" size="sm" className="gap-1" onClick={() => downloadSample("txt")}>
|
||||
<Download className="h-3.5 w-3.5" />
|
||||
{labels.sampleTxt || "TXT sample"}
|
||||
</Button>
|
||||
<Button type="button" variant="secondary" size="sm" className="gap-1" onClick={() => downloadSample("xlsx")}>
|
||||
<Download className="h-3.5 w-3.5" />
|
||||
{labels.sampleXlsx || "XLSX sample"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{parseError ? (
|
||||
<div className="flex gap-2 rounded-xl border border-red-200 bg-red-50 p-3 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/40 dark:text-red-300">
|
||||
<AlertCircle className="mt-0.5 h-4 w-4 shrink-0" />
|
||||
{parseError}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="min-w-0 space-y-4">
|
||||
<div className="grid gap-3 sm:grid-cols-3">
|
||||
<div className="rounded-xl bg-slate-100 p-3 dark:bg-slate-900">
|
||||
<p className="text-xs text-slate-500">{labels.totalRows || "Total rows"}</p>
|
||||
<p className="text-lg font-semibold text-slate-900 dark:text-white">
|
||||
{validation?.summary.total ?? parsedRows.length}
|
||||
</p>
|
||||
</div>
|
||||
<div className="rounded-xl bg-emerald-50 p-3 dark:bg-emerald-950/30">
|
||||
<p className="text-xs text-emerald-700 dark:text-emerald-300">{labels.validRows || "Valid rows"}</p>
|
||||
<p className="text-lg font-semibold text-emerald-700 dark:text-emerald-300">
|
||||
{validation?.summary.valid ?? parsedRows.length - localInvalidCount}
|
||||
</p>
|
||||
</div>
|
||||
<div className="rounded-xl bg-red-50 p-3 dark:bg-red-950/30">
|
||||
<p className="text-xs text-red-700 dark:text-red-300">{labels.invalidRows || "Invalid rows"}</p>
|
||||
<p className="text-lg font-semibold text-red-700 dark:text-red-300">
|
||||
{validation?.summary.invalid ?? localInvalidCount}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{localInvalidCount > 0 && !validation ? (
|
||||
<div className="rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-800 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-300">
|
||||
{labels.localErrors || "Fix local file errors before backend validation."}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="max-h-[440px] overflow-auto rounded-xl border border-slate-200 dark:border-slate-800">
|
||||
<table className="min-w-full divide-y divide-slate-200 text-sm dark:divide-slate-800">
|
||||
<thead className="sticky top-0 bg-slate-100 text-xs uppercase text-slate-500 dark:bg-slate-900 dark:text-slate-400">
|
||||
<tr>
|
||||
<th className="px-3 py-2 text-start">{labels.line || "Line"}</th>
|
||||
<th className="px-3 py-2 text-start">{labels.mobile || "Mobile"}</th>
|
||||
<th className="px-3 py-2 text-start">{labels.user || "User"}</th>
|
||||
<th className="px-3 py-2 text-start">{labels.role || "Role"}</th>
|
||||
<th className="px-3 py-2 text-start">{labels.hourlyRate || "Hourly rate"}</th>
|
||||
<th className="px-3 py-2 text-start">{labels.currency || "Currency"}</th>
|
||||
<th className="px-3 py-2 text-start">{labels.status || "Status"}</th>
|
||||
<th className="px-3 py-2 text-start">{labels.messages || "Messages"}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100 dark:divide-slate-800">
|
||||
{displayedRows.length ? (
|
||||
displayedRows.map((row) => (
|
||||
<tr key={`${row.line}-${row.mobile}`} className="bg-white dark:bg-slate-950">
|
||||
<td className="px-3 py-2 text-slate-600 dark:text-slate-300">{row.line ?? "-"}</td>
|
||||
<td className="px-3 py-2 font-medium text-slate-900 dark:text-white">{row.mobile || "-"}</td>
|
||||
<td className="px-3 py-2 text-slate-600 dark:text-slate-300">{row.user?.full_name || "-"}</td>
|
||||
<td className="px-3 py-2 text-slate-600 dark:text-slate-300">{row.role || "member"}</td>
|
||||
<td className="px-3 py-2 text-slate-600 dark:text-slate-300">{row.hourly_rate || "-"}</td>
|
||||
<td className="px-3 py-2 text-slate-600 dark:text-slate-300">{row.currency || "-"}</td>
|
||||
<td className="px-3 py-2">
|
||||
{row.status === "valid" ? (
|
||||
<span className="inline-flex items-center gap-1 rounded-full bg-emerald-100 px-2 py-1 text-xs font-medium text-emerald-700 dark:bg-emerald-500/15 dark:text-emerald-300">
|
||||
<CheckCircle2 className="h-3 w-3" />
|
||||
{labels.valid || "Valid"}
|
||||
</span>
|
||||
) : (
|
||||
<span className="inline-flex items-center gap-1 rounded-full bg-red-100 px-2 py-1 text-xs font-medium text-red-700 dark:bg-red-500/15 dark:text-red-300">
|
||||
<XCircle className="h-3 w-3" />
|
||||
{labels.invalid || "Invalid"}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="min-w-[220px] px-3 py-2 text-xs text-slate-500 dark:text-slate-400">
|
||||
{row.messages.length ? row.messages.join(" | ") : "-"}
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td colSpan={8} className="px-3 py-10 text-center text-slate-500 dark:text-slate-400">
|
||||
{labels.noRows || "No rows loaded yet."}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-3 border-t border-slate-200 px-6 py-4 dark:border-slate-800 sm:flex-row sm:justify-end">
|
||||
<Button type="button" variant="secondary" onClick={handleClose}>
|
||||
{labels.close || "Close"}
|
||||
</Button>
|
||||
<Button type="button" variant="secondary" disabled={!canValidate} onClick={handleValidate}>
|
||||
{isValidating ? labels.validating || "Validating..." : labels.validate || "Validate file"}
|
||||
</Button>
|
||||
<Button type="button" disabled={!canCommit} onClick={handleImport}>
|
||||
{isImporting ? labels.importing || "Importing..." : labels.import || "Import members"}
|
||||
</Button>
|
||||
</div>
|
||||
</Dialog.Panel>
|
||||
</Transition.Child>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
</Transition>
|
||||
);
|
||||
}
|
||||
236
src/content/about.json
Normal file
236
src/content/about.json
Normal file
@@ -0,0 +1,236 @@
|
||||
{
|
||||
"en": {
|
||||
"eyebrow": "About Qlockify",
|
||||
"hero": {
|
||||
"title": "A focused operating layer for time, work, and accountability.",
|
||||
"accent": "Qlockify turns daily work into context your team can trust.",
|
||||
"description": "Qlockify is built for teams that need more than a stopwatch. It connects time entries to workspaces, projects, clients, tags, rates, exports, and activity logs so time becomes useful operational data."
|
||||
},
|
||||
"sections": [
|
||||
{
|
||||
"title": "Why it exists",
|
||||
"description": "Most teams lose context between the moment work happens and the moment reports are reviewed. Qlockify keeps that context attached from the first timer click to the final exported report."
|
||||
},
|
||||
{
|
||||
"title": "What it protects",
|
||||
"description": "The product is designed to reduce missing billable work, unclear project history, manual spreadsheet cleanup, and undocumented workspace changes."
|
||||
},
|
||||
{
|
||||
"title": "How it feels",
|
||||
"description": "The interface stays minimal because time tracking should not become another heavy workflow. Teams can record work quickly while managers still receive structured, reviewable data."
|
||||
}
|
||||
],
|
||||
"principles": [
|
||||
{
|
||||
"title": "Capture first",
|
||||
"description": "Recording work should be fast enough to happen at the source, with project and billing context attached immediately."
|
||||
},
|
||||
{
|
||||
"title": "Explain every change",
|
||||
"description": "Workspace roles, rates, access changes, and report actions should remain visible instead of disappearing into chat or memory."
|
||||
},
|
||||
{
|
||||
"title": "Make reports usable",
|
||||
"description": "Reports should be ready for review, export, and decision-making without rebuilding them in spreadsheets."
|
||||
}
|
||||
],
|
||||
"capabilities": [
|
||||
{
|
||||
"title": "Time tracking",
|
||||
"description": "Run timers, adjust historical entries, and keep work tied to the correct project, client, and tags."
|
||||
},
|
||||
{
|
||||
"title": "Workspace control",
|
||||
"description": "Manage members, roles, project access, and rates without making everyday users deal with unnecessary complexity."
|
||||
},
|
||||
{
|
||||
"title": "Operational reports",
|
||||
"description": "Review daily summaries, project distribution, billable work, and exportable reports for management or client review."
|
||||
},
|
||||
{
|
||||
"title": "Activity history",
|
||||
"description": "Keep a clear trail of important actions so teams can understand what changed and when."
|
||||
}
|
||||
],
|
||||
"audience": [
|
||||
"Agencies",
|
||||
"Consulting teams",
|
||||
"Product teams",
|
||||
"Operations teams",
|
||||
"Client-service businesses"
|
||||
],
|
||||
"trust": [
|
||||
"Data is organized around workspaces so each team can keep its own operational context.",
|
||||
"Project access and user roles help limit what each person can see or use.",
|
||||
"Exports and logs are designed to make review easier, not to hide important details."
|
||||
],
|
||||
"contact": {
|
||||
"eyebrow": "Contact",
|
||||
"title": "Need help or want to talk about Qlockify?",
|
||||
"description": "Send a note or reach out through the support channels below. Contact form submissions are stored securely so the team can review and follow up.",
|
||||
"formTitle": "Send a note",
|
||||
"fields": {
|
||||
"firstName": "First name",
|
||||
"lastName": "Last name",
|
||||
"email": "Email",
|
||||
"mobile": "Mobile",
|
||||
"message": "Message"
|
||||
},
|
||||
"placeholders": {
|
||||
"firstName": "Your first name",
|
||||
"lastName": "Your last name",
|
||||
"email": "you@example.com",
|
||||
"mobile": "09...",
|
||||
"message": "Tell us what you need help with..."
|
||||
},
|
||||
"submit": "Send message",
|
||||
"submitting": "Sending...",
|
||||
"success": "Your message was saved. We will contact you soon.",
|
||||
"error": "Could not send your message. Please try again.",
|
||||
"channels": [
|
||||
{
|
||||
"label": "Telegram support",
|
||||
"value": "qlockify_support",
|
||||
"href": "https://t.me/qlockify_support"
|
||||
},
|
||||
{
|
||||
"label": "Telegram channel",
|
||||
"value": "qlockify",
|
||||
"href": "https://t.me/qlockify"
|
||||
},
|
||||
{
|
||||
"label": "Support email",
|
||||
"value": "qlockify@gmail.com",
|
||||
"href": "mailto:qlockify@gmail.com"
|
||||
},
|
||||
{
|
||||
"label": "Mobile (message or call)",
|
||||
"value": "09938228438",
|
||||
"href": "tel:09938228438"
|
||||
}
|
||||
]
|
||||
},
|
||||
"cta": {
|
||||
"title": "Start with one workspace and make time easier to explain.",
|
||||
"description": "Open Qlockify, track a real workday, and compare the report with the way your team reviews work today.",
|
||||
"button": "Open Qlockify"
|
||||
}
|
||||
},
|
||||
"fa": {
|
||||
"eyebrow": "درباره Qlockify",
|
||||
"hero": {
|
||||
"title": "یک لایه عملیاتی متمرکز برای زمان، کار و پاسخگویی.",
|
||||
"accent": "Qlockify کار روزانه را به دادهای تبدیل میکند که تیم بتواند به آن اعتماد کند.",
|
||||
"description": "Qlockify برای تیمهایی ساخته شده که فقط یک تایمر ساده نمیخواهند. این محصول ورودیهای زمان را به ورکاسپیس، پروژه، مشتری، تگ، نرخ، خروجی گزارش و لاگ فعالیتها وصل میکند تا زمان به داده عملیاتی قابل استفاده تبدیل شود."
|
||||
},
|
||||
"sections": [
|
||||
{
|
||||
"title": "چرا ساخته شده است",
|
||||
"description": "بیشتر تیمها بین لحظه انجام کار و زمان مرور گزارشها، بستر و جزئیات مهم را از دست میدهند. Qlockify این بستر را از اولین کلیک تایمر تا گزارش خروجی نهایی نگه میدارد."
|
||||
},
|
||||
{
|
||||
"title": "چه چیزی را حفظ میکند",
|
||||
"description": "محصول برای کاهش کارکرد ثبتنشده، تاریخچه نامشخص پروژه، پاکسازی دستی فایلهای گزارش و تغییرات ثبتنشده در ورکاسپیس طراحی شده است."
|
||||
},
|
||||
{
|
||||
"title": "چه حسی دارد",
|
||||
"description": "رابط کاربری مینیمال میماند، چون ردیابی زمان نباید خودش به یک فرایند سنگین تبدیل شود. تیم میتواند سریع کار را ثبت کند و مدیر همچنان داده ساختارمند و قابل بررسی داشته باشد."
|
||||
}
|
||||
],
|
||||
"principles": [
|
||||
{
|
||||
"title": "اول ثبت دقیق",
|
||||
"description": "ثبت کار باید آنقدر سریع باشد که در همان لحظه انجام شود و پروژه و بستر مالی همان ابتدا به آن وصل شود."
|
||||
},
|
||||
{
|
||||
"title": "هر تغییر قابل توضیح",
|
||||
"description": "نقشها، نرخها، دسترسی پروژهها و عملیات گزارش باید قابل مشاهده بمانند، نه اینکه در چت یا حافظه افراد گم شوند."
|
||||
},
|
||||
{
|
||||
"title": "گزارش قابل استفاده",
|
||||
"description": "گزارش باید برای بررسی، خروجی گرفتن و تصمیمگیری آماده باشد، بدون اینکه دوباره در فایلهای اکسل ساخته شود."
|
||||
}
|
||||
],
|
||||
"capabilities": [
|
||||
{
|
||||
"title": "ردیابی زمان",
|
||||
"description": "تایمر اجرا کنید، ورودیهای گذشته را اصلاح کنید و کار را به پروژه، مشتری و تگ درست وصل نگه دارید."
|
||||
},
|
||||
{
|
||||
"title": "کنترل ورکاسپیس",
|
||||
"description": "اعضا، نقشها، دسترسی پروژهها و نرخها را مدیریت کنید، بدون اینکه کاربران روزمره درگیر پیچیدگی اضافه شوند."
|
||||
},
|
||||
{
|
||||
"title": "گزارش عملیاتی",
|
||||
"description": "خلاصه روزانه، توزیع پروژهها، کارکرد قابل صورتحساب و گزارشهای خروجی را برای مدیریت یا مرور مشتری بررسی کنید."
|
||||
},
|
||||
{
|
||||
"title": "تاریخچه فعالیتها",
|
||||
"description": "رد روشنی از عملیات مهم نگه دارید تا تیم بداند چه چیزی، چه زمانی و توسط چه کسی تغییر کرده است."
|
||||
}
|
||||
],
|
||||
"audience": [
|
||||
"آژانسها",
|
||||
"تیمهای مشاوره",
|
||||
"تیمهای محصول",
|
||||
"تیمهای عملیات",
|
||||
"کسبوکارهای مشتریمحور"
|
||||
],
|
||||
"trust": [
|
||||
"دادهها حول ورکاسپیس سازماندهی میشوند تا هر تیم بستر عملیاتی خودش را داشته باشد.",
|
||||
"دسترسی پروژه و نقش کاربران کمک میکند هر فرد فقط چیزی را ببیند یا استفاده کند که باید.",
|
||||
"خروجیها و لاگها برای سادهتر کردن بررسی طراحی شدهاند، نه برای پنهان کردن جزئیات مهم."
|
||||
],
|
||||
"contact": {
|
||||
"eyebrow": "تماس",
|
||||
"title": "کمک میخواهید یا میخواهید درباره Qlockify صحبت کنیم؟",
|
||||
"description": "یک پیام بفرستید یا از مسیرهای پشتیبانی زیر با ما در ارتباط باشید. پیامهای فرم تماس ذخیره میشوند تا تیم بتواند آنها را بررسی و پیگیری کند.",
|
||||
"formTitle": "ارسال پیام",
|
||||
"fields": {
|
||||
"firstName": "نام",
|
||||
"lastName": "نام خانوادگی",
|
||||
"email": "ایمیل",
|
||||
"mobile": "موبایل",
|
||||
"message": "پیام"
|
||||
},
|
||||
"placeholders": {
|
||||
"firstName": "نام شما",
|
||||
"lastName": "نام خانوادگی شما",
|
||||
"email": "you@example.com",
|
||||
"mobile": "09...",
|
||||
"message": "بگویید برای چه چیزی به کمک نیاز دارید..."
|
||||
},
|
||||
"submit": "ارسال پیام",
|
||||
"submitting": "در حال ارسال...",
|
||||
"success": "پیام شما ثبت شد. بهزودی با شما تماس میگیریم.",
|
||||
"error": "ارسال پیام انجام نشد. لطفا دوباره تلاش کنید.",
|
||||
"channels": [
|
||||
{
|
||||
"label": "پشتیبانی تلگرام",
|
||||
"value": "qlockify_support",
|
||||
"href": "https://t.me/qlockify_support"
|
||||
},
|
||||
{
|
||||
"label": "کانال تلگرام",
|
||||
"value": "qlockify",
|
||||
"href": "https://t.me/qlockify"
|
||||
},
|
||||
{
|
||||
"label": "ایمیل پشتیبانی",
|
||||
"value": "qlockify@gmail.com",
|
||||
"href": "mailto:qlockify@gmail.com"
|
||||
},
|
||||
{
|
||||
"label": "موبایل (پیام یا تماس)",
|
||||
"value": "09938228438",
|
||||
"href": "tel:09938228438"
|
||||
}
|
||||
]
|
||||
},
|
||||
"cta": {
|
||||
"title": "با یک ورکاسپیس شروع کنید و توضیح زمان را سادهتر کنید.",
|
||||
"description": "Qlockify را باز کنید، یک روز کاری واقعی را ثبت کنید و گزارش آن را با روش فعلی مرور کار در تیم مقایسه کنید.",
|
||||
"button": "باز کردن Qlockify"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ interface User {
|
||||
last_name: string;
|
||||
email?: string;
|
||||
profile_picture?: string | null;
|
||||
is_demo?: boolean;
|
||||
demo_expires_at?: string | null;
|
||||
}
|
||||
|
||||
interface AppContextType {
|
||||
|
||||
@@ -30,6 +30,8 @@ export const WorkspaceProvider = ({ children }: { children: ReactNode }) => {
|
||||
const [workspaces, setWorkspaces] = useState<Workspace[]>([])
|
||||
const [activeWorkspace, setActiveWorkspaceState] = useState<Workspace | null>(null)
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [hasLoadedWorkspaces, setHasLoadedWorkspaces] = useState(false)
|
||||
const [workspaceLoadError, setWorkspaceLoadError] = useState(false)
|
||||
const [newWorkspaceName, setNewWorkspaceName] = useState("")
|
||||
const [isCreatingFirst, setIsCreatingFirst] = useState(false)
|
||||
|
||||
@@ -38,16 +40,20 @@ export const WorkspaceProvider = ({ children }: { children: ReactNode }) => {
|
||||
|
||||
const refreshWorkspaces = async () => {
|
||||
if (!isAuthenticated || isRateLimitActive()) {
|
||||
setHasLoadedWorkspaces(false)
|
||||
setWorkspaceLoadError(false)
|
||||
setIsLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
setIsLoading(true)
|
||||
setWorkspaceLoadError(false)
|
||||
const response = await fetchWorkspaces()
|
||||
|
||||
const data = Array.isArray(response) ? response : (response?.results || [])
|
||||
setWorkspaces(data)
|
||||
setHasLoadedWorkspaces(true)
|
||||
|
||||
if (data.length > 0) {
|
||||
const storedId = localStorage.getItem("activeWorkspaceId")
|
||||
@@ -64,6 +70,8 @@ export const WorkspaceProvider = ({ children }: { children: ReactNode }) => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
setWorkspaceLoadError(true)
|
||||
setHasLoadedWorkspaces(false)
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
@@ -71,6 +79,8 @@ export const WorkspaceProvider = ({ children }: { children: ReactNode }) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated || rateLimited) {
|
||||
setHasLoadedWorkspaces(false)
|
||||
setWorkspaceLoadError(false)
|
||||
setIsLoading(false)
|
||||
return
|
||||
}
|
||||
@@ -92,6 +102,8 @@ export const WorkspaceProvider = ({ children }: { children: ReactNode }) => {
|
||||
setIsCreatingFirst(true)
|
||||
const newWs = await createWorkspace({ name, description: "" })
|
||||
setWorkspaces((prev) => [...prev, newWs])
|
||||
setHasLoadedWorkspaces(true)
|
||||
setWorkspaceLoadError(false)
|
||||
setActiveWorkspace(newWs)
|
||||
toast.success(t.workspace?.successCreate || t.workspace?.toast?.successCreate || "Workspace created!")
|
||||
} catch (error) {
|
||||
@@ -103,8 +115,29 @@ export const WorkspaceProvider = ({ children }: { children: ReactNode }) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (!rateLimited && !isLoading && isAuthenticated && workspaceLoadError) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-slate-50 dark:bg-slate-900 px-4">
|
||||
<div className="w-full max-w-md bg-white dark:bg-slate-800 p-8 rounded-xl shadow-lg border border-slate-200 dark:border-slate-700">
|
||||
<h2 className="text-2xl font-bold text-slate-900 dark:text-white mb-2">
|
||||
{t.workspace?.fetchError || "Failed to load workspace data"}
|
||||
</h2>
|
||||
<p className="text-slate-600 dark:text-slate-400 mb-6">
|
||||
{t.workspace?.loadErrorDescription || "The backend service may be unavailable. Please try again in a moment."}
|
||||
</p>
|
||||
<Button
|
||||
onClick={() => void refreshWorkspaces()}
|
||||
className="w-full bg-blue-600 hover:bg-blue-700 text-white"
|
||||
>
|
||||
{t.workspace?.retry || "Try again"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Force workspace creation if authenticated but none exist
|
||||
if (!rateLimited && !isLoading && isAuthenticated && workspaces.length === 0) {
|
||||
if (!rateLimited && !isLoading && isAuthenticated && hasLoadedWorkspaces && workspaces.length === 0) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-slate-50 dark:bg-slate-900 px-4">
|
||||
<div className="w-full max-w-md bg-white dark:bg-slate-800 p-8 rounded-xl shadow-lg border border-slate-200 dark:border-slate-700">
|
||||
|
||||
76
src/lib/money.ts
Normal file
76
src/lib/money.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
const PERSIAN_DIGITS = "۰۱۲۳۴۵۶۷۸۹";
|
||||
|
||||
export const localizeDigits = (value: string, lang: "en" | "fa") =>
|
||||
lang === "fa" ? value.replace(/\d/g, (digit) => PERSIAN_DIGITS[Number(digit)] || digit) : value;
|
||||
|
||||
export const currencyLabel = (currency: string, lang: "en" | "fa") => {
|
||||
const normalized = currency.toUpperCase();
|
||||
if (lang !== "fa") return normalized;
|
||||
return (
|
||||
{
|
||||
USD: "دلار آمریکا",
|
||||
EUR: "یورو",
|
||||
GBP: "پوند",
|
||||
IRR: "ریال",
|
||||
IRT: "تومان",
|
||||
AED: "درهم",
|
||||
TRY: "لیر",
|
||||
}[normalized] || normalized
|
||||
);
|
||||
};
|
||||
|
||||
export const shouldTrimCurrencyDecimals = (currency?: string | null) => {
|
||||
const normalized = (currency || "").toUpperCase();
|
||||
return normalized === "IRR" || normalized === "IRT";
|
||||
};
|
||||
|
||||
export const formatAmountForCurrency = (
|
||||
value: string,
|
||||
currency: string | null | undefined,
|
||||
lang: "en" | "fa",
|
||||
) => {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) return trimmed;
|
||||
const normalizedValue = trimmed.replace(/,/g, "");
|
||||
const numeric = Number(normalizedValue);
|
||||
if (Number.isNaN(numeric)) return localizeDigits(trimmed, lang);
|
||||
|
||||
const [integerPart, fractionalPart] = normalizedValue.split(".");
|
||||
const grouped = Math.abs(Number(integerPart)).toLocaleString("en-US");
|
||||
const signed = normalizedValue.startsWith("-") ? `-${grouped}` : grouped;
|
||||
let formatted = signed;
|
||||
|
||||
if (fractionalPart) {
|
||||
const nextFraction = shouldTrimCurrencyDecimals(currency)
|
||||
? ""
|
||||
: fractionalPart.replace(/0+$/, "");
|
||||
if (nextFraction) {
|
||||
formatted = `${formatted}.${nextFraction}`;
|
||||
}
|
||||
}
|
||||
|
||||
return localizeDigits(formatted, lang);
|
||||
};
|
||||
|
||||
export const formatMoneyTotals = (
|
||||
totals: { currency: string; amount: string }[],
|
||||
lang: "en" | "fa",
|
||||
) => {
|
||||
if (!totals.length) return "-";
|
||||
return totals
|
||||
.map((item) => `${formatAmountForCurrency(item.amount, item.currency, lang)} ${currencyLabel(item.currency, lang)}`)
|
||||
.join(" | ");
|
||||
};
|
||||
|
||||
export const formatRateDisplay = (
|
||||
rate: { amount?: string | null; hourly_rate?: string | null; currency: string; price_unit?: { code?: string; local_name?: string; name?: string } | null } | null,
|
||||
lang: "en" | "fa",
|
||||
) => {
|
||||
if (!rate) return "-";
|
||||
const amount = rate.amount ?? rate.hourly_rate ?? "";
|
||||
const unitLabel =
|
||||
lang === "fa"
|
||||
? rate.price_unit?.local_name || rate.price_unit?.code || currencyLabel(rate.currency, lang)
|
||||
: rate.price_unit?.code || rate.currency;
|
||||
return `${formatAmountForCurrency(amount, rate.currency, lang)} ${unitLabel}`;
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
export const SESSION_CHANGED_EVENT = "auth_session_changed"
|
||||
const DEMO_EXPIRES_AT_KEY = "demoExpiresAt"
|
||||
|
||||
export const getAccessToken = () => localStorage.getItem("accessToken")
|
||||
|
||||
@@ -14,8 +15,21 @@ export const setSessionTokens = (accessToken: string, refreshToken: string) => {
|
||||
emitSessionChanged()
|
||||
}
|
||||
|
||||
export const setDemoSessionMeta = (expiresAt: string | null | undefined) => {
|
||||
if (expiresAt) {
|
||||
localStorage.setItem(DEMO_EXPIRES_AT_KEY, expiresAt)
|
||||
} else {
|
||||
localStorage.removeItem(DEMO_EXPIRES_AT_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
export const getDemoSessionExpiresAt = () => localStorage.getItem(DEMO_EXPIRES_AT_KEY)
|
||||
|
||||
export const isDemoSession = () => !!getDemoSessionExpiresAt()
|
||||
|
||||
export const clearSessionTokens = () => {
|
||||
localStorage.removeItem("accessToken")
|
||||
localStorage.removeItem("refreshToken")
|
||||
localStorage.removeItem(DEMO_EXPIRES_AT_KEY)
|
||||
emitSessionChanged()
|
||||
}
|
||||
|
||||
@@ -283,6 +283,47 @@ export const en = {
|
||||
statsGuests: "Guests",
|
||||
membersSectionTitle: "Members",
|
||||
membersSectionSubtitle: "People in this workspace and their current roles.",
|
||||
projectRateHint: "Project-specific user rates can be managed from the Projects page. Open a project and use its access modal to set a custom rate that overrides the workspace rate for that project.",
|
||||
memberImport: {
|
||||
button: "Import members",
|
||||
title: "Import members",
|
||||
description: "Upload a file with mobile, role, hourly_rate, and currency columns. Mobile is required; role defaults to member.",
|
||||
uploadTitle: "Upload member file",
|
||||
uploadDescription: "CSV, TSV, TXT, or XLSX. The first row must contain headers.",
|
||||
sampleCsv: "CSV sample",
|
||||
sampleTsv: "TSV sample",
|
||||
sampleTxt: "TXT sample",
|
||||
sampleXlsx: "XLSX sample",
|
||||
validate: "Validate file",
|
||||
validating: "Validating...",
|
||||
import: "Import members",
|
||||
importing: "Importing...",
|
||||
chooseFile: "Choose file",
|
||||
selectedFile: "Selected file",
|
||||
validRows: "Valid rows",
|
||||
invalidRows: "Invalid rows",
|
||||
totalRows: "Total rows",
|
||||
line: "Line",
|
||||
mobile: "Mobile",
|
||||
user: "User",
|
||||
role: "Role",
|
||||
hourlyRate: "Hourly rate",
|
||||
currency: "Currency",
|
||||
status: "Status",
|
||||
messages: "Messages",
|
||||
valid: "Valid",
|
||||
invalid: "Invalid",
|
||||
noRows: "No rows loaded yet.",
|
||||
localErrors: "Fix local file errors before backend validation.",
|
||||
success: "Members imported successfully.",
|
||||
parseFailed: "Failed to parse the file.",
|
||||
missingMobile: "Mobile is required.",
|
||||
duplicateMobile: "This mobile appears more than once.",
|
||||
invalidRole: "Role must be admin, member, or guest.",
|
||||
invalidRate: "Hourly rate must be a valid positive number.",
|
||||
rateCurrencyPair: "Hourly rate and currency must be provided together.",
|
||||
tooManyRows: "Import is limited to 500 rows.",
|
||||
},
|
||||
membersLocked: "Only owners and admins can view the full member list.",
|
||||
manageMembers: "Manage members",
|
||||
mobileNumber: "Mobile Number",
|
||||
@@ -300,6 +341,8 @@ export const en = {
|
||||
createdSuccess: "Workspace created successfully",
|
||||
updatedSuccess: "Workspace updated successfully",
|
||||
fetchError: "Failed to load workspace data",
|
||||
loadErrorDescription: "The backend service may be unavailable. Please try again in a moment.",
|
||||
retry: "Try again",
|
||||
remove: "Remove",
|
||||
noUsersFound: "No user found",
|
||||
selectRole: "Select Role",
|
||||
@@ -400,6 +443,7 @@ export const en = {
|
||||
demo: "Product demo",
|
||||
features: "Core capabilities",
|
||||
workflow: "How it works",
|
||||
about: "About us",
|
||||
},
|
||||
actions: {
|
||||
switchToEnglish: "English",
|
||||
@@ -410,6 +454,7 @@ export const en = {
|
||||
startNow: "Start tracking with control",
|
||||
watchDemo: "See the product demo",
|
||||
readTerms: "Read terms",
|
||||
readAbout: "About Qlockify",
|
||||
},
|
||||
hero: {
|
||||
titleTop: "Turn every working hour into a reliable operating signal.",
|
||||
@@ -480,6 +525,15 @@ export const en = {
|
||||
finalCtaDescription:
|
||||
"Open the app, create a workspace, and see how fast your reporting discipline improves when the product stops leaking context.",
|
||||
},
|
||||
demo: {
|
||||
badge: "Demo environment",
|
||||
starting: "Preparing demo...",
|
||||
started: "Demo environment is ready.",
|
||||
startError: "Could not start the demo environment.",
|
||||
expiresAt: "Expires at",
|
||||
resetAction: "Reset demo",
|
||||
reset: "Fresh demo environment is ready.",
|
||||
},
|
||||
|
||||
ordering: {
|
||||
createdAtDesc: "Newest First",
|
||||
@@ -526,11 +580,11 @@ export const en = {
|
||||
clearClientFilters: "Clear filters",
|
||||
namePlaceholder: "Project name...",
|
||||
teamMembers: "Team Members",
|
||||
manageAccess: "Manage access",
|
||||
accessModalTitle: "Project access",
|
||||
accessModalDescription: "Grant or revoke project access for workspace members.",
|
||||
accessMemberLabel: "Member",
|
||||
accessNoMembers: "No eligible members were found.",
|
||||
manageAccess: "Projects & Rates",
|
||||
accessModalTitle: "Projects & Rates",
|
||||
accessModalDescription: "Manage project access for members and guests, and set project-specific rates for any workspace user.",
|
||||
accessMemberLabel: "User",
|
||||
accessNoMembers: "No workspace users were found.",
|
||||
accessNoProjects: "No projects found.",
|
||||
accessSelectVisible: "Select all visible",
|
||||
accessClearSelection: "Clear selection",
|
||||
@@ -543,6 +597,7 @@ export const en = {
|
||||
accessRevokeSuccess: "Project access revoked.",
|
||||
accessLoadError: "Failed to load project access state.",
|
||||
accessSaveError: "Failed to update project access.",
|
||||
implicitAccessHint: "Owners and admins always have access to all projects. You can still set project-specific rate overrides here.",
|
||||
creator: "Creator",
|
||||
addUser: "Add user by mobile",
|
||||
addFromWorkspace: "Add from workspace",
|
||||
@@ -595,8 +650,17 @@ export const en = {
|
||||
rates: {
|
||||
workspaceSectionTitle: "Workspace User Rates",
|
||||
projectSectionTitle: "Project User Rates",
|
||||
myRatesTitle: "My rates",
|
||||
myRatesHint: "Project-specific rates override your workspace rate in the current workspace.",
|
||||
workspaceRate: "Workspace rate",
|
||||
workspaceRateHint: "This is your default rate unless a project-specific rate overrides it.",
|
||||
projectOverride: "Project override",
|
||||
projectOverrides: "Project overrides",
|
||||
accessibleProjects: "Accessible projects",
|
||||
workspaceFallbackProjects: "Using workspace rate",
|
||||
projectOverrideHint: "Only projects with custom overrides are listed here. Other accessible projects use your workspace rate.",
|
||||
projectOverrideEmpty: "You do not have any project-specific rate overrides in this workspace.",
|
||||
myRatesEmpty: "No rates are available for this workspace yet.",
|
||||
inheritsWorkspaceRate: "Inherits workspace rate",
|
||||
noRate: "No rate",
|
||||
hourlyRatePlaceholder: "0.00",
|
||||
@@ -618,6 +682,7 @@ export const en = {
|
||||
description: (workspaceName: string) => `Track time inside ${workspaceName}`,
|
||||
selectWorkspace: "Please select a workspace first.",
|
||||
addEntry: "Add Entry",
|
||||
addManualEntry: "Add manual entry",
|
||||
startTimer: "Start Timer",
|
||||
stopTimer: "Stop Timer",
|
||||
timerRunning: "Timer Running",
|
||||
@@ -632,6 +697,7 @@ export const en = {
|
||||
noEntriesSearch: "Try adjusting your search query or filters.",
|
||||
emptyDescription: "No description",
|
||||
createTitle: "Add Time Entry",
|
||||
manualCreateTitle: "Add Manual Time Entry",
|
||||
startTitle: "Start Timer",
|
||||
editTitle: "Edit Time Entry",
|
||||
createSuccess: "Time entry created successfully.",
|
||||
@@ -677,6 +743,10 @@ export const en = {
|
||||
noProjectsFoundLabel: "No projects found.",
|
||||
deletedProjectLabel: "Deleted project",
|
||||
deletedTagLabel: "Deleted tag",
|
||||
startRequiredError: "Start date and time are required.",
|
||||
endRequiredError: "End date and time must both be filled.",
|
||||
invalidEndTimeError: "End time is invalid.",
|
||||
endBeforeStartError: "End must be after start.",
|
||||
},
|
||||
|
||||
reports: {
|
||||
@@ -726,6 +796,9 @@ export const en = {
|
||||
userSummaryDetailsDescription: "Review the selected user's rate history and time distribution.",
|
||||
rateHistory: "Rate history",
|
||||
percentage: "Percentage",
|
||||
hourPercentage: "Hour %",
|
||||
incomePercentage: "Income %",
|
||||
now: "Now",
|
||||
chartTitle: "Activity chart",
|
||||
totalSeconds: "Total seconds",
|
||||
exportExcel: "Export Excel",
|
||||
|
||||
@@ -285,6 +285,47 @@ export const fa = {
|
||||
membersSectionTitle: "اعضا",
|
||||
membersSectionSubtitle: "اعضای این ورکاسپیس و نقش فعلی آنها.",
|
||||
membersLocked: "فهرست کامل اعضا فقط برای مالک و ادمین قابل مشاهده است.",
|
||||
projectRateHint: "برای هر کاربر میتوانید از صفحه پروژهها و داخل پنجره دسترسی پروژه، یک نرخ اختصاصی برای همان پروژه تعریف کنید تا روی نرخ ساعتی ورکاسپیس اولویت داشته باشد.",
|
||||
memberImport: {
|
||||
button: "درونریزی اعضا",
|
||||
title: "درونریزی اعضا",
|
||||
description: "فایلی با ستونهای mobile، role، hourly_rate و currency بارگذاری کنید. موبایل الزامی است و نقش در صورت خالی بودن عضو در نظر گرفته میشود.",
|
||||
uploadTitle: "بارگذاری فایل اعضا",
|
||||
uploadDescription: "فرمتهای CSV، TSV، TXT یا XLSX پشتیبانی میشوند. ردیف اول باید عنوان ستونها باشد.",
|
||||
sampleCsv: "نمونه CSV",
|
||||
sampleTsv: "نمونه TSV",
|
||||
sampleTxt: "نمونه TXT",
|
||||
sampleXlsx: "نمونه XLSX",
|
||||
validate: "اعتبارسنجی فایل",
|
||||
validating: "در حال اعتبارسنجی...",
|
||||
import: "درونریزی اعضا",
|
||||
importing: "در حال درونریزی...",
|
||||
chooseFile: "انتخاب فایل",
|
||||
selectedFile: "فایل انتخابشده",
|
||||
validRows: "ردیفهای معتبر",
|
||||
invalidRows: "ردیفهای نامعتبر",
|
||||
totalRows: "کل ردیفها",
|
||||
line: "ردیف",
|
||||
mobile: "موبایل",
|
||||
user: "کاربر",
|
||||
role: "نقش",
|
||||
hourlyRate: "نرخ ساعتی",
|
||||
currency: "واحد پول",
|
||||
status: "وضعیت",
|
||||
messages: "پیامها",
|
||||
valid: "معتبر",
|
||||
invalid: "نامعتبر",
|
||||
noRows: "هنوز ردیفی بارگذاری نشده است.",
|
||||
localErrors: "قبل از اعتبارسنجی سمت سرور، خطاهای فایل را اصلاح کنید.",
|
||||
success: "اعضا با موفقیت درونریزی شدند.",
|
||||
parseFailed: "خواندن فایل ناموفق بود.",
|
||||
missingMobile: "موبایل الزامی است.",
|
||||
duplicateMobile: "این موبایل بیش از یک بار در فایل آمده است.",
|
||||
invalidRole: "نقش باید admin، member یا guest باشد.",
|
||||
invalidRate: "نرخ ساعتی باید عددی معتبر و بزرگتر از صفر باشد.",
|
||||
rateCurrencyPair: "نرخ ساعتی و واحد پول باید با هم وارد شوند.",
|
||||
tooManyRows: "درونریزی به ۵۰۰ ردیف محدود است.",
|
||||
},
|
||||
manageMembers: "مدیریت اعضا",
|
||||
mobileNumber: "شماره تماس",
|
||||
youLabel: "شما",
|
||||
@@ -301,6 +342,8 @@ export const fa = {
|
||||
createdSuccess: "ورکاسپیس با موفقیت ایجاد شد",
|
||||
updatedSuccess: "ورکاسپیس با موفقیت ویرایش شد",
|
||||
fetchError: "خطا در دریافت اطلاعات ورکاسپیس",
|
||||
loadErrorDescription: "ممکن است سرویس بکاند در دسترس نباشد. لطفاً چند لحظه بعد دوباره تلاش کنید.",
|
||||
retry: "تلاش دوباره",
|
||||
remove: "حذف",
|
||||
noUsersFound: "کاربری یافت نشد",
|
||||
selectRole: "انتخاب نقش",
|
||||
@@ -397,6 +440,7 @@ export const fa = {
|
||||
demo: "دموی محصول",
|
||||
features: "قابلیتها",
|
||||
workflow: "فرآیند کار",
|
||||
about: "درباره ما",
|
||||
},
|
||||
actions: {
|
||||
switchToEnglish: "English",
|
||||
@@ -407,6 +451,7 @@ export const fa = {
|
||||
startNow: "شروع با کنترل کامل",
|
||||
watchDemo: "مشاهده دموی محصول",
|
||||
readTerms: "مطالعه قوانین",
|
||||
readAbout: "درباره Qlockify",
|
||||
},
|
||||
hero: {
|
||||
titleTop: "هر ساعت کاری را به یک سیگنال عملیاتی قابل اعتماد تبدیل کنید.",
|
||||
@@ -477,6 +522,15 @@ export const fa = {
|
||||
finalCtaDescription:
|
||||
"اپ را باز کنید، ورکاسپیس بسازید و ببینید وقتی محصول نشت بستر را متوقف میکند، انضباط گزارشدهی چقدر سریع بهتر میشود.",
|
||||
},
|
||||
demo: {
|
||||
badge: "محیط دمو",
|
||||
starting: "در حال آمادهسازی دمو...",
|
||||
started: "محیط دمو آماده شد.",
|
||||
startError: "امکان ساخت محیط دمو وجود ندارد.",
|
||||
expiresAt: "زمان انقضا",
|
||||
resetAction: "شروع دوباره دمو",
|
||||
reset: "محیط دموی تازه آماده شد.",
|
||||
},
|
||||
|
||||
ordering: {
|
||||
createdAtDesc: "جدیدترین",
|
||||
@@ -490,7 +544,7 @@ export const fa = {
|
||||
title: "پروژهها",
|
||||
description: (workspaceName: string) => `مدیریت پروژهها برای ${workspaceName}`,
|
||||
active: "پروژههای فعال",
|
||||
archived: "پروژههای بایگانی شده",
|
||||
archived: "بایگانی شده",
|
||||
createNew: "ایجاد پروژه جدید",
|
||||
searchPlaceholder: "جستجوی پروژهها...",
|
||||
selectWorkspace: "لطفاً ابتدا یک ورکاسپیس انتخاب کنید.",
|
||||
@@ -535,11 +589,11 @@ export const fa = {
|
||||
},
|
||||
namePlaceholder: "نام پروژه...",
|
||||
teamMembers: "اعضای تیم",
|
||||
manageAccess: "مدیریت دسترسی",
|
||||
accessModalTitle: "دسترسی پروژهها",
|
||||
accessModalDescription: "دسترسی اعضای ورکاسپیس به پروژهها را اعطا یا لغو کنید.",
|
||||
accessMemberLabel: "عضو",
|
||||
accessNoMembers: "عضو واجد شرایطی پیدا نشد.",
|
||||
manageAccess: "پروژهها و نرخها",
|
||||
accessModalTitle: "پروژهها و نرخها",
|
||||
accessModalDescription: "دسترسی پروژهها را برای اعضا و مهمانها مدیریت کنید و برای هر کاربر ورکاسپیس نرخ اختصاصی پروژه ثبت کنید.",
|
||||
accessMemberLabel: "کاربر",
|
||||
accessNoMembers: "کاربری در این ورکاسپیس پیدا نشد.",
|
||||
accessNoProjects: "پروژهای پیدا نشد.",
|
||||
accessSelectVisible: "انتخاب همه موارد قابل مشاهده",
|
||||
accessClearSelection: "پاک کردن انتخاب",
|
||||
@@ -552,6 +606,7 @@ export const fa = {
|
||||
accessRevokeSuccess: "دسترسی پروژه با موفقیت لغو شد.",
|
||||
accessLoadError: "بارگذاری وضعیت دسترسی پروژهها انجام نشد.",
|
||||
accessSaveError: "بهروزرسانی دسترسی پروژهها انجام نشد.",
|
||||
implicitAccessHint: "مالکها و ادمینها همیشه به همه پروژهها دسترسی دارند. از اینجا فقط میتوانید نرخ اختصاصی پروژه برای آنها تنظیم کنید.",
|
||||
createSuccess: "پروژه با موفقیت ایجاد شد.",
|
||||
createError: "خطا در ایجاد پروژه.",
|
||||
updateSuccess: "پروژه با موفقیت بهروزرسانی شد.",
|
||||
@@ -592,8 +647,17 @@ export const fa = {
|
||||
rates: {
|
||||
workspaceSectionTitle: "نرخهای کاربران ورکاسپیس",
|
||||
projectSectionTitle: "نرخهای کاربران پروژه",
|
||||
myRatesTitle: "تعرفههای من",
|
||||
myRatesHint: "نرخهای اختصاصی پروژه در این ورکاسپیس روی نرخ پیشفرض شما اولویت دارند.",
|
||||
workspaceRate: "دستمزد ساعتی",
|
||||
workspaceRateHint: "این نرخ پیشفرض شما است مگر اینکه برای یک پروژه نرخ اختصاصی ثبت شده باشد.",
|
||||
projectOverride: "نرخ اختصاصی پروژه",
|
||||
projectOverrides: "نرخهای اختصاصی پروژه",
|
||||
accessibleProjects: "پروژههای دردسترس",
|
||||
workspaceFallbackProjects: "با نرخ ورکاسپیس",
|
||||
projectOverrideHint: "فقط پروژههایی که نرخ اختصاصی دارند اینجا نمایش داده میشوند. بقیه پروژههای دردسترس از نرخ ورکاسپیس استفاده میکنند.",
|
||||
projectOverrideEmpty: "برای شما در این ورکاسپیس هنوز نرخ اختصاصی پروژهای ثبت نشده است.",
|
||||
myRatesEmpty: "هنوز نرخی برای این ورکاسپیس ثبت نشده است.",
|
||||
inheritsWorkspaceRate: "ارثبری از دستمزد ساعتی",
|
||||
noRate: "بدون نرخ",
|
||||
hourlyRatePlaceholder: "0.00",
|
||||
@@ -615,6 +679,7 @@ export const fa = {
|
||||
description: (workspaceName: string) => `ثبت زمان در ${workspaceName}`,
|
||||
selectWorkspace: "لطفاً ابتدا یک ورکاسپیس انتخاب کنید.",
|
||||
addEntry: "افزودن ورودی",
|
||||
addManualEntry: "افزودن دستی زمان",
|
||||
startTimer: "شروع تایمر",
|
||||
stopTimer: "توقف تایمر",
|
||||
timerRunning: "تایمر فعال است",
|
||||
@@ -629,6 +694,7 @@ export const fa = {
|
||||
emptyStateDescription: "برای شروع، تایمر را اجرا کنید یا یک ورودی دستی اضافه کنید.",
|
||||
noEntriesSearch: "عبارت جستوجو یا فیلترهای خود را تغییر دهید.",
|
||||
createTitle: "افزودن ورودی زمان",
|
||||
manualCreateTitle: "افزودن دستی زمان",
|
||||
startTitle: "شروع تایمر",
|
||||
editTitle: "ویرایش ورودی زمان",
|
||||
createSuccess: "ورودی زمان با موفقیت ایجاد شد.",
|
||||
@@ -674,6 +740,10 @@ export const fa = {
|
||||
noProjectsFoundLabel: "پروژهای پیدا نشد.",
|
||||
deletedProjectLabel: "پروژه حذفشده",
|
||||
deletedTagLabel: "تگ حذفشده",
|
||||
startRequiredError: "تاریخ و زمان شروع الزامی است.",
|
||||
endRequiredError: "تاریخ و زمان پایان باید هر دو وارد شوند.",
|
||||
invalidEndTimeError: "زمان پایان معتبر نیست.",
|
||||
endBeforeStartError: "پایان باید بعد از شروع باشد.",
|
||||
},
|
||||
reports: {
|
||||
title: "گزارشها",
|
||||
@@ -722,6 +792,9 @@ export const fa = {
|
||||
userSummaryDetailsDescription: "تاریخچه نرخهای ساعتی و توزیع زمان کار برای کاربر انتخابشده را بررسی کنید.",
|
||||
rateHistory: "تاریخچه نرخها",
|
||||
percentage: "درصد",
|
||||
hourPercentage: "درصد ساعت",
|
||||
incomePercentage: "درصد کارکرد",
|
||||
now: "حال",
|
||||
chartTitle: "نمودار فعالیت",
|
||||
totalSeconds: "مجموع ثانیه",
|
||||
exportExcel: "خروجی Excel",
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import App from './App';
|
||||
import { AppProvider } from './context/AppContext';
|
||||
import './index.css';
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<AppProvider>
|
||||
<App />
|
||||
</AppProvider>
|
||||
</React.StrictMode>
|
||||
);
|
||||
499
src/pages/About.tsx
Normal file
499
src/pages/About.tsx
Normal file
@@ -0,0 +1,499 @@
|
||||
import { useState, type FormEvent } from "react"
|
||||
import { Link, useNavigate } from "react-router-dom"
|
||||
import { toast } from "sonner"
|
||||
import {
|
||||
ArrowLeft,
|
||||
ArrowRight,
|
||||
AtSign,
|
||||
BarChart3,
|
||||
CheckCircle2,
|
||||
Command,
|
||||
FileText,
|
||||
Globe2,
|
||||
Layers3,
|
||||
LockKeyhole,
|
||||
Mail,
|
||||
MessageCircle,
|
||||
Moon,
|
||||
Phone,
|
||||
Send,
|
||||
ShieldCheck,
|
||||
Sparkles,
|
||||
Sun,
|
||||
TimerReset,
|
||||
Users,
|
||||
Waypoints,
|
||||
} from "lucide-react"
|
||||
|
||||
import { Button } from "../components/ui/button"
|
||||
import { Input } from "../components/ui/input"
|
||||
import { TextAreaInput } from "../components/ui/TextAreaInput"
|
||||
import { useTheme } from "../components/ThemeProvider"
|
||||
import { useTranslation } from "../hooks/useTranslation"
|
||||
import { submitContactForm } from "../api/contact"
|
||||
import aboutContent from "../content/about.json"
|
||||
import { cn } from "../lib/utils"
|
||||
|
||||
type AboutContent = typeof aboutContent.en
|
||||
|
||||
const sectionIcons = [Sparkles, ShieldCheck, Layers3]
|
||||
const principleIcons = [TimerReset, Waypoints, BarChart3]
|
||||
const capabilityIcons = [TimerReset, Users, FileText, LockKeyhole]
|
||||
const contactIcons = [MessageCircle, MessageCircle, Mail, Phone]
|
||||
|
||||
export default function About() {
|
||||
const navigate = useNavigate()
|
||||
const { t, lang, setLanguage } = useTranslation()
|
||||
const { theme, setTheme } = useTheme()
|
||||
const [contactForm, setContactForm] = useState({
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
email: "",
|
||||
mobile: "",
|
||||
message: "",
|
||||
})
|
||||
const [isContactSubmitting, setIsContactSubmitting] = useState(false)
|
||||
|
||||
const content = aboutContent[lang] as AboutContent
|
||||
const isAuthenticated = typeof window !== "undefined" && !!localStorage.getItem("accessToken")
|
||||
const isDarkMode =
|
||||
theme === "dark" ||
|
||||
(theme === "system" && document.documentElement.classList.contains("dark"))
|
||||
const ctaTarget = isAuthenticated ? "/timesheet" : "/auth"
|
||||
|
||||
const updateContactField = (field: keyof typeof contactForm, value: string) => {
|
||||
setContactForm((current) => ({ ...current, [field]: value }))
|
||||
}
|
||||
|
||||
const handleContactSubmit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault()
|
||||
setIsContactSubmitting(true)
|
||||
try {
|
||||
await submitContactForm({
|
||||
first_name: contactForm.firstName.trim(),
|
||||
last_name: contactForm.lastName.trim(),
|
||||
email: contactForm.email.trim(),
|
||||
mobile: contactForm.mobile.trim(),
|
||||
message: contactForm.message.trim(),
|
||||
})
|
||||
setContactForm({
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
email: "",
|
||||
mobile: "",
|
||||
message: "",
|
||||
})
|
||||
toast.success(content.contact.success)
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : content.contact.error)
|
||||
} finally {
|
||||
setIsContactSubmitting(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="scroll-smooth min-h-screen overflow-x-hidden bg-[radial-gradient(circle_at_top,#e0f2fe_0%,#f8fafc_36%,#eef2ff_100%)] text-slate-950 dark:bg-[radial-gradient(circle_at_top,#082f49_0%,#020617_40%,#020617_100%)] dark:text-slate-50">
|
||||
<div className="landing-aurora pointer-events-none fixed inset-0 opacity-80" />
|
||||
<div className="landing-hero-grid pointer-events-none fixed inset-0 opacity-70 dark:opacity-40" />
|
||||
<div className="pointer-events-none fixed left-[-12rem] top-20 h-80 w-80 rounded-full bg-cyan-400/20 blur-3xl dark:bg-cyan-500/10" />
|
||||
<div className="pointer-events-none fixed right-[-10rem] top-52 h-72 w-72 rounded-full bg-emerald-300/20 blur-3xl dark:bg-emerald-400/10" />
|
||||
|
||||
<div className="relative mx-auto flex min-h-screen max-w-7xl flex-col px-4 pb-14 pt-5 sm:px-6 lg:px-8">
|
||||
<header className="animate-landing-rise flex items-center justify-between rounded-full border border-white/70 bg-white/75 px-4 py-3 shadow-[0_20px_60px_-36px_rgba(15,23,42,0.45)] backdrop-blur-xl dark:border-white/10 dark:bg-slate-950/55">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => navigate("/")}
|
||||
className="inline-flex items-center gap-3 rounded-full px-2 py-1 text-left"
|
||||
>
|
||||
<span className="flex h-10 w-10 items-center justify-center rounded-2xl bg-slate-950 text-white shadow-lg shadow-cyan-500/20 dark:bg-white dark:text-slate-950">
|
||||
<Command className="h-5 w-5" />
|
||||
</span>
|
||||
<span className="hidden sm:block">
|
||||
<span className="block text-lg font-semibold">{t.title}</span>
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<nav className="hidden items-center gap-2 md:flex">
|
||||
<Link
|
||||
to="/"
|
||||
className="rounded-full px-4 py-2 text-sm font-medium text-slate-600 transition dark:text-slate-200 dark:hover:text-white"
|
||||
>
|
||||
{lang === "fa" ? "خانه" : "Home"}
|
||||
</Link>
|
||||
<Link
|
||||
to="/about"
|
||||
className="rounded-ful px-4 py-2 text-sm text-white shadow-sm font-bold"
|
||||
>
|
||||
{lang === "fa" ? "درباره ما" : "About us"}
|
||||
</Link>
|
||||
</nav>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setLanguage(lang === "fa" ? "en" : "fa")}
|
||||
className="inline-flex h-11 items-center gap-2 rounded-full border border-slate-200/80 bg-white/80 px-4 text-sm font-medium text-slate-700 transition hover:bg-slate-50 dark:border-slate-800 dark:bg-slate-950/80 dark:text-slate-200 dark:hover:bg-slate-900"
|
||||
>
|
||||
<Globe2 className="h-4 w-4" />
|
||||
{lang === "fa" ? t.landing.actions.switchToEnglish : t.landing.actions.switchToPersian}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setTheme(isDarkMode ? "light" : "dark")}
|
||||
className="inline-flex h-11 w-11 items-center justify-center rounded-full border border-slate-200/80 bg-white/80 text-slate-700 transition hover:bg-slate-50 dark:border-slate-800 dark:bg-slate-950/80 dark:text-slate-200 dark:hover:bg-slate-900"
|
||||
aria-label={isDarkMode ? t.lightMode : t.darkMode}
|
||||
>
|
||||
{isDarkMode ? <Sun className="h-4 w-4" /> : <Moon className="h-4 w-4" />}
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main className="flex-1">
|
||||
<section className="grid items-center gap-10 py-12 lg:grid-cols-[1.05fr_0.95fr] lg:py-20">
|
||||
<div className="space-y-7">
|
||||
<div className="animate-landing-rise">
|
||||
<div className="mb-5 inline-flex items-center gap-2 rounded-full border border-cyan-200/70 bg-white/75 px-4 py-2 text-sm font-medium text-cyan-900 shadow-sm backdrop-blur dark:border-cyan-500/20 dark:bg-cyan-500/10 dark:text-cyan-100">
|
||||
<Sparkles className="h-4 w-4" />
|
||||
{content.eyebrow}
|
||||
</div>
|
||||
<h1 className="max-w-4xl text-4xl font-semibold leading-[1.08] text-slate-950 sm:text-5xl lg:text-6xl dark:text-white">
|
||||
{content.hero.title}
|
||||
<span className="landing-shimmer mt-4 block bg-[linear-gradient(120deg,#0f172a_15%,#0891b2_48%,#0f766e_78%,#0f172a_100%)] bg-clip-text pb-4 text-transparent dark:bg-[linear-gradient(120deg,#ffffff_18%,#67e8f9_48%,#2dd4bf_78%,#ffffff_100%)]">
|
||||
{content.hero.accent}
|
||||
</span>
|
||||
</h1>
|
||||
<p className="mt-6 max-w-2xl text-lg leading-8 text-slate-600 dark:text-slate-300 sm:text-xl">
|
||||
{content.hero.description}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="animate-landing-rise flex flex-col gap-3 sm:flex-row [animation-delay:140ms]">
|
||||
<Button
|
||||
asChild
|
||||
className="h-14 rounded-full bg-slate-950 px-7 text-base text-white shadow-[0_30px_80px_-28px_rgba(8,145,178,0.45)] hover:bg-slate-800 dark:bg-cyan-400 dark:text-slate-950 dark:hover:bg-cyan-300"
|
||||
>
|
||||
<Link to={ctaTarget}>
|
||||
{content.cta.button}
|
||||
<ArrowRight className={cn("ms-2 h-4 w-4", lang === "fa" && "rotate-180")} />
|
||||
</Link>
|
||||
</Button>
|
||||
<Button
|
||||
asChild
|
||||
variant="outline"
|
||||
className="h-14 rounded-full border-slate-200 bg-white/85 px-7 text-base text-slate-800 shadow-sm backdrop-blur hover:bg-white dark:border-slate-800 dark:bg-slate-950/70 dark:text-slate-100 dark:hover:bg-slate-900"
|
||||
>
|
||||
<Link to="/">
|
||||
{lang === "fa" ? "بازگشت به صفحه اصلی" : "Back to home"}
|
||||
{lang === "fa" ? <ArrowLeft className="ms-2 h-4 w-4" /> : <ArrowRight className="ms-2 h-4 w-4" />}
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="animate-landing-rise [animation-delay:180ms]">
|
||||
<div className="relative overflow-hidden rounded-[2rem] border border-white/70 bg-white/80 p-5 shadow-[0_45px_110px_-48px_rgba(15,23,42,0.6)] backdrop-blur-2xl dark:border-white/10 dark:bg-slate-950/70 sm:p-6">
|
||||
<div className="absolute inset-x-0 top-0 h-24 bg-[linear-gradient(90deg,rgba(34,211,238,0.16),rgba(16,185,129,0.12),rgba(245,158,11,0.12))]" />
|
||||
<div className="relative">
|
||||
<div className="mb-6 flex items-center justify-between">
|
||||
<div>
|
||||
<div className="text-xs uppercase tracking-[0.22em] text-slate-400 dark:text-slate-500">
|
||||
{lang === "fa" ? "مدل محصول" : "Product model"}
|
||||
</div>
|
||||
<div className="mt-2 text-2xl font-semibold tracking-[-0.04em] text-slate-950 dark:text-white">
|
||||
{lang === "fa" ? "از ثبت تا تصمیم" : "From capture to decision"}
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-full border border-emerald-200 bg-emerald-50 px-4 py-2 text-sm font-semibold text-emerald-700 dark:border-emerald-500/20 dark:bg-emerald-500/10 dark:text-emerald-200">
|
||||
{lang === "fa" ? "شفاف" : "Clear"}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
{content.sections.map((section, index) => {
|
||||
const Icon = sectionIcons[index] ?? Sparkles
|
||||
|
||||
return (
|
||||
<div
|
||||
key={section.title}
|
||||
className="rounded-[1.5rem] border border-slate-200/80 bg-white/80 p-4 shadow-sm backdrop-blur dark:border-slate-800 dark:bg-slate-900/80"
|
||||
>
|
||||
<div className="flex items-start gap-4">
|
||||
<div className="flex h-11 w-11 shrink-0 items-center justify-center rounded-2xl bg-slate-950 text-white dark:bg-cyan-400 dark:text-slate-950">
|
||||
<Icon className="h-5 w-5" />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold tracking-[-0.03em] text-slate-950 dark:text-white">
|
||||
{section.title}
|
||||
</h2>
|
||||
<p className="mt-2 text-sm leading-7 text-slate-600 dark:text-slate-300">
|
||||
{section.description}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="grid gap-4 py-8 md:grid-cols-3">
|
||||
{content.principles.map((principle, index) => {
|
||||
const Icon = principleIcons[index] ?? CheckCircle2
|
||||
|
||||
return (
|
||||
<article
|
||||
key={principle.title}
|
||||
className="animate-landing-rise rounded-[2rem] border border-white/70 bg-white/80 p-6 shadow-[0_30px_80px_-50px_rgba(15,23,42,0.6)] backdrop-blur-xl dark:border-white/10 dark:bg-slate-950/65"
|
||||
style={{ animationDelay: `${index * 120}ms` }}
|
||||
>
|
||||
<div className="flex h-12 w-12 items-center justify-center rounded-2xl bg-slate-950 text-white dark:bg-cyan-400 dark:text-slate-950">
|
||||
<Icon className="h-5 w-5" />
|
||||
</div>
|
||||
<h2 className="mt-5 text-2xl font-semibold tracking-[-0.04em] text-slate-950 dark:text-white">
|
||||
{principle.title}
|
||||
</h2>
|
||||
<p className="mt-3 text-base leading-7 text-slate-600 dark:text-slate-300">
|
||||
{principle.description}
|
||||
</p>
|
||||
</article>
|
||||
)
|
||||
})}
|
||||
</section>
|
||||
|
||||
<section className="grid gap-6 py-8 lg:grid-cols-[0.9fr_1.1fr]">
|
||||
<div className="animate-landing-rise rounded-[2rem] border border-white/70 bg-white/80 p-7 shadow-[0_30px_80px_-50px_rgba(15,23,42,0.6)] backdrop-blur-xl dark:border-white/10 dark:bg-slate-950/65">
|
||||
<div className="text-sm font-semibold uppercase tracking-[0.2em] text-cyan-700 dark:text-cyan-300">
|
||||
{lang === "fa" ? "برای چه تیمهایی" : "Who it serves"}
|
||||
</div>
|
||||
<h2 className="mt-4 text-4xl font-semibold tracking-[-0.05em] text-slate-950 dark:text-white">
|
||||
{lang === "fa" ? "برای تیمهایی که زمان را بخشی از عملیات میدانند." : "For teams that treat time as part of operations."}
|
||||
</h2>
|
||||
<div className="mt-6 flex flex-wrap gap-3">
|
||||
{content.audience.map((item) => (
|
||||
<span
|
||||
key={item}
|
||||
className="rounded-full border border-cyan-200/70 bg-cyan-50/70 px-4 py-2 text-sm font-medium text-cyan-900 backdrop-blur dark:border-cyan-500/20 dark:bg-cyan-500/10 dark:text-cyan-100"
|
||||
>
|
||||
{item}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
{content.capabilities.map((capability, index) => {
|
||||
const Icon = capabilityIcons[index] ?? Waypoints
|
||||
|
||||
return (
|
||||
<article
|
||||
key={capability.title}
|
||||
className="animate-landing-rise rounded-[2rem] border border-white/70 bg-gradient-to-br from-white/95 to-slate-50/80 p-6 shadow-[0_26px_70px_-48px_rgba(15,23,42,0.65)] backdrop-blur-xl dark:border-white/10 dark:from-slate-950/80 dark:to-slate-900/55"
|
||||
style={{ animationDelay: `${index * 90}ms` }}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex h-11 w-11 items-center justify-center rounded-2xl bg-slate-950 text-white dark:bg-white dark:text-slate-950">
|
||||
<Icon className="h-5 w-5" />
|
||||
</div>
|
||||
<h3 className="text-xl font-semibold tracking-[-0.04em] text-slate-950 dark:text-white">
|
||||
{capability.title}
|
||||
</h3>
|
||||
</div>
|
||||
<p className="mt-4 text-sm leading-7 text-slate-600 dark:text-slate-300">
|
||||
{capability.description}
|
||||
</p>
|
||||
</article>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="py-8">
|
||||
<div className="rounded-[2rem] border border-white/70 bg-white/80 p-7 shadow-[0_30px_80px_-50px_rgba(15,23,42,0.6)] backdrop-blur-xl dark:border-white/10 dark:bg-slate-950/65">
|
||||
<div className="mb-6 flex flex-col gap-2 sm:flex-row sm:items-end sm:justify-between">
|
||||
<div>
|
||||
<div className="text-sm font-semibold uppercase tracking-[0.2em] text-cyan-700 dark:text-cyan-300">
|
||||
{lang === "fa" ? "اعتماد و کنترل" : "Trust and control"}
|
||||
</div>
|
||||
<h2 className="mt-3 text-3xl font-semibold tracking-[-0.05em] text-slate-950 dark:text-white">
|
||||
{lang === "fa" ? "جزئیات مهم باید قابل بررسی بمانند." : "Important details should remain reviewable."}
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-3 md:grid-cols-3">
|
||||
{content.trust.map((item, index) => (
|
||||
<div
|
||||
key={item}
|
||||
className="rounded-[1.5rem] border border-slate-200/80 bg-white/80 p-4 text-sm leading-7 text-slate-600 shadow-sm backdrop-blur dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-300"
|
||||
>
|
||||
<CheckCircle2 className="mb-4 h-5 w-5 text-emerald-500" />
|
||||
{item}
|
||||
<div className="mt-5 text-xs font-semibold uppercase tracking-[0.2em] text-slate-400 dark:text-slate-500">
|
||||
{lang === "fa" ? `نکته ${new Intl.NumberFormat("fa-IR").format(index + 1)}` : `Note ${index + 1}`}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="grid gap-6 py-8 lg:grid-cols-[0.95fr_1.05fr]">
|
||||
<div className="animate-landing-rise rounded-[2rem] border border-white/70 bg-white/80 p-7 shadow-[0_30px_80px_-50px_rgba(15,23,42,0.6)] backdrop-blur-xl dark:border-white/10 dark:bg-slate-950/65">
|
||||
<div className="text-sm font-semibold uppercase tracking-[0.2em] text-cyan-700 dark:text-cyan-300">
|
||||
{content.contact.eyebrow}
|
||||
</div>
|
||||
<h2 className="mt-4 text-4xl font-semibold tracking-[-0.05em] text-slate-950 dark:text-white">
|
||||
{content.contact.title}
|
||||
</h2>
|
||||
<p className="mt-4 text-base leading-8 text-slate-600 dark:text-slate-300">
|
||||
{content.contact.description}
|
||||
</p>
|
||||
|
||||
<div className="mt-7 grid gap-3">
|
||||
{content.contact.channels.map((channel, index) => {
|
||||
const Icon = contactIcons[index] ?? AtSign
|
||||
|
||||
return (
|
||||
<a
|
||||
key={channel.label}
|
||||
href={channel.href}
|
||||
target={channel.href.startsWith("http") ? "_blank" : undefined}
|
||||
rel={channel.href.startsWith("http") ? "noreferrer" : undefined}
|
||||
className="group flex items-center justify-between gap-4 rounded-2xl border border-slate-200/80 bg-white/80 p-4 text-start shadow-sm transition hover:border-cyan-300 hover:bg-cyan-50/70 dark:border-slate-800 dark:bg-slate-900/75 dark:hover:border-cyan-500/40 dark:hover:bg-cyan-950/30"
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-3">
|
||||
<span className="flex h-10 w-10 shrink-0 items-center justify-center rounded-2xl bg-slate-950 text-white dark:bg-cyan-400 dark:text-slate-950">
|
||||
<Icon className="h-5 w-5" />
|
||||
</span>
|
||||
<span className="min-w-0">
|
||||
<span className="block text-sm font-semibold text-slate-950 dark:text-white">
|
||||
{channel.label}
|
||||
</span>
|
||||
<span className="block truncate text-sm text-slate-600 dark:text-slate-300">
|
||||
{channel.value}
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
{lang === "fa" ? (
|
||||
<ArrowLeft className="h-4 w-4 shrink-0 text-slate-400 transition group-hover:text-cyan-600 dark:group-hover:text-cyan-300" />
|
||||
) : (
|
||||
<ArrowRight className="h-4 w-4 shrink-0 text-slate-400 transition group-hover:text-cyan-600 dark:group-hover:text-cyan-300" />
|
||||
)}
|
||||
</a>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form
|
||||
onSubmit={handleContactSubmit}
|
||||
className="animate-landing-rise rounded-[2rem] border border-white/70 bg-white/85 p-7 shadow-[0_30px_80px_-50px_rgba(15,23,42,0.6)] backdrop-blur-xl dark:border-white/10 dark:bg-slate-950/70"
|
||||
>
|
||||
<div className="mb-6 flex items-center gap-3">
|
||||
<span className="flex h-11 w-11 items-center justify-center rounded-2xl bg-slate-950 text-white dark:bg-cyan-400 dark:text-slate-950">
|
||||
<Send className="h-5 w-5" />
|
||||
</span>
|
||||
<h2 className="text-2xl font-semibold tracking-[-0.04em] text-slate-950 dark:text-white">
|
||||
{content.contact.formTitle}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<label className="text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
{content.contact.fields.firstName}
|
||||
<Input
|
||||
value={contactForm.firstName}
|
||||
onChange={(event) => updateContactField("firstName", event.target.value)}
|
||||
placeholder={content.contact.placeholders.firstName}
|
||||
className="mt-2 h-12 rounded-2xl"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label className="text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
{content.contact.fields.lastName}
|
||||
<Input
|
||||
value={contactForm.lastName}
|
||||
onChange={(event) => updateContactField("lastName", event.target.value)}
|
||||
placeholder={content.contact.placeholders.lastName}
|
||||
className="mt-2 h-12 rounded-2xl"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label className="text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
{content.contact.fields.email}
|
||||
<Input
|
||||
type="email"
|
||||
value={contactForm.email}
|
||||
onChange={(event) => updateContactField("email", event.target.value)}
|
||||
placeholder={content.contact.placeholders.email}
|
||||
className="mt-2 h-12 rounded-2xl"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label className="text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
{content.contact.fields.mobile}
|
||||
<Input
|
||||
value={contactForm.mobile}
|
||||
onChange={(event) => updateContactField("mobile", event.target.value)}
|
||||
placeholder={content.contact.placeholders.mobile}
|
||||
className="mt-2 h-12 rounded-2xl"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<label className="mt-4 block text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
{content.contact.fields.message}
|
||||
<TextAreaInput
|
||||
value={contactForm.message}
|
||||
onChange={(event) => updateContactField("message", event.target.value)}
|
||||
placeholder={content.contact.placeholders.message}
|
||||
className="mt-2 min-h-40 rounded-2xl"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={isContactSubmitting}
|
||||
className="mt-6 h-14 w-full rounded-full bg-slate-950 px-7 text-base text-white hover:bg-slate-800 dark:bg-cyan-400 dark:text-slate-950 dark:hover:bg-cyan-300"
|
||||
>
|
||||
<Send className="me-2 h-4 w-4" />
|
||||
{isContactSubmitting ? content.contact.submitting : content.contact.submit}
|
||||
</Button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="py-8">
|
||||
<div className="relative overflow-hidden rounded-[2.5rem] border border-slate-950/5 bg-slate-950 px-6 py-10 text-white shadow-[0_40px_100px_-40px_rgba(15,23,42,0.8)] dark:border-white/10 sm:px-10">
|
||||
<div className="pointer-events-none absolute inset-y-0 right-0 w-[45%] bg-[radial-gradient(circle_at_top_right,rgba(34,211,238,0.35),transparent_55%),radial-gradient(circle_at_bottom_right,rgba(16,185,129,0.24),transparent_45%)]" />
|
||||
<div className="relative flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between">
|
||||
<div className="max-w-3xl">
|
||||
<div className="text-sm font-semibold uppercase tracking-[0.2em] text-cyan-300">
|
||||
{lang === "fa" ? "شروع ساده" : "Simple start"}
|
||||
</div>
|
||||
<h2 className="mt-4 text-4xl font-semibold leading-[1.1] tracking-[-0.05em] sm:text-5xl">
|
||||
{content.cta.title}
|
||||
</h2>
|
||||
<p className="mt-4 text-lg leading-8 text-slate-300">{content.cta.description}</p>
|
||||
</div>
|
||||
<Button
|
||||
asChild
|
||||
className="h-14 rounded-full bg-white px-7 text-base font-semibold text-slate-950 hover:bg-slate-100"
|
||||
>
|
||||
<Link to={ctaTarget}>
|
||||
{content.cta.button}
|
||||
<ArrowRight className={cn("ms-2 h-4 w-4", lang === "fa" && "rotate-180")} />
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -190,7 +190,11 @@ export default function Clients() {
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-slate-100 text-sm font-semibold text-slate-700 dark:bg-slate-700 dark:text-slate-200">
|
||||
{client.name.trim().charAt(0).toUpperCase() || "C"}
|
||||
{client.thumbnail ? (
|
||||
<img src={client.thumbnail} alt={client.name} className="h-full w-full rounded-xl object-cover" />
|
||||
) : (
|
||||
client.name.trim().charAt(0).toUpperCase() || "C"
|
||||
)}
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<CardTitle className="truncate text-base text-slate-900 dark:text-white">{client.name}</CardTitle>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMemo } from "react"
|
||||
import { useMemo, useState } from "react"
|
||||
import { Link, useNavigate } from "react-router-dom"
|
||||
import {
|
||||
ArrowRight,
|
||||
@@ -15,11 +15,14 @@ import {
|
||||
TimerReset,
|
||||
Waypoints,
|
||||
} from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { Button } from "../components/ui/button"
|
||||
import { useTheme } from "../components/ThemeProvider"
|
||||
import { useTranslation } from "../hooks/useTranslation"
|
||||
import { cn } from "../lib/utils"
|
||||
import { startDemo } from "../api/demo"
|
||||
import { setDemoSessionMeta, setSessionTokens } from "../lib/session"
|
||||
|
||||
const formatNumber = (value: number, lang: "en" | "fa") =>
|
||||
new Intl.NumberFormat(lang === "fa" ? "fa-IR" : "en-US").format(value)
|
||||
@@ -28,6 +31,7 @@ export default function Landing() {
|
||||
const navigate = useNavigate()
|
||||
const { t, lang, setLanguage } = useTranslation()
|
||||
const { theme, setTheme } = useTheme()
|
||||
const [isStartingDemo, setIsStartingDemo] = useState(false)
|
||||
|
||||
const isAuthenticated = typeof window !== "undefined" && !!localStorage.getItem("accessToken")
|
||||
const isDarkMode =
|
||||
@@ -87,6 +91,23 @@ export default function Landing() {
|
||||
|
||||
const ctaTarget = isAuthenticated ? "/timesheet" : "/auth"
|
||||
|
||||
const handleStartDemo = async () => {
|
||||
if (isStartingDemo) return
|
||||
setIsStartingDemo(true)
|
||||
try {
|
||||
const demo = await startDemo()
|
||||
setSessionTokens(demo.access, demo.refresh)
|
||||
setDemoSessionMeta(demo.expires_at)
|
||||
toast.success(t.demo?.started || "Demo environment is ready.")
|
||||
navigate("/timesheet")
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
toast.error(t.demo?.startError || "Could not start the demo environment.")
|
||||
} finally {
|
||||
setIsStartingDemo(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="scroll-smooth min-h-screen overflow-x-hidden bg-[radial-gradient(circle_at_top,#e0f2fe_0%,#f8fafc_36%,#eef2ff_100%)] text-slate-950 dark:bg-[radial-gradient(circle_at_top,#082f49_0%,#020617_40%,#020617_100%)] dark:text-slate-50">
|
||||
<div className="landing-aurora pointer-events-none fixed inset-0 opacity-80" />
|
||||
@@ -110,15 +131,12 @@ export default function Landing() {
|
||||
</button>
|
||||
|
||||
<div className="hidden items-center gap-2 md:flex">
|
||||
<a href="#demo" className="rounded-full px-4 py-2 text-sm font-medium text-slate-600 transition hover:bg-slate-100 hover:text-slate-950 dark:text-slate-300 dark:hover:bg-slate-900 dark:hover:text-white">
|
||||
{t.landing.nav.demo}
|
||||
</a>
|
||||
<a href="#features" className="rounded-full px-4 py-2 text-sm font-medium text-slate-600 transition hover:bg-slate-100 hover:text-slate-950 dark:text-slate-300 dark:hover:bg-slate-900 dark:hover:text-white">
|
||||
{t.landing.nav.features}
|
||||
</a>
|
||||
<a href="#workflow" className="rounded-full px-4 py-2 text-sm font-medium text-slate-600 transition hover:bg-slate-100 hover:text-slate-950 dark:text-slate-300 dark:hover:bg-slate-900 dark:hover:text-white">
|
||||
{t.landing.nav.workflow}
|
||||
</a>
|
||||
<Link to="/" className="rounded-ful px-4 py-2 text-sm text-white shadow-sm font-bold">
|
||||
{lang === "fa" ? "خانه" : "Home"}
|
||||
</Link>
|
||||
<Link to="/about" className="rounded-full px-4 py-2 text-sm font-medium text-slate-600 transition dark:text-slate-200 dark:hover:text-white">
|
||||
{t.landing.nav.about}
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
@@ -167,12 +185,14 @@ export default function Landing() {
|
||||
{isAuthenticated ? t.landing.actions.openWorkspace : t.landing.actions.startNow}
|
||||
<ArrowRight className={cn("ms-2 h-4 w-4", lang === "fa" && "rtl:rotate-180")} />
|
||||
</Button>
|
||||
<a
|
||||
href="#demo"
|
||||
className="inline-flex h-14 items-center justify-center rounded-full border border-slate-200 bg-white/85 px-7 text-base font-medium text-slate-800 shadow-sm backdrop-blur transition hover:bg-white dark:border-slate-800 dark:bg-slate-950/70 dark:text-slate-100 dark:hover:bg-slate-900"
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleStartDemo}
|
||||
disabled={isStartingDemo}
|
||||
className="inline-flex h-14 items-center justify-center rounded-full border border-slate-200 bg-white/85 px-7 text-base font-medium text-slate-800 shadow-sm backdrop-blur transition hover:bg-white disabled:cursor-not-allowed disabled:opacity-70 dark:border-slate-800 dark:bg-slate-950/70 dark:text-slate-100 dark:hover:bg-slate-900"
|
||||
>
|
||||
{t.landing.actions.watchDemo}
|
||||
</a>
|
||||
{isStartingDemo ? t.demo?.starting || "Preparing demo..." : t.landing.actions.watchDemo}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="animate-landing-rise grid gap-3 sm:grid-cols-3 [animation-delay:320ms]">
|
||||
@@ -385,16 +405,16 @@ export default function Landing() {
|
||||
|
||||
<section className="py-8">
|
||||
<div className="relative overflow-hidden rounded-[2.5rem] border border-slate-950/5 bg-slate-950 px-6 py-10 text-white shadow-[0_40px_100px_-40px_rgba(15,23,42,0.8)] dark:border-white/10 sm:px-10">
|
||||
<div className="pointer-events-none absolute inset-y-0 right-0 w-[45%] bg-[radial-gradient(circle_at_top_right,rgba(34,211,238,0.35),transparent_55%),radial-gradient(circle_at_bottom_right,rgba(245,158,11,0.22),transparent_45%)]" />
|
||||
<div className="relative flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between">
|
||||
<div className="max-w-3xl">
|
||||
<div className="flex flex-row pointer-events-none absolute inset-y-0 right-0 w-[45%] bg-[radial-gradient(circle_at_top_right,rgba(34,211,238,0.35),transparent_55%),radial-gradient(circle_at_bottom_right,rgba(245,158,11,0.22),transparent_45%)]" />
|
||||
<div className="relative flex flex-col lg:flex-row gap-6 justify-between">
|
||||
<div className="max-w-4xl">
|
||||
<div className="text-sm font-semibold uppercase tracking-[0.2em] text-cyan-300">{t.landing.finalCtaTag}</div>
|
||||
<h2 className="mt-4 text-4xl font-semibold leading-[1.1] tracking-[-0.05em] sm:text-5xl">
|
||||
{t.landing.finalCtaTitle}
|
||||
</h2>
|
||||
<p className="mt-4 text-lg leading-8 text-slate-300">{t.landing.finalCtaDescription}</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-3 sm:flex-row">
|
||||
<div className="flex flex-row lg:flex-col gap-3">
|
||||
<Button
|
||||
onClick={() => navigate(ctaTarget)}
|
||||
className="h-14 rounded-full bg-white px-7 text-base font-semibold text-slate-950 hover:bg-slate-100"
|
||||
@@ -408,6 +428,13 @@ export default function Landing() {
|
||||
>
|
||||
<Link to="/terms">{t.landing.actions.readTerms}</Link>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
asChild
|
||||
className="h-14 rounded-full border-white/20 bg-white/5 px-7 text-base text-white hover:bg-white/10 dark:border-white/20 dark:bg-white/5 dark:text-white dark:hover:bg-white/10"
|
||||
>
|
||||
<Link to="/about">{t.landing.actions.readAbout}</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
48
src/pages/NotFound.tsx
Normal file
48
src/pages/NotFound.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import { useNavigate } from "react-router-dom"
|
||||
import { ArrowLeft, ArrowRight, Home } from "lucide-react"
|
||||
|
||||
import { Button } from "../components/ui/button"
|
||||
import { useTranslation } from "../hooks/useTranslation"
|
||||
|
||||
export default function NotFound() {
|
||||
const navigate = useNavigate()
|
||||
const { lang } = useTranslation()
|
||||
const isFa = lang === "fa"
|
||||
|
||||
return (
|
||||
<main className="flex min-h-screen items-center justify-center bg-[radial-gradient(circle_at_top,#e0f2fe_0%,#f8fafc_42%,#eef2ff_100%)] px-4 text-center text-slate-950 dark:bg-[radial-gradient(circle_at_top,#082f49_0%,#020617_44%,#020617_100%)] dark:text-slate-50">
|
||||
<section className="mx-auto max-w-2xl">
|
||||
<div className="text-[7rem] font-semibold leading-none tracking-[-0.08em] text-slate-950 sm:text-[10rem] dark:text-white">
|
||||
404
|
||||
</div>
|
||||
<h1 className="mt-5 text-3xl font-semibold tracking-[-0.04em] sm:text-5xl">
|
||||
{isFa ? "صفحه پیدا نشد" : "Page not found"}
|
||||
</h1>
|
||||
<p className="mx-auto mt-5 max-w-xl text-base leading-8 text-slate-600 sm:text-lg dark:text-slate-300">
|
||||
{isFa
|
||||
? "این صفحه وجود ندارد یا آدرس آن تغییر کرده است."
|
||||
: "This page does not exist or its address has changed."}
|
||||
</p>
|
||||
<div className="mt-9 flex flex-col justify-center gap-3 sm:flex-row">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => navigate(-1)}
|
||||
className="h-14 rounded-full border-slate-200 bg-white/80 px-7 text-base text-slate-800 backdrop-blur hover:bg-white dark:border-slate-800 dark:bg-slate-950/70 dark:text-slate-100 dark:hover:bg-slate-900"
|
||||
>
|
||||
{isFa ? <ArrowRight className="me-2 h-4 w-4" /> : <ArrowLeft className="me-2 h-4 w-4" />}
|
||||
{isFa ? "بازگشت" : "Go back"}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={() => navigate("/")}
|
||||
className="h-14 rounded-full bg-slate-950 px-7 text-base text-white hover:bg-slate-800 dark:bg-cyan-400 dark:text-slate-950 dark:hover:bg-cyan-300"
|
||||
>
|
||||
<Home className="me-2 h-4 w-4" />
|
||||
{isFa ? "صفحه اصلی" : "Home page"}
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useBlocker, useNavigate } from "react-router-dom";
|
||||
import { Briefcase, Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { getClients } from "../api/clients";
|
||||
import { createProject } from "../api/projects";
|
||||
import { Button } from "../components/ui/button";
|
||||
import { Input } from "../components/ui/input";
|
||||
import { Select } from "../components/ui/Select";
|
||||
import { TextAreaInput } from "../components/ui/TextAreaInput";
|
||||
import { useWorkspace } from "../context/WorkspaceContext";
|
||||
import { useTranslation } from "../hooks/useTranslation";
|
||||
import { PROJECTS_CREATE, canWorkspace } from "../lib/permissions";
|
||||
|
||||
const COLORS = [
|
||||
"#3B82F6",
|
||||
"#10B981",
|
||||
"#F59E0B",
|
||||
"#EF4444",
|
||||
"#8B5CF6",
|
||||
"#EC4899",
|
||||
"#14B8A6",
|
||||
"#64748B",
|
||||
];
|
||||
|
||||
export default function ProjectCreate() {
|
||||
const navigate = useNavigate();
|
||||
const { t } = useTranslation();
|
||||
const { activeWorkspace } = useWorkspace();
|
||||
const canCreateProject = canWorkspace(activeWorkspace?.my_role, PROJECTS_CREATE);
|
||||
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [color, setColor] = useState(COLORS[0]);
|
||||
const [client, setClient] = useState("");
|
||||
const [clientsList, setClientsList] = useState<{ id: string; name: string }[]>([]);
|
||||
const [isLoadingData, setIsLoadingData] = useState(true);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
const hasUnsavedChanges = name.trim() !== "" || description.trim() !== "" || client !== "" || color !== COLORS[0];
|
||||
|
||||
useEffect(() => {
|
||||
if (activeWorkspace && !canCreateProject) {
|
||||
toast.error("You do not have permission to create projects.");
|
||||
navigate("/projects");
|
||||
}
|
||||
}, [activeWorkspace, canCreateProject, navigate]);
|
||||
|
||||
useBlocker(({ currentLocation, nextLocation }) => {
|
||||
if (hasUnsavedChanges && !isSaving && currentLocation.pathname !== nextLocation.pathname) {
|
||||
return !window.confirm(t.confirmLeave || "You have unsaved changes. Are you sure you want to leave?");
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeWorkspace?.id) return;
|
||||
|
||||
setName("");
|
||||
setDescription("");
|
||||
setColor(COLORS[0]);
|
||||
setClient("");
|
||||
setClientsList([]);
|
||||
setIsLoadingData(true);
|
||||
|
||||
const loadInitialData = async () => {
|
||||
try {
|
||||
const clientsRes = await getClients(activeWorkspace.id);
|
||||
setClientsList(clientsRes.results || []);
|
||||
} catch {
|
||||
toast.error(t.projects?.clientFetchError || "Failed to load clients.");
|
||||
} finally {
|
||||
setIsLoadingData(false);
|
||||
}
|
||||
};
|
||||
|
||||
void loadInitialData();
|
||||
}, [activeWorkspace?.id, t.projects?.clientFetchError]);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!name.trim() || !activeWorkspace) return;
|
||||
|
||||
try {
|
||||
setIsSaving(true);
|
||||
const newProject = await createProject({
|
||||
workspace: activeWorkspace.id,
|
||||
name,
|
||||
description,
|
||||
color,
|
||||
client: client || null,
|
||||
is_archived: false,
|
||||
});
|
||||
|
||||
window.dispatchEvent(new CustomEvent("project_created", { detail: newProject }));
|
||||
toast.success(t.projects?.createSuccess || "Project created successfully.");
|
||||
navigate("/projects");
|
||||
} catch (error: any) {
|
||||
toast.error(error.message || t.projects?.createError || "Failed to create project.");
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (!activeWorkspace) return null;
|
||||
|
||||
return (
|
||||
<div className="absolute inset-0 overflow-y-auto bg-slate-50 p-4 dark:bg-slate-900 sm:p-6">
|
||||
<div className="mx-auto max-w-3xl">
|
||||
<h1 className="mb-6 text-2xl font-bold text-slate-800 dark:text-slate-200">
|
||||
{t.projects?.createNew || "Create New Project"}
|
||||
</h1>
|
||||
|
||||
<div className="rounded-3xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900">
|
||||
<form onSubmit={handleSubmit} className="space-y-6 p-6">
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="h-10 w-10 shrink-0 rounded-lg shadow-sm" style={{ backgroundColor: color }} />
|
||||
<Input
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder={t.projects?.namePlaceholder || "Project name..."}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{COLORS.map((paletteColor) => (
|
||||
<button
|
||||
key={paletteColor}
|
||||
type="button"
|
||||
onClick={() => setColor(paletteColor)}
|
||||
className={`h-5 w-5 shrink-0 rounded-full transition-all duration-150 ${
|
||||
color === paletteColor
|
||||
? "scale-110 ring-2 ring-blue-500 ring-offset-2 ring-offset-white shadow-md dark:ring-offset-slate-900"
|
||||
: "shadow-sm hover:scale-110"
|
||||
}`}
|
||||
style={{ backgroundColor: paletteColor }}
|
||||
aria-label={`Select color ${paletteColor}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 flex items-center gap-2 text-slate-700 dark:text-slate-300">
|
||||
<Briefcase size={16} />
|
||||
{t.projects?.client || "Client"}
|
||||
</label>
|
||||
<Select
|
||||
value={client}
|
||||
onChange={setClient}
|
||||
options={[
|
||||
{ value: "", label: t.projects?.noClient || "No Client" },
|
||||
...clientsList.map((item) => ({ value: item.id, label: item.name })),
|
||||
]}
|
||||
isLoading={isLoadingData}
|
||||
className="w-full"
|
||||
buttonClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-slate-700 dark:text-slate-300">
|
||||
{t.projects?.descriptionLabel || "Description"}
|
||||
</label>
|
||||
<TextAreaInput
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder={t.projects?.descriptionPlaceholder || "Add more details..."}
|
||||
rows={5}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-3 border-t border-slate-200 pt-4 dark:border-slate-700">
|
||||
<Button variant="ghost" type="button" onClick={() => navigate("/projects")}>
|
||||
{t.cancel || "Cancel"}
|
||||
</Button>
|
||||
<Button type="submit" disabled={isSaving || !name.trim()}>
|
||||
{isSaving ? <Loader2 className="me-2 h-4 w-4 animate-spin" /> : null}
|
||||
{t.create || "Create"}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useBlocker, useNavigate, useParams } from "react-router-dom";
|
||||
import { Briefcase, Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { getClients } from "../api/clients";
|
||||
import { getProject, updateProject } from "../api/projects";
|
||||
import { Button } from "../components/ui/button";
|
||||
import { Input } from "../components/ui/input";
|
||||
import { Select } from "../components/ui/Select";
|
||||
import { TextAreaInput } from "../components/ui/TextAreaInput";
|
||||
import { useWorkspace } from "../context/WorkspaceContext";
|
||||
import { useTranslation } from "../hooks/useTranslation";
|
||||
import { PROJECTS_EDIT, canWorkspace } from "../lib/permissions";
|
||||
|
||||
const COLORS = [
|
||||
"#3B82F6",
|
||||
"#10B981",
|
||||
"#F59E0B",
|
||||
"#EF4444",
|
||||
"#8B5CF6",
|
||||
"#EC4899",
|
||||
"#14B8A6",
|
||||
"#64748B",
|
||||
];
|
||||
|
||||
export default function ProjectEdit() {
|
||||
const navigate = useNavigate();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const { t } = useTranslation();
|
||||
const { activeWorkspace } = useWorkspace();
|
||||
const canEditProject = canWorkspace(activeWorkspace?.my_role, PROJECTS_EDIT);
|
||||
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [color, setColor] = useState(COLORS[0]);
|
||||
const [client, setClient] = useState("");
|
||||
const [clientsList, setClientsList] = useState<{ id: string; name: string }[]>([]);
|
||||
const [isLoadingData, setIsLoadingData] = useState(true);
|
||||
const [isProjectLoading, setIsProjectLoading] = useState(true);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
const hasUnsavedChanges = name.trim() !== "";
|
||||
|
||||
useEffect(() => {
|
||||
if (activeWorkspace && !canEditProject) {
|
||||
toast.error("You do not have permission to edit projects.");
|
||||
navigate("/projects");
|
||||
}
|
||||
}, [activeWorkspace, canEditProject, navigate]);
|
||||
|
||||
useBlocker(({ currentLocation, nextLocation }) => {
|
||||
if (hasUnsavedChanges && !isSaving && !isProjectLoading && currentLocation.pathname !== nextLocation.pathname) {
|
||||
return !window.confirm(t.confirmLeave || "You have unsaved changes. Are you sure you want to leave?");
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeWorkspace?.id || !id) return;
|
||||
|
||||
const loadInitialData = async () => {
|
||||
try {
|
||||
const [clientsRes, projectRes] = await Promise.all([
|
||||
getClients(activeWorkspace.id),
|
||||
getProject(id),
|
||||
]);
|
||||
|
||||
setClientsList(clientsRes.results || []);
|
||||
setName(projectRes.name || "");
|
||||
setDescription(projectRes.description || "");
|
||||
setColor(projectRes.color || COLORS[0]);
|
||||
setClient(projectRes.client?.id || projectRes.client || "");
|
||||
} catch {
|
||||
toast.error("Failed to load project data.");
|
||||
navigate("/projects");
|
||||
} finally {
|
||||
setIsLoadingData(false);
|
||||
setIsProjectLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
void loadInitialData();
|
||||
}, [activeWorkspace?.id, id, navigate]);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!name.trim() || !activeWorkspace || !id) return;
|
||||
|
||||
try {
|
||||
setIsSaving(true);
|
||||
const updatedProject = await updateProject(id, {
|
||||
name,
|
||||
description,
|
||||
color,
|
||||
client: client || null,
|
||||
});
|
||||
|
||||
window.dispatchEvent(new CustomEvent("project_updated", { detail: updatedProject }));
|
||||
toast.success(t.projects?.updateSuccess || "Project updated successfully.");
|
||||
navigate("/projects");
|
||||
} catch (error: any) {
|
||||
toast.error(error.message || t.projects?.updateError || "Failed to update project.");
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (!activeWorkspace) return null;
|
||||
|
||||
if (isProjectLoading) {
|
||||
return (
|
||||
<div className="absolute inset-0 flex items-center justify-center bg-slate-50 dark:bg-slate-900">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-blue-500" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="absolute inset-0 overflow-y-auto bg-slate-50 p-4 dark:bg-slate-900 sm:p-6">
|
||||
<div className="mx-auto max-w-3xl">
|
||||
<h1 className="mb-6 text-2xl font-bold text-slate-800 dark:text-slate-200">
|
||||
{t.projects?.edit || "Edit Project"}
|
||||
</h1>
|
||||
|
||||
<div className="rounded-3xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900">
|
||||
<form onSubmit={handleSubmit} className="space-y-6 p-6">
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="h-10 w-10 shrink-0 rounded-lg shadow-sm" style={{ backgroundColor: color }} />
|
||||
<Input
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder={t.projects?.namePlaceholder || "Project name..."}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{COLORS.map((paletteColor) => (
|
||||
<button
|
||||
key={paletteColor}
|
||||
type="button"
|
||||
onClick={() => setColor(paletteColor)}
|
||||
className={`h-5 w-5 shrink-0 rounded-full transition-all duration-150 ${
|
||||
color === paletteColor
|
||||
? "scale-110 ring-2 ring-blue-500 ring-offset-2 ring-offset-white shadow-md dark:ring-offset-slate-900"
|
||||
: "shadow-sm hover:scale-110"
|
||||
}`}
|
||||
style={{ backgroundColor: paletteColor }}
|
||||
aria-label={`Select color ${paletteColor}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 flex items-center gap-2 text-slate-700 dark:text-slate-300">
|
||||
<Briefcase size={16} />
|
||||
{t.projects?.client || "Client"}
|
||||
</label>
|
||||
<Select
|
||||
value={client}
|
||||
onChange={setClient}
|
||||
options={[
|
||||
{ value: "", label: t.projects?.noClient || "No Client" },
|
||||
...clientsList.map((item) => ({ value: item.id, label: item.name })),
|
||||
]}
|
||||
isLoading={isLoadingData}
|
||||
className="w-full"
|
||||
buttonClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-slate-700 dark:text-slate-300">
|
||||
{t.projects?.descriptionLabel || "Description"}
|
||||
</label>
|
||||
<TextAreaInput
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder={t.projects?.descriptionPlaceholder || "Add more details..."}
|
||||
rows={5}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-3 border-t border-slate-200 pt-4 dark:border-slate-700">
|
||||
<Button variant="ghost" type="button" onClick={() => navigate("/projects")}>
|
||||
{t.cancel || "Cancel"}
|
||||
</Button>
|
||||
<Button type="submit" disabled={isSaving || !name.trim()}>
|
||||
{isSaving ? <Loader2 className="me-2 h-4 w-4 animate-spin" /> : null}
|
||||
{t.save || "Save"}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import React, { useEffect, useMemo, useState, type FormEvent } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import { useTranslation } from "../hooks/useTranslation";
|
||||
import { getProjects, deleteProject, type Project } from "../api/projects";
|
||||
@@ -9,7 +9,7 @@ import { ProjectCreateModal } from "../components/projects/ProjectCreateModal";
|
||||
import { ProjectEditModal } from "../components/projects/ProjectEditModal";
|
||||
import { ProjectAccessModal } from "../components/projects/ProjectAccessModal";
|
||||
import { Pagination } from "../components/Pagination";
|
||||
import { Plus, Archive, Building2, Pencil, ShieldCheck, Trash2, X } from "lucide-react";
|
||||
import { Plus, Building2, Pencil, ShieldCheck, Trash2, X } from "lucide-react";
|
||||
|
||||
import EmptyStateCard from "../components/EmptyStateCard";
|
||||
import FilterBar from "../components/FilterBar";
|
||||
@@ -19,6 +19,7 @@ import { Card, CardContent, CardTitle } from "../components/ui/card";
|
||||
import { Modal } from "../components/Modal";
|
||||
import { toast } from "sonner";
|
||||
import { Input } from "../components/ui/input";
|
||||
import { MultiSearchableSelect } from "../components/ui/MultiSearchableSelect";
|
||||
import {
|
||||
PROJECTS_ARCHIVE,
|
||||
PROJECTS_CREATE,
|
||||
@@ -148,7 +149,8 @@ export const Projects: React.FC = () => {
|
||||
};
|
||||
}, [activeWorkspace?.id, currentPage, limit, search, isArchived, ordering, selectedClientIdsKey]);
|
||||
|
||||
const confirmDelete = async () => {
|
||||
const confirmDelete = async (event?: FormEvent<HTMLFormElement>) => {
|
||||
event?.preventDefault();
|
||||
if (!deleteModal.project) return;
|
||||
try {
|
||||
const deletedId = deleteModal.project.id;
|
||||
@@ -188,13 +190,16 @@ export const Projects: React.FC = () => {
|
||||
return [...selected, ...unselected];
|
||||
}, [clients, selectedClientIdsKey]);
|
||||
|
||||
const toggleClientFilter = (clientId: string) => {
|
||||
const nextClientIds = selectedClientIds.includes(clientId)
|
||||
? selectedClientIds.filter((id) => id !== clientId)
|
||||
: [...selectedClientIds, clientId];
|
||||
const clientOptions = useMemo(
|
||||
() =>
|
||||
sortedClients.map((client) => ({
|
||||
value: client.id,
|
||||
label: client.name,
|
||||
})),
|
||||
[sortedClients],
|
||||
);
|
||||
|
||||
updateListParams({ clients: nextClientIds, page: 1 });
|
||||
};
|
||||
const hasActiveProjectFilters = selectedClientIds.length > 0 || isArchived;
|
||||
|
||||
const updateListParams = (
|
||||
updates: Record<string, string | number | boolean | null | undefined | string[]>,
|
||||
@@ -243,16 +248,6 @@ export const Projects: React.FC = () => {
|
||||
{t.projects?.manageAccess || "Manage access"}
|
||||
</Button>
|
||||
)}
|
||||
{canArchiveProject && (
|
||||
<Button
|
||||
variant={isArchived ? "default" : "secondary"}
|
||||
onClick={() => updateListParams({ archived: !isArchived, page: 1 })}
|
||||
className="flex-1 gap-2 shadow-sm sm:flex-none"
|
||||
>
|
||||
<Archive className="h-4 w-4" />
|
||||
{isArchived ? (t.projects?.active || 'Active Projects') : (t.projects?.archived || 'Archived Projects')}
|
||||
</Button>
|
||||
)}
|
||||
{canCreateProject && (
|
||||
<Button
|
||||
onClick={() => setIsCreateModalOpen(true)}
|
||||
@@ -277,63 +272,81 @@ export const Projects: React.FC = () => {
|
||||
searchPlaceholder={t.projects?.searchPlaceholder || 'Search projects...'}
|
||||
/>
|
||||
|
||||
<div className="mt-4 flex items-center justify-between gap-3">
|
||||
<div className="mt-4 flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between">
|
||||
<div className="grid gap-3 md:grid-cols-[minmax(0,1fr)_auto] lg:flex-1">
|
||||
<div className="space-y-2">
|
||||
<div className="text-xs font-semibold uppercase tracking-[0.14em] text-slate-400 dark:text-slate-500">
|
||||
{t.projects?.filterClients || "Filter by client"}
|
||||
</div>
|
||||
{selectedClientIds.length > 0 ? (
|
||||
<MultiSearchableSelect
|
||||
values={selectedClientIds}
|
||||
onChange={(values) => updateListParams({ clients: values, page: 1 })}
|
||||
options={clientOptions}
|
||||
placeholder={t.reports?.allClients || "All clients"}
|
||||
searchPlaceholder={t.reports?.searchClients || "Search clients..."}
|
||||
emptyLabel={t.clients?.noClients || "No clients found"}
|
||||
renderValue={(selectedOptions) => {
|
||||
if (selectedOptions.length === 0) {
|
||||
return t.reports?.allClients || "All clients";
|
||||
}
|
||||
if (selectedOptions.length <= 2) {
|
||||
return selectedOptions.map((option) => option.label).join(", ");
|
||||
}
|
||||
return `${selectedOptions[0]?.label} +${selectedOptions.length - 1}`;
|
||||
}}
|
||||
buttonClassName="min-h-11 w-full rounded-xl border-slate-200 bg-slate-50/80 dark:border-slate-700"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{canArchiveProject ? (
|
||||
<div className="space-y-2">
|
||||
<div className="text-xs font-semibold uppercase tracking-[0.14em] text-slate-400 dark:text-slate-500">
|
||||
{t.projects?.archived || "Archived Projects"}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
updateListParams({ clients: [], page: 1 });
|
||||
}}
|
||||
className="text-xs font-medium text-slate-500 transition hover:text-slate-900 dark:text-slate-400 dark:hover:text-white"
|
||||
role="switch"
|
||||
aria-checked={isArchived}
|
||||
aria-label={t.projects?.archived || "Archived Projects"}
|
||||
onClick={() => updateListParams({ archived: !isArchived, page: 1 })}
|
||||
className={`inline-flex min-h-11 w-full items-center justify-between gap-3 rounded-xl border px-3 py-2 text-sm font-medium transition md:w-auto ${
|
||||
isArchived
|
||||
? "border-amber-300 bg-amber-50 text-amber-800 dark:border-amber-500/30 dark:bg-amber-500/15 dark:text-amber-300"
|
||||
: "border-slate-200 bg-slate-50/80 text-slate-600 hover:border-slate-300 hover:text-slate-900 dark:border-slate-700 dark:bg-slate-950/60 dark:text-slate-300 dark:hover:border-slate-600 dark:hover:text-white"
|
||||
}`}
|
||||
>
|
||||
{t.projects?.clearClientFilters || "Clear filters"}
|
||||
<span>{t.projects?.archived || "Archived Projects"}</span>
|
||||
<span
|
||||
className={`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition ${
|
||||
isArchived ? "bg-amber-500 dark:bg-amber-400" : "bg-slate-300 dark:bg-slate-700"
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
className={`inline-block h-5 w-5 rounded-full bg-white shadow-sm transition-transform ${
|
||||
isArchived ? "translate-x-5 rtl:-translate-x-5" : "translate-x-0.5 rtl:-translate-x-0.5"
|
||||
}`}
|
||||
/>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="mt-3 overflow-x-auto pb-2">
|
||||
<div className="flex min-w-max items-center gap-2">
|
||||
{sortedClients.map((client) => {
|
||||
const isSelected = selectedClientIds.includes(client.id);
|
||||
return (
|
||||
<button
|
||||
key={client.id}
|
||||
type="button"
|
||||
onClick={() => toggleClientFilter(client.id)}
|
||||
className={`inline-flex items-center gap-2 rounded-full border px-3 py-2 text-sm font-medium transition ${
|
||||
isSelected
|
||||
? "border-sky-200 bg-sky-50 text-sky-700 dark:border-sky-500/30 dark:bg-sky-500/10 dark:text-sky-300"
|
||||
: "border-slate-200 bg-slate-50 text-slate-600 hover:border-slate-300 hover:bg-slate-100 dark:border-slate-700 dark:bg-slate-950/60 dark:text-slate-300 dark:hover:border-slate-600 dark:hover:bg-slate-800"
|
||||
}`}
|
||||
>
|
||||
<span className="whitespace-nowrap">{client.name}</span>
|
||||
{isSelected ? (
|
||||
<span
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
toggleClientFilter(client.id);
|
||||
onClick={() => {
|
||||
updateListParams({ clients: [], archived: false, page: 1 });
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
toggleClientFilter(client.id);
|
||||
}
|
||||
}}
|
||||
className="inline-flex h-4 w-4 items-center justify-center rounded-full bg-sky-100 text-sky-700 dark:bg-sky-500/20 dark:text-sky-200"
|
||||
disabled={!hasActiveProjectFilters}
|
||||
aria-label={t.projects?.clearClientFilters || "Clear filters"}
|
||||
className={`inline-flex h-10 w-10 items-center justify-center self-start rounded-xl border text-sm transition lg:self-end ${
|
||||
hasActiveProjectFilters
|
||||
? "border-red-200 bg-red-50 text-red-700 hover:border-red-300 hover:bg-red-100 hover:text-red-800 dark:border-red-500/30 dark:bg-red-500/15 dark:text-red-300 dark:hover:border-red-400 dark:hover:bg-red-500/20 dark:hover:text-red-200"
|
||||
: "border-slate-200 bg-white text-slate-400 opacity-60 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-500"
|
||||
} disabled:cursor-not-allowed`}
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
</span>
|
||||
) : null}
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -362,9 +375,15 @@ export const Projects: React.FC = () => {
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<div
|
||||
className="h-10 w-10 shrink-0 rounded-xl border border-slate-200 dark:border-slate-700"
|
||||
className="flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-xl border border-slate-200 text-sm font-semibold text-white dark:border-slate-700"
|
||||
style={{ backgroundColor: project.color || "#3B82F6" }}
|
||||
/>
|
||||
>
|
||||
{project.thumbnail ? (
|
||||
<img src={project.thumbnail} alt={project.name} className="h-full w-full object-cover" />
|
||||
) : (
|
||||
project.name.trim().charAt(0).toUpperCase() || "P"
|
||||
)}
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<CardTitle className="truncate text-base text-slate-900 dark:text-white">{project.name}</CardTitle>
|
||||
<div className="mt-1 text-sm text-slate-500 dark:text-slate-400">
|
||||
@@ -483,6 +502,20 @@ export const Projects: React.FC = () => {
|
||||
accessOff: t.projects?.accessOff || "No access",
|
||||
loadError: t.projects?.accessLoadError || "Failed to load project access state.",
|
||||
saveError: t.projects?.accessSaveError || "Failed to update project access.",
|
||||
workspaceRate: t.rates?.workspaceRate || "Workspace rate",
|
||||
projectOverride: t.rates?.projectOverride || "Project override",
|
||||
inheritsWorkspaceRate: t.rates?.inheritsWorkspaceRate || "Inherits workspace rate",
|
||||
noRate: t.rates?.noRate || "No rate",
|
||||
hourlyRatePlaceholder: t.rates?.hourlyRatePlaceholder || "0.00",
|
||||
currencyPlaceholder: t.rates?.currencyPlaceholder || "USD",
|
||||
removeRate: t.rates?.removeRate || "Remove rate",
|
||||
projectRateSaved: t.rates?.projectSaveSuccess || "Project user rate saved.",
|
||||
projectRateRemoved: t.rates?.projectRemoveSuccess || "Project user rate removed.",
|
||||
projectRateSaveError: t.rates?.projectSaveError || "Failed to save project user rate.",
|
||||
projectRateRemoveError: t.rates?.projectRemoveError || "Failed to remove project user rate.",
|
||||
implicitAccessHint:
|
||||
t.projects?.implicitAccessHint ||
|
||||
"Owners and admins always have access to all projects. You can still set project-specific rate overrides here.",
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
@@ -511,7 +544,8 @@ export const Projects: React.FC = () => {
|
||||
<Button
|
||||
variant="destructive"
|
||||
disabled={deleteInput !== deleteModal.project.name}
|
||||
onClick={confirmDelete}
|
||||
type="submit"
|
||||
form="delete-project-form"
|
||||
className="rounded-xl font-semibold"
|
||||
>
|
||||
{t.actions?.delete || 'Delete'}
|
||||
@@ -519,7 +553,7 @@ export const Projects: React.FC = () => {
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="flex flex-col gap-4">
|
||||
<form id="delete-project-form" onSubmit={confirmDelete} className="flex flex-col gap-4">
|
||||
<p className="text-slate-600 dark:text-slate-400 text-sm leading-relaxed">
|
||||
{t.projects?.deleteWarning || 'To confirm deletion, please type the project name:'} <strong className="text-slate-900 dark:text-white select-all">{deleteModal.project.name}</strong>
|
||||
</p>
|
||||
@@ -530,7 +564,7 @@ export const Projects: React.FC = () => {
|
||||
onChange={(e) => setDeleteInput(e.target.value)}
|
||||
placeholder={deleteModal.project.name}
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
|
||||
@@ -10,10 +10,12 @@ import {
|
||||
getChartReport,
|
||||
getDayDetailsReport,
|
||||
getTableReport,
|
||||
getUserSummaryReport,
|
||||
type ChartReportResponse,
|
||||
type DayDetailsResponse,
|
||||
type ReportFilters,
|
||||
type TableReportResponse,
|
||||
type UserScopedTableReport,
|
||||
} from "../api/reports";
|
||||
import { getTags, type Tag } from "../api/tags";
|
||||
import { fetchWorkspaceMemberships, type WorkspaceMembership } from "../api/workspaces";
|
||||
@@ -262,6 +264,13 @@ export default function Reports() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleLoadUserSummaryReport = async (userId: string): Promise<UserScopedTableReport> => {
|
||||
if (!apiFilters) {
|
||||
throw new Error("Missing report filters");
|
||||
}
|
||||
return getUserSummaryReport(apiFilters, userId);
|
||||
};
|
||||
|
||||
if (!activeWorkspace) {
|
||||
return (
|
||||
<div className="p-6">
|
||||
@@ -362,13 +371,10 @@ export default function Reports() {
|
||||
}}
|
||||
/>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="rounded-2xl border border-slate-200 bg-white p-6 text-sm text-slate-600 dark:border-slate-800 dark:bg-slate-900 dark:text-slate-300">
|
||||
{t.loading || "Loading..."}
|
||||
</div>
|
||||
) : tab === "chart" ? (
|
||||
{tab === "chart" ? (
|
||||
<ReportsChartPanel
|
||||
data={chartData}
|
||||
isLoading={isLoading}
|
||||
labels={{
|
||||
totalHours: t.reports?.totalHours || "Total hours",
|
||||
billableHours: t.reports?.billableHours || "Billable hours",
|
||||
@@ -376,6 +382,7 @@ export default function Reports() {
|
||||
totalIncome: t.reports?.totalIncome || "Total income",
|
||||
chart: t.reports?.chartTitle || "Activity chart",
|
||||
totalSeconds: t.reports?.totalSeconds || "Total seconds",
|
||||
loading: t.loading || "Loading...",
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
@@ -384,8 +391,10 @@ export default function Reports() {
|
||||
dayDetails={dayDetails}
|
||||
openDay={openDay}
|
||||
onToggleDay={(day) => void handleToggleDay(day)}
|
||||
onLoadUserSummaryReport={(userId) => handleLoadUserSummaryReport(userId)}
|
||||
onExport={(type) => void handleExport(type)}
|
||||
exportState={exportState}
|
||||
isLoading={isLoading}
|
||||
labels={{
|
||||
exportExcel: t.reports?.exportExcel || "Export Excel",
|
||||
exportPdf: t.reports?.exportPdf || "Export PDF",
|
||||
@@ -409,13 +418,19 @@ export default function Reports() {
|
||||
userSummaryDetailsTitle: t.reports?.userSummaryDetailsTitle || "User details: {name}",
|
||||
userSummaryDetailsDescription: t.reports?.userSummaryDetailsDescription || "Detailed rate history and distribution for the selected user.",
|
||||
rateHistory: t.reports?.rateHistory || "Rate history",
|
||||
project: t.reports?.project || "Project",
|
||||
fromDate: t.reports?.fromDate || "From",
|
||||
toDate: t.reports?.toDate || "To",
|
||||
now: t.reports?.now || "Now",
|
||||
loadDetailsError: t.reports?.loadError || "Failed to load user report details.",
|
||||
hourPercentage: t.reports?.hourPercentage || "Hour %",
|
||||
incomePercentage: t.reports?.incomePercentage || "Income %",
|
||||
noData: t.reports?.noData || "No data",
|
||||
clientsTable: t.reports?.clientsTable || "Clients",
|
||||
projectsTable: t.reports?.projectsTable || "Projects",
|
||||
tagsTable: t.reports?.tagsTable || "Tags",
|
||||
noDescription: t.timesheet?.emptyDescription || "No description",
|
||||
loading: t.loading || "Loading...",
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useState, type FormEvent } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import { Edit2, Plus, Tag as TagIcon, Trash2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
@@ -105,7 +105,8 @@ export default function Tags() {
|
||||
setFormColor(DEFAULT_COLOR);
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const handleSubmit = async (event?: FormEvent<HTMLFormElement>) => {
|
||||
event?.preventDefault();
|
||||
if (!activeWorkspace?.id || !formName.trim()) return;
|
||||
|
||||
try {
|
||||
@@ -284,13 +285,13 @@ export default function Tags() {
|
||||
<Button variant="secondary" onClick={closeModal}>
|
||||
{t.actions?.cancel || "Cancel"}
|
||||
</Button>
|
||||
<Button onClick={() => void handleSubmit()} disabled={isSaving || !formName.trim()}>
|
||||
<Button type="submit" form="tag-form" disabled={isSaving || !formName.trim()}>
|
||||
{isSaving ? "..." : (editingTag ? (t.save || "Save") : (t.create || "Create"))}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
<form id="tag-form" onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">
|
||||
{t.tags?.nameLabel || "Tag name"}
|
||||
@@ -304,7 +305,7 @@ export default function Tags() {
|
||||
</label>
|
||||
<input type="color" value={formColor} onChange={(event) => setFormColor(event.target.value)} className="h-10 w-14 cursor-pointer rounded-md border border-slate-200 dark:border-slate-700 bg-transparent" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
{deleteModal.tag && (
|
||||
@@ -320,21 +321,28 @@ export default function Tags() {
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={() => {
|
||||
if (!deleteModal.tag) return;
|
||||
void handleDelete(deleteModal.tag);
|
||||
setDeleteModal({ isOpen: false, tag: null });
|
||||
}}
|
||||
type="submit"
|
||||
form="delete-tag-form"
|
||||
>
|
||||
{t.actions?.delete || "Delete"}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form
|
||||
id="delete-tag-form"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
if (!deleteModal.tag) return;
|
||||
void handleDelete(deleteModal.tag);
|
||||
setDeleteModal({ isOpen: false, tag: null });
|
||||
}}
|
||||
>
|
||||
<p className="text-sm leading-relaxed text-slate-600 dark:text-slate-400">
|
||||
{(t.tags?.deleteConfirmMessage as ((name: string) => string) | undefined)?.(deleteModal.tag.name) ||
|
||||
`Are you sure you want to delete "${deleteModal.tag.name}"?`}
|
||||
</p>
|
||||
</form>
|
||||
</Modal>
|
||||
)}
|
||||
</div>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,6 +26,7 @@ import {
|
||||
import { useAppContext } from '../context/AppContext';
|
||||
import { useWorkspace } from '../context/WorkspaceContext';
|
||||
import { useTranslation } from '../hooks/useTranslation';
|
||||
import { formatRateDisplay } from '../lib/money';
|
||||
import {
|
||||
CLIENTS_VIEW,
|
||||
PROJECTS_VIEW,
|
||||
@@ -188,14 +189,17 @@ export default function WorkspaceDetail() {
|
||||
return `${firstName}${lastName}`.trim().toUpperCase() || getMemberName(member).charAt(0).toUpperCase();
|
||||
};
|
||||
|
||||
const formatRateUnit = (rate?: WorkspaceUserRate) => {
|
||||
if (!rate) return t.rates?.noRate || 'No rate';
|
||||
const unitLabel =
|
||||
lang === 'fa'
|
||||
? rate.price_unit?.local_name || rate.price_unit?.code || rate.currency
|
||||
: rate.price_unit?.code || rate.currency;
|
||||
return `${rate.hourly_rate} ${unitLabel}`;
|
||||
};
|
||||
const formatRateUnit = (rate?: WorkspaceUserRate) =>
|
||||
rate
|
||||
? formatRateDisplay(
|
||||
{
|
||||
hourly_rate: rate.hourly_rate,
|
||||
currency: rate.currency,
|
||||
price_unit: rate.price_unit,
|
||||
},
|
||||
lang,
|
||||
)
|
||||
: (t.rates?.noRate || 'No rate');
|
||||
|
||||
const workspaceRole = workspace?.my_role;
|
||||
const canEdit = canWorkspace(workspaceRole, WORKSPACE_EDIT);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useEffect, useRef, Fragment, useMemo, useCallback } from 'react';
|
||||
import { useBlocker, useNavigate, useParams } from 'react-router-dom';
|
||||
import { useTranslation } from '../hooks/useTranslation';
|
||||
import { AlertCircle, UserPlus, Trash2, Shield, UploadCloud } from 'lucide-react';
|
||||
import { AlertCircle, ShieldCheck, UserPlus, Trash2, Shield, UploadCloud } from 'lucide-react';
|
||||
import { Dialog, Transition } from '@headlessui/react';
|
||||
import { toast } from 'sonner';
|
||||
import { getPriceUnits, getWorkspaceUserRates, type PriceUnit, type WorkspaceUserRate } from '../api/rates';
|
||||
@@ -29,6 +29,8 @@ import { Select } from '../components/ui/Select';
|
||||
import { Input } from '../components/ui/input';
|
||||
import { TextAreaInput } from '../components/ui/TextAreaInput';
|
||||
import WorkspaceMemberRateFields from '../components/rates/WorkspaceMemberRateFields';
|
||||
import { ProjectAccessModal } from '../components/projects/ProjectAccessModal';
|
||||
import { WorkspaceMemberImportModal } from '../components/workspaces/WorkspaceMemberImportModal';
|
||||
|
||||
const toEnglishDigits = (str: string) => {
|
||||
return str.replace(/[۰-۹]/g, (d) => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d).toString())
|
||||
@@ -82,6 +84,8 @@ export default function EditWorkspace() {
|
||||
// Modal State
|
||||
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
|
||||
const [memberIdToDelete, setMemberIdToDelete] = useState<string | null>(null);
|
||||
const [isProjectAccessModalOpen, setIsProjectAccessModalOpen] = useState(false);
|
||||
const [isMemberImportModalOpen, setIsMemberImportModalOpen] = useState(false);
|
||||
|
||||
const searchTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
@@ -197,6 +201,19 @@ export default function EditWorkspace() {
|
||||
}
|
||||
};
|
||||
|
||||
const refreshMembersAndRates = async () => {
|
||||
if (!id) return;
|
||||
const [membersData, ratesData] = await Promise.all([
|
||||
fetchWorkspaceMemberships({ workspace: id, limit: LIMIT, offset: 0 }),
|
||||
getWorkspaceUserRates(id),
|
||||
]);
|
||||
const results = membersData.results || (Array.isArray(membersData) ? membersData : []);
|
||||
setMembers(results);
|
||||
setWorkspaceRates(ratesData.results || []);
|
||||
setOffset(LIMIT);
|
||||
setHasMore(membersData.next ? true : results.length >= LIMIT);
|
||||
};
|
||||
|
||||
const loadMoreMembers = useCallback(async () => {
|
||||
if (isLoadingMembers || !hasMore || !id) return;
|
||||
try {
|
||||
@@ -339,6 +356,7 @@ export default function EditWorkspace() {
|
||||
if (isLoading) return <div className="p-8 text-center">{t.workspace?.loading || "Loading..."}</div>;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="absolute inset-0 flex flex-col overflow-y-auto bg-slate-50 p-4 dark:bg-slate-900 lg:overflow-hidden sm:p-6">
|
||||
<h1 className="text-2xl font-bold text-slate-900 dark:text-white mb-4 sm:mb-6 shrink-0">
|
||||
{t.workspace?.editTitle || "Edit Workspace"}
|
||||
@@ -432,9 +450,43 @@ export default function EditWorkspace() {
|
||||
|
||||
<div className="w-full rounded-xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900 lg:flex lg:w-2/3 lg:min-h-0 lg:flex-1 lg:flex-col lg:overflow-hidden">
|
||||
<div className="p-6 shrink-0 border-b border-slate-100 dark:border-slate-800 bg-white dark:bg-slate-900 z-10">
|
||||
<h2 className="text-lg font-semibold text-slate-900 dark:text-white mb-4">
|
||||
<div className="mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<h2 className="text-lg font-semibold text-slate-900 dark:text-white">
|
||||
{ t.workspace?.members || "Members" }
|
||||
</h2>
|
||||
<div className="flex flex-wrap gap-2 self-start sm:self-auto">
|
||||
{canWorkspace(myRole, WORKSPACE_MEMBERS_ADD) && id ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => setIsMemberImportModalOpen(true)}
|
||||
className="gap-2"
|
||||
>
|
||||
<UploadCloud className="h-4 w-4" />
|
||||
{t.workspace?.memberImport?.button || "Import members"}
|
||||
</Button>
|
||||
) : null}
|
||||
{canWorkspace(myRole, WORKSPACE_EDIT) && id ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => setIsProjectAccessModalOpen(true)}
|
||||
className="gap-2"
|
||||
>
|
||||
<ShieldCheck className="h-4 w-4" />
|
||||
{t.projects?.manageAccess || "Projects & Rates"}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mb-4 flex items-start gap-3 rounded-xl border border-sky-100 bg-sky-50/80 px-4 py-3 text-sm text-sky-900 dark:border-sky-900/60 dark:bg-sky-950/30 dark:text-sky-100">
|
||||
<AlertCircle className="mt-0.5 h-4 w-4 shrink-0" />
|
||||
<p className="leading-6">
|
||||
{t.workspace?.projectRateHint ||
|
||||
"Project-specific user rates can be managed from the Projects page. Open a project and use its access modal to set an override rate for a specific member."}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{canWorkspace(myRole, WORKSPACE_MEMBERS_ADD) && (
|
||||
<div className="space-y-3">
|
||||
@@ -651,5 +703,108 @@ export default function EditWorkspace() {
|
||||
</Dialog>
|
||||
</Transition>
|
||||
</div>
|
||||
|
||||
{canWorkspace(myRole, WORKSPACE_EDIT) && id ? (
|
||||
<ProjectAccessModal
|
||||
isOpen={isProjectAccessModalOpen}
|
||||
onClose={() => setIsProjectAccessModalOpen(false)}
|
||||
workspaceId={id}
|
||||
onApplied={() => {}}
|
||||
labels={{
|
||||
title: t.projects?.accessModalTitle || "Projects & Rates",
|
||||
description:
|
||||
t.projects?.accessModalDescription ||
|
||||
"Manage project access for members and guests, and set project-specific rates for any workspace user.",
|
||||
close: t.actions?.cancel || "Close",
|
||||
member: t.projects?.accessMemberLabel || "User",
|
||||
projects: t.sidebar?.projects || "Projects",
|
||||
loading: t.loading || "Loading...",
|
||||
noMembers: t.projects?.accessNoMembers || "No workspace users were found.",
|
||||
noProjects: t.projects?.accessNoProjects || "No projects found.",
|
||||
searchPlaceholder: t.projects?.searchPlaceholder || "Search projects...",
|
||||
allClients: t.reports?.allClients || "All clients",
|
||||
selectAllVisible: t.projects?.accessSelectVisible || "Select all visible",
|
||||
clearSelection: t.projects?.accessClearSelection || "Clear selection",
|
||||
selectClientProjects: t.projects?.accessSelectClientProjects || "Select all projects for client",
|
||||
grantSelected: t.projects?.accessGrant || "Grant selected",
|
||||
revokeSelected: t.projects?.accessRevoke || "Revoke selected",
|
||||
accessGranted: t.projects?.accessGrantSuccess || "Project access granted.",
|
||||
accessRevoked: t.projects?.accessRevokeSuccess || "Project access revoked.",
|
||||
memberRole: t.workspace?.roleLabel || "Role",
|
||||
client: t.projects?.clientLabel || "Client",
|
||||
noClient: t.projects?.noClient || "No client",
|
||||
accessOn: t.projects?.accessOn || "Has access",
|
||||
accessOff: t.projects?.accessOff || "No access",
|
||||
loadError: t.projects?.accessLoadError || "Failed to load project access state.",
|
||||
saveError: t.projects?.accessSaveError || "Failed to update project access.",
|
||||
workspaceRate: t.rates?.workspaceRate || "Workspace rate",
|
||||
projectOverride: t.rates?.projectOverride || "Project override",
|
||||
inheritsWorkspaceRate: t.rates?.inheritsWorkspaceRate || "Inherits workspace rate",
|
||||
noRate: t.rates?.noRate || "No rate",
|
||||
hourlyRatePlaceholder: t.rates?.hourlyRatePlaceholder || "0.00",
|
||||
currencyPlaceholder: t.rates?.currencyPlaceholder || "USD",
|
||||
removeRate: t.rates?.removeRate || "Remove rate",
|
||||
projectRateSaved: t.rates?.projectSaveSuccess || "Project user rate saved.",
|
||||
projectRateRemoved: t.rates?.projectRemoveSuccess || "Project user rate removed.",
|
||||
projectRateSaveError: t.rates?.projectSaveError || "Failed to save project user rate.",
|
||||
projectRateRemoveError: t.rates?.projectRemoveError || "Failed to remove project user rate.",
|
||||
implicitAccessHint:
|
||||
t.projects?.implicitAccessHint ||
|
||||
"Owners and admins always have access to all projects. You can still set project-specific rate overrides here.",
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
{canWorkspace(myRole, WORKSPACE_MEMBERS_ADD) && id ? (
|
||||
<WorkspaceMemberImportModal
|
||||
isOpen={isMemberImportModalOpen}
|
||||
onClose={() => setIsMemberImportModalOpen(false)}
|
||||
workspaceId={id}
|
||||
priceUnits={priceUnits}
|
||||
onImported={refreshMembersAndRates}
|
||||
labels={{
|
||||
title: t.workspace?.memberImport?.title || "Import members",
|
||||
description:
|
||||
t.workspace?.memberImport?.description ||
|
||||
"Upload a file with mobile, role, hourly_rate, and currency columns. Mobile is required; role defaults to member.",
|
||||
uploadTitle: t.workspace?.memberImport?.uploadTitle || "Upload member file",
|
||||
uploadDescription: t.workspace?.memberImport?.uploadDescription || "CSV, TSV, TXT, or XLSX. The first row must contain headers.",
|
||||
sampleCsv: t.workspace?.memberImport?.sampleCsv || "CSV sample",
|
||||
sampleTsv: t.workspace?.memberImport?.sampleTsv || "TSV sample",
|
||||
sampleTxt: t.workspace?.memberImport?.sampleTxt || "TXT sample",
|
||||
sampleXlsx: t.workspace?.memberImport?.sampleXlsx || "XLSX sample",
|
||||
validate: t.workspace?.memberImport?.validate || "Validate file",
|
||||
validating: t.workspace?.memberImport?.validating || "Validating...",
|
||||
import: t.workspace?.memberImport?.import || "Import members",
|
||||
importing: t.workspace?.memberImport?.importing || "Importing...",
|
||||
close: t.actions?.cancel || "Close",
|
||||
chooseFile: t.workspace?.memberImport?.chooseFile || "Choose file",
|
||||
selectedFile: t.workspace?.memberImport?.selectedFile || "Selected file",
|
||||
validRows: t.workspace?.memberImport?.validRows || "Valid rows",
|
||||
invalidRows: t.workspace?.memberImport?.invalidRows || "Invalid rows",
|
||||
totalRows: t.workspace?.memberImport?.totalRows || "Total rows",
|
||||
line: t.workspace?.memberImport?.line || "Line",
|
||||
mobile: t.workspace?.memberImport?.mobile || "Mobile",
|
||||
user: t.workspace?.memberImport?.user || "User",
|
||||
role: t.workspace?.memberImport?.role || "Role",
|
||||
hourlyRate: t.workspace?.memberImport?.hourlyRate || "Hourly rate",
|
||||
currency: t.workspace?.memberImport?.currency || "Currency",
|
||||
status: t.workspace?.memberImport?.status || "Status",
|
||||
messages: t.workspace?.memberImport?.messages || "Messages",
|
||||
valid: t.workspace?.memberImport?.valid || "Valid",
|
||||
invalid: t.workspace?.memberImport?.invalid || "Invalid",
|
||||
noRows: t.workspace?.memberImport?.noRows || "No rows loaded yet.",
|
||||
localErrors: t.workspace?.memberImport?.localErrors || "Fix local file errors before backend validation.",
|
||||
success: t.workspace?.memberImport?.success || "Members imported successfully.",
|
||||
parseFailed: t.workspace?.memberImport?.parseFailed || "Failed to parse the file.",
|
||||
missingMobile: t.workspace?.memberImport?.missingMobile || "Mobile is required.",
|
||||
duplicateMobile: t.workspace?.memberImport?.duplicateMobile || "This mobile appears more than once.",
|
||||
invalidRole: t.workspace?.memberImport?.invalidRole || "Role must be admin, member, or guest.",
|
||||
invalidRate: t.workspace?.memberImport?.invalidRate || "Hourly rate must be a valid positive number.",
|
||||
rateCurrencyPair: t.workspace?.memberImport?.rateCurrencyPair || "Hourly rate and currency must be provided together.",
|
||||
tooManyRows: t.workspace?.memberImport?.tooManyRows || "Import is limited to 500 rows.",
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useState, type FormEvent } from 'react';
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { Plus, Trash2, Pencil, Eye, LayoutDashboard } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
@@ -94,7 +94,8 @@ export default function Workspaces() {
|
||||
}
|
||||
};
|
||||
|
||||
const confirmDelete = async () => {
|
||||
const confirmDelete = async (event?: FormEvent<HTMLFormElement>) => {
|
||||
event?.preventDefault();
|
||||
if (!deleteModal.workspace) return;
|
||||
try {
|
||||
const deletedId = deleteModal.workspace.id;
|
||||
@@ -275,7 +276,8 @@ export default function Workspaces() {
|
||||
<Button
|
||||
variant="destructive"
|
||||
disabled={deleteInput !== deleteModal.workspace.name}
|
||||
onClick={confirmDelete}
|
||||
type="submit"
|
||||
form="delete-workspace-form"
|
||||
className="rounded-xl font-semibold"
|
||||
>
|
||||
{t.actions?.delete || 'Delete'}
|
||||
@@ -283,7 +285,7 @@ export default function Workspaces() {
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="flex flex-col gap-4">
|
||||
<form id="delete-workspace-form" onSubmit={confirmDelete} className="flex flex-col gap-4">
|
||||
<p className="text-slate-600 dark:text-slate-400 text-sm leading-relaxed">
|
||||
{t.workspace?.deleteWarning || 'To confirm deletion, please type the workspace name:'} <strong className="text-slate-900 dark:text-white select-all">{deleteModal.workspace.name}</strong>
|
||||
</p>
|
||||
@@ -294,7 +296,7 @@ export default function Workspaces() {
|
||||
onChange={(e) => setDeleteInput(e.target.value)}
|
||||
placeholder={deleteModal.workspace.name}
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { toast } from "sonner"
|
||||
import { ApiError } from "../../api/client"
|
||||
import { setSessionTokens } from "../../lib/session"
|
||||
|
||||
const PERSIAN_DIGITS = ["\u06f0", "\u06f1", "\u06f2", "\u06f3", "\u06f4", "\u06f5", "\u06f6", "\u06f7", "\u06f8", "\u06f9"]
|
||||
const PERSIAN_DIGITS = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"]
|
||||
|
||||
export const localizeDigits = (value: string, isRtl: boolean) =>
|
||||
isRtl ? value.replace(/\d/g, (digit) => PERSIAN_DIGITS[Number.parseInt(digit, 10)] ?? digit) : value
|
||||
|
||||
@@ -9,6 +9,7 @@ export interface Client {
|
||||
id: string;
|
||||
name: string;
|
||||
notes: string | null;
|
||||
thumbnail?: string | null;
|
||||
workspace: string;
|
||||
created_by?: AuditUser | null;
|
||||
can_delete: boolean;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
Reference in New Issue
Block a user