Initial commit of react-revamp for Auditor Portal
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
73
README.md
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
# React + TypeScript + Vite
|
||||||
|
|
||||||
|
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||||
|
|
||||||
|
Currently, two official plugins are available:
|
||||||
|
|
||||||
|
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
||||||
|
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
||||||
|
|
||||||
|
## React Compiler
|
||||||
|
|
||||||
|
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||||
|
|
||||||
|
## Expanding the ESLint configuration
|
||||||
|
|
||||||
|
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||||
|
|
||||||
|
```js
|
||||||
|
export default defineConfig([
|
||||||
|
globalIgnores(['dist']),
|
||||||
|
{
|
||||||
|
files: ['**/*.{ts,tsx}'],
|
||||||
|
extends: [
|
||||||
|
// Other configs...
|
||||||
|
|
||||||
|
// Remove tseslint.configs.recommended and replace with this
|
||||||
|
tseslint.configs.recommendedTypeChecked,
|
||||||
|
// Alternatively, use this for stricter rules
|
||||||
|
tseslint.configs.strictTypeChecked,
|
||||||
|
// Optionally, add this for stylistic rules
|
||||||
|
tseslint.configs.stylisticTypeChecked,
|
||||||
|
|
||||||
|
// Other configs...
|
||||||
|
],
|
||||||
|
languageOptions: {
|
||||||
|
parserOptions: {
|
||||||
|
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||||
|
tsconfigRootDir: import.meta.dirname,
|
||||||
|
},
|
||||||
|
// other options...
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||||
|
|
||||||
|
```js
|
||||||
|
// eslint.config.js
|
||||||
|
import reactX from 'eslint-plugin-react-x'
|
||||||
|
import reactDom from 'eslint-plugin-react-dom'
|
||||||
|
|
||||||
|
export default defineConfig([
|
||||||
|
globalIgnores(['dist']),
|
||||||
|
{
|
||||||
|
files: ['**/*.{ts,tsx}'],
|
||||||
|
extends: [
|
||||||
|
// Other configs...
|
||||||
|
// Enable lint rules for React
|
||||||
|
reactX.configs['recommended-typescript'],
|
||||||
|
// Enable lint rules for React DOM
|
||||||
|
reactDom.configs.recommended,
|
||||||
|
],
|
||||||
|
languageOptions: {
|
||||||
|
parserOptions: {
|
||||||
|
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||||
|
tsconfigRootDir: import.meta.dirname,
|
||||||
|
},
|
||||||
|
// other options...
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
```
|
||||||
22
eslint.config.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import js from '@eslint/js'
|
||||||
|
import globals from 'globals'
|
||||||
|
import reactHooks from 'eslint-plugin-react-hooks'
|
||||||
|
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||||
|
import tseslint from 'typescript-eslint'
|
||||||
|
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||||
|
|
||||||
|
export default defineConfig([
|
||||||
|
globalIgnores(['dist']),
|
||||||
|
{
|
||||||
|
files: ['**/*.{ts,tsx}'],
|
||||||
|
extends: [
|
||||||
|
js.configs.recommended,
|
||||||
|
tseslint.configs.recommended,
|
||||||
|
reactHooks.configs.flat.recommended,
|
||||||
|
reactRefresh.configs.vite,
|
||||||
|
],
|
||||||
|
languageOptions: {
|
||||||
|
globals: globals.browser,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
13
index.html
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>react-revamp</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
3984
package-lock.json
generated
Normal file
40
package.json
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"name": "react-revamp",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "tsc -b && vite build",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@emotion/react": "^11.14.0",
|
||||||
|
"@emotion/styled": "^11.14.1",
|
||||||
|
"@mui/icons-material": "^9.1.0",
|
||||||
|
"@mui/material": "^9.1.0",
|
||||||
|
"axios": "^1.17.0",
|
||||||
|
"react": "^19.2.6",
|
||||||
|
"react-dom": "^19.2.6",
|
||||||
|
"react-hook-form": "^7.78.0",
|
||||||
|
"react-router-dom": "^7.17.0",
|
||||||
|
"socket.io-client": "^4.8.3",
|
||||||
|
"zod": "^4.4.3",
|
||||||
|
"zustand": "^5.0.14"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^10.0.1",
|
||||||
|
"@types/node": "^24.12.3",
|
||||||
|
"@types/react": "^19.2.14",
|
||||||
|
"@types/react-dom": "^19.2.3",
|
||||||
|
"@vitejs/plugin-react": "^6.0.1",
|
||||||
|
"eslint": "^10.3.0",
|
||||||
|
"eslint-plugin-react-hooks": "^7.1.1",
|
||||||
|
"eslint-plugin-react-refresh": "^0.5.2",
|
||||||
|
"globals": "^17.6.0",
|
||||||
|
"typescript": "~6.0.2",
|
||||||
|
"typescript-eslint": "^8.59.2",
|
||||||
|
"vite": "^8.0.12"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
public/assets/images/logo/dashboard_logo.png
Normal file
|
After Width: | Height: | Size: 5.1 KiB |
BIN
public/assets/images/logo/side-bar-logo.png
Normal file
|
After Width: | Height: | Size: 68 KiB |
BIN
public/assets/images/master_and_shift_image_not_available.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
public/assets/images/master_image_not_available.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
public/assets/images/only_master_image_not_available.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
1
public/favicon.svg
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
24
public/icons.svg
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<symbol id="bluesky-icon" viewBox="0 0 16 17">
|
||||||
|
<g clip-path="url(#bluesky-clip)"><path fill="#08060d" d="M7.75 7.735c-.693-1.348-2.58-3.86-4.334-5.097-1.68-1.187-2.32-.981-2.74-.79C.188 2.065.1 2.812.1 3.251s.241 3.602.398 4.13c.52 1.744 2.367 2.333 4.07 2.145-2.495.37-4.71 1.278-1.805 4.512 3.196 3.309 4.38-.71 4.987-2.746.608 2.036 1.307 5.91 4.93 2.746 2.72-2.746.747-4.143-1.747-4.512 1.702.189 3.55-.4 4.07-2.145.156-.528.397-3.691.397-4.13s-.088-1.186-.575-1.406c-.42-.19-1.06-.395-2.741.79-1.755 1.24-3.64 3.752-4.334 5.099"/></g>
|
||||||
|
<defs><clipPath id="bluesky-clip"><path fill="#fff" d="M.1.85h15.3v15.3H.1z"/></clipPath></defs>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="discord-icon" viewBox="0 0 20 19">
|
||||||
|
<path fill="#08060d" d="M16.224 3.768a14.5 14.5 0 0 0-3.67-1.153c-.158.286-.343.67-.47.976a13.5 13.5 0 0 0-4.067 0c-.128-.306-.317-.69-.476-.976A14.4 14.4 0 0 0 3.868 3.77C1.546 7.28.916 10.703 1.231 14.077a14.7 14.7 0 0 0 4.5 2.306q.545-.748.965-1.587a9.5 9.5 0 0 1-1.518-.74q.191-.14.372-.293c2.927 1.369 6.107 1.369 8.999 0q.183.152.372.294-.723.437-1.52.74.418.838.963 1.588a14.6 14.6 0 0 0 4.504-2.308c.37-3.911-.63-7.302-2.644-10.309m-9.13 8.234c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.894 0 1.614.82 1.599 1.82.001 1-.705 1.82-1.6 1.82m5.91 0c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.893 0 1.614.82 1.599 1.82 0 1-.706 1.82-1.6 1.82"/>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="documentation-icon" viewBox="0 0 21 20">
|
||||||
|
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="m15.5 13.333 1.533 1.322c.645.555.967.833.967 1.178s-.322.623-.967 1.179L15.5 18.333m-3.333-5-1.534 1.322c-.644.555-.966.833-.966 1.178s.322.623.966 1.179l1.534 1.321"/>
|
||||||
|
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M17.167 10.836v-4.32c0-1.41 0-2.117-.224-2.68-.359-.906-1.118-1.621-2.08-1.96-.599-.21-1.349-.21-2.848-.21-2.623 0-3.935 0-4.983.369-1.684.591-3.013 1.842-3.641 3.428C3 6.449 3 7.684 3 10.154v2.122c0 2.558 0 3.838.706 4.726q.306.383.713.671c.76.536 1.79.64 3.581.66"/>
|
||||||
|
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M3 10a2.78 2.78 0 0 1 2.778-2.778c.555 0 1.209.097 1.748-.047.48-.129.854-.503.982-.982.145-.54.048-1.194.048-1.749a2.78 2.78 0 0 1 2.777-2.777"/>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="github-icon" viewBox="0 0 19 19">
|
||||||
|
<path fill="#08060d" fill-rule="evenodd" d="M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844" clip-rule="evenodd"/>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="social-icon" viewBox="0 0 20 20">
|
||||||
|
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M12.5 6.667a4.167 4.167 0 1 0-8.334 0 4.167 4.167 0 0 0 8.334 0"/>
|
||||||
|
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M2.5 16.667a5.833 5.833 0 0 1 8.75-5.053m3.837.474.513 1.035c.07.144.257.282.414.309l.93.155c.596.1.736.536.307.965l-.723.73a.64.64 0 0 0-.152.531l.207.903c.164.715-.213.991-.84.618l-.872-.52a.63.63 0 0 0-.577 0l-.872.52c-.624.373-1.003.094-.84-.618l.207-.903a.64.64 0 0 0-.152-.532l-.723-.729c-.426-.43-.289-.864.306-.964l.93-.156a.64.64 0 0 0 .412-.31l.513-1.034c.28-.562.735-.562 1.012 0"/>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="x-icon" viewBox="0 0 19 19">
|
||||||
|
<path fill="#08060d" fill-rule="evenodd" d="M1.893 1.98c.052.072 1.245 1.769 2.653 3.77l2.892 4.114c.183.261.333.48.333.486s-.068.089-.152.183l-.522.593-.765.867-3.597 4.087c-.375.426-.734.834-.798.905a1 1 0 0 0-.118.148c0 .01.236.017.664.017h.663l.729-.83c.4-.457.796-.906.879-.999a692 692 0 0 0 1.794-2.038c.034-.037.301-.34.594-.675l.551-.624.345-.392a7 7 0 0 1 .34-.374c.006 0 .93 1.306 2.052 2.903l2.084 2.965.045.063h2.275c1.87 0 2.273-.003 2.266-.021-.008-.02-1.098-1.572-3.894-5.547-2.013-2.862-2.28-3.246-2.273-3.266.008-.019.282-.332 2.085-2.38l2-2.274 1.567-1.782c.022-.028-.016-.03-.65-.03h-.674l-.3.342a871 871 0 0 1-1.782 2.025c-.067.075-.405.458-.75.852a100 100 0 0 1-.803.91c-.148.172-.299.344-.99 1.127-.304.343-.32.358-.345.327-.015-.019-.904-1.282-1.976-2.808L6.365 1.85H1.8zm1.782.91 8.078 11.294c.772 1.08 1.413 1.973 1.425 1.984.016.017.241.02 1.05.017l1.03-.004-2.694-3.766L7.796 5.75 5.722 2.852l-1.039-.004-1.039-.004z" clip-rule="evenodd"/>
|
||||||
|
</symbol>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 4.9 KiB |
BIN
public/images/SeekRightLogo.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
184
src/App.css
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
.counter {
|
||||||
|
font-size: 16px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
color: var(--accent);
|
||||||
|
background: var(--accent-bg);
|
||||||
|
border: 2px solid transparent;
|
||||||
|
transition: border-color 0.3s;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-color: var(--accent-border);
|
||||||
|
}
|
||||||
|
&:focus-visible {
|
||||||
|
outline: 2px solid var(--accent);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.base,
|
||||||
|
.framework,
|
||||||
|
.vite {
|
||||||
|
inset-inline: 0;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.base {
|
||||||
|
width: 170px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.framework,
|
||||||
|
.vite {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.framework {
|
||||||
|
z-index: 1;
|
||||||
|
top: 34px;
|
||||||
|
height: 28px;
|
||||||
|
transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg)
|
||||||
|
scale(1.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.vite {
|
||||||
|
z-index: 0;
|
||||||
|
top: 107px;
|
||||||
|
height: 26px;
|
||||||
|
width: auto;
|
||||||
|
transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg)
|
||||||
|
scale(0.8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#center {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 25px;
|
||||||
|
place-content: center;
|
||||||
|
place-items: center;
|
||||||
|
flex-grow: 1;
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
padding: 32px 20px 24px;
|
||||||
|
gap: 18px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#next-steps {
|
||||||
|
display: flex;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
text-align: left;
|
||||||
|
|
||||||
|
& > div {
|
||||||
|
flex: 1 1 0;
|
||||||
|
padding: 32px;
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
padding: 24px 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
flex-direction: column;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#docs {
|
||||||
|
border-right: 1px solid var(--border);
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
border-right: none;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#next-steps ul {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
margin: 32px 0 0;
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: var(--text-h);
|
||||||
|
font-size: 16px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: var(--social-bg);
|
||||||
|
display: flex;
|
||||||
|
padding: 6px 12px;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: box-shadow 0.3s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
}
|
||||||
|
.button-icon {
|
||||||
|
height: 18px;
|
||||||
|
width: 18px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
margin-top: 20px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
li {
|
||||||
|
flex: 1 1 calc(50% - 8px);
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
width: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#spacer {
|
||||||
|
height: 88px;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
height: 48px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ticks {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
&::before,
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: -4.5px;
|
||||||
|
border: 5px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
left: 0;
|
||||||
|
border-left-color: var(--border);
|
||||||
|
}
|
||||||
|
&::after {
|
||||||
|
right: 0;
|
||||||
|
border-right-color: var(--border);
|
||||||
|
}
|
||||||
|
}
|
||||||
70
src/App.tsx
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
|
||||||
|
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
||||||
|
import { MainLayout } from './components/layout/MainLayout';
|
||||||
|
import { ProtectedRoute } from './components/ProtectedRoute';
|
||||||
|
|
||||||
|
// Creating a base Material-UI theme to replace Nebular's default
|
||||||
|
const theme = createTheme({
|
||||||
|
palette: {
|
||||||
|
mode: 'dark',
|
||||||
|
primary: {
|
||||||
|
main: '#3b82f6', // Matching dashboard blue
|
||||||
|
},
|
||||||
|
background: {
|
||||||
|
default: '#0b1121', // Dark navy
|
||||||
|
paper: '#0f172a', // Slightly lighter navy
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typography: {
|
||||||
|
fontFamily: '"Open Sans", sans-serif',
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
MuiAppBar: {
|
||||||
|
styleOverrides: {
|
||||||
|
root: {
|
||||||
|
backgroundColor: '#0f172a',
|
||||||
|
color: '#f8fafc',
|
||||||
|
backgroundImage: 'none',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
MuiPaper: {
|
||||||
|
styleOverrides: {
|
||||||
|
root: {
|
||||||
|
backgroundImage: 'none',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
import { Login } from './pages/account/Login';
|
||||||
|
import { Dashboard } from './pages/dashboard/Dashboard';
|
||||||
|
import { GlobalFeed } from './pages/activity-feeds/GlobalFeed';
|
||||||
|
import { AuditSession } from './pages/audit-session/AuditSession';
|
||||||
|
|
||||||
|
export default function App() {
|
||||||
|
return (
|
||||||
|
<ThemeProvider theme={theme}>
|
||||||
|
<BrowserRouter>
|
||||||
|
<Routes>
|
||||||
|
{/* Public Routes */}
|
||||||
|
<Route path="/login" element={<Login />} />
|
||||||
|
|
||||||
|
{/* Protected Routes inside the Main Layout */}
|
||||||
|
<Route element={<ProtectedRoute />}>
|
||||||
|
<Route path="/audit-session" element={<AuditSession />} />
|
||||||
|
<Route path="/" element={<MainLayout />}>
|
||||||
|
<Route index element={<Navigate to="/dashboard" replace />} />
|
||||||
|
<Route path="dashboard" element={<Dashboard />} />
|
||||||
|
<Route path="activity-feeds" element={<GlobalFeed />} />
|
||||||
|
</Route>
|
||||||
|
</Route>
|
||||||
|
|
||||||
|
{/* Catch-all */}
|
||||||
|
<Route path="*" element={<Navigate to="/" replace />} />
|
||||||
|
</Routes>
|
||||||
|
</BrowserRouter>
|
||||||
|
</ThemeProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
19
src/api/accountService.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { axiosClient } from './axiosClient';
|
||||||
|
|
||||||
|
export const accountService = {
|
||||||
|
login: async (username: string, password: string) => {
|
||||||
|
// Replicating the environment.origin behavior if needed, currently hardcoded
|
||||||
|
const body = {
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
origin: "AUDITOR_REMOTE",
|
||||||
|
};
|
||||||
|
const response = await axiosClient.post('/api/dashboard/Master/login', body);
|
||||||
|
return (response as any).responseData?.[0]?.records?.[0]; // matching the Angular extraction logic
|
||||||
|
},
|
||||||
|
|
||||||
|
getOrganizations: async () => {
|
||||||
|
const response = await axiosClient.get('/api/audit/account/organizations');
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
};
|
||||||
35
src/api/activityFeedsService.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { axiosClient } from './axiosClient';
|
||||||
|
|
||||||
|
export const activityFeedsService = {
|
||||||
|
getAssets: async () => {
|
||||||
|
const response = await axiosClient.get('/api/dashboard/Master/asset_types');
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
|
||||||
|
getHistoryDates: async (isRectificationEnabled: boolean) => {
|
||||||
|
// Requires dbName and siteIds, which should be handled by axios interceptors or passed in
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
isRectificationEnabled: String(isRectificationEnabled)
|
||||||
|
});
|
||||||
|
const response = await axiosClient.get(`/api/audit/anomaly/get_history_dates?${params.toString()}`);
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
|
||||||
|
getHistory: async (params: any) => {
|
||||||
|
const queryParams = new URLSearchParams(params);
|
||||||
|
const response = await axiosClient.get(`/api/audit/anomaly/history?${queryParams.toString()}`);
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Mocking update anomaly
|
||||||
|
updateAuditedAnomaly: async (site_id: string, anomaly_id: string, payload: any) => {
|
||||||
|
const response = await axiosClient.put(`/api/audit/anomalies/updateAuditedAnomaly/${site_id}/${anomaly_id}`, payload);
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
|
||||||
|
getOrganizationSites: async (org_id: string) => {
|
||||||
|
const params = new URLSearchParams({ org_id });
|
||||||
|
const response = await axiosClient.get(`/api/dashboard/Master/site?${params.toString()}`);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
};
|
||||||
55
src/api/axiosClient.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import { useAuthStore } from '../store/authStore';
|
||||||
|
|
||||||
|
// You can move this to an environment variable later
|
||||||
|
// Base URL is empty because we use specific proxy prefixes in the service calls
|
||||||
|
const BASE_URL = '';
|
||||||
|
|
||||||
|
export const axiosClient = axios.create({
|
||||||
|
baseURL: BASE_URL,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Request Interceptor: Attach token if available
|
||||||
|
axiosClient.interceptors.request.use(
|
||||||
|
(config) => {
|
||||||
|
const user = useAuthStore.getState().user;
|
||||||
|
if (user?.access_token) {
|
||||||
|
config.headers['x-access-token'] = user.access_token;
|
||||||
|
}
|
||||||
|
if (user?.db_name) {
|
||||||
|
config.params = { ...config.params, dbName: user.db_name };
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
(error) => Promise.reject(error)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Response Interceptor: Global Error Handling (like Angular's HttpService)
|
||||||
|
axiosClient.interceptors.response.use(
|
||||||
|
(response) => response.data,
|
||||||
|
(error) => {
|
||||||
|
if (!error.response) {
|
||||||
|
// Network offline or CORS error (status 0 in Angular)
|
||||||
|
alert('Seems one of the sub-application is offline. Please restart the application again.');
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { status, data } = error.response;
|
||||||
|
|
||||||
|
if (status === 400) {
|
||||||
|
const message = data?.responseStatus?.responseMessage || data?.errorMessage || 'OOPS! Something wrong has happened. Please refresh the browser and try again.';
|
||||||
|
alert(message);
|
||||||
|
} else if (status === 401) {
|
||||||
|
console.error('Login issue');
|
||||||
|
useAuthStore.getState().logout();
|
||||||
|
window.location.href = '/login'; // Redirect to login
|
||||||
|
} else {
|
||||||
|
alert('OOPS! Something wrong has happened. Please refresh the browser and try again.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
BIN
src/assets/hero.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
1
src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||||
|
After Width: | Height: | Size: 4.0 KiB |
1
src/assets/vite.svg
Normal file
|
After Width: | Height: | Size: 8.5 KiB |
24
src/components/ProtectedRoute.tsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { Navigate, Outlet } from 'react-router-dom';
|
||||||
|
import { useAuthStore } from '../store/authStore';
|
||||||
|
|
||||||
|
interface ProtectedRouteProps {
|
||||||
|
requiredRole?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ProtectedRoute = ({ requiredRole }: ProtectedRouteProps) => {
|
||||||
|
const { isAuthenticated, hasRole } = useAuthStore();
|
||||||
|
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
// If user is not authenticated, redirect to login
|
||||||
|
return <Navigate to="/login" replace />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requiredRole && !hasRole(requiredRole)) {
|
||||||
|
// If user doesn't have the required role, redirect them or show unauthorized
|
||||||
|
// For now, redirecting to a default safe page
|
||||||
|
return <Navigate to="/unauthorized" replace />;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If authenticated and authorized, render the child routes
|
||||||
|
return <Outlet />;
|
||||||
|
};
|
||||||
121
src/components/common/TopFilterBar.tsx
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
|
import { Box, Button, FormControl, Select, MenuItem } from '@mui/material';
|
||||||
|
import FilterListIcon from '@mui/icons-material/FilterList';
|
||||||
|
import HistoryIcon from '@mui/icons-material/History';
|
||||||
|
import { useFeedStore } from '../../store/feedStore';
|
||||||
|
import { FeedFilters } from '../../pages/activity-feeds/FeedFilters';
|
||||||
|
|
||||||
|
const DEBOUNCE_MS = 600; // wait 600ms after user stops changing before committing to store
|
||||||
|
|
||||||
|
export const TopFilterBar: React.FC = () => {
|
||||||
|
const {
|
||||||
|
sites,
|
||||||
|
selectedSite, setSelectedSite,
|
||||||
|
auditStatus, setAuditStatus,
|
||||||
|
setIsFiltersModalOpen
|
||||||
|
} = useFeedStore();
|
||||||
|
|
||||||
|
// Local draft values — these do NOT trigger API calls
|
||||||
|
const [localAuditStatus, setLocalAuditStatus] = useState(auditStatus || 'Auto Audits');
|
||||||
|
const [localSiteId, setLocalSiteId] = useState<string>(selectedSite?.site_id || 'All Sites');
|
||||||
|
|
||||||
|
// Sync local state when store changes externally (e.g., on initial load)
|
||||||
|
useEffect(() => {
|
||||||
|
setLocalAuditStatus(auditStatus || 'Auto Audits');
|
||||||
|
}, [auditStatus]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setLocalSiteId(selectedSite?.site_id || 'All Sites');
|
||||||
|
}, [selectedSite?.site_id]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
|
// Debounced commit for auditStatus
|
||||||
|
const auditDebounce = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
|
const handleAuditChange = (value: string) => {
|
||||||
|
setLocalAuditStatus(value);
|
||||||
|
if (auditDebounce.current) clearTimeout(auditDebounce.current);
|
||||||
|
auditDebounce.current = setTimeout(() => {
|
||||||
|
setAuditStatus(value); // triggers API refetch only after user stops
|
||||||
|
}, DEBOUNCE_MS);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Debounced commit for selectedSite
|
||||||
|
const siteDebounce = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
|
const handleSiteChange = (siteId: string) => {
|
||||||
|
setLocalSiteId(siteId);
|
||||||
|
if (siteDebounce.current) clearTimeout(siteDebounce.current);
|
||||||
|
siteDebounce.current = setTimeout(() => {
|
||||||
|
const site = siteId === 'All Sites'
|
||||||
|
? { site_id: 'All Sites', site_name: 'All Sites' }
|
||||||
|
: sites.find(s => s.site_id === siteId);
|
||||||
|
setSelectedSite(site); // triggers API refetch only after user stops
|
||||||
|
}, DEBOUNCE_MS);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Cleanup on unmount
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (auditDebounce.current) clearTimeout(auditDebounce.current);
|
||||||
|
if (siteDebounce.current) clearTimeout(siteDebounce.current);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', gap: 1.5, px: 2, py: 1.5, bgcolor: '#0b1121' }}>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
startIcon={<FilterListIcon />}
|
||||||
|
sx={{ bgcolor: 'rgba(255,255,255,0.1)', color: '#fff', '&:hover': { bgcolor: 'rgba(255,255,255,0.2)' }, borderRadius: 2, textTransform: 'none', fontWeight: 'bold', boxShadow: 'none' }}
|
||||||
|
onClick={() => setIsFiltersModalOpen(true)}
|
||||||
|
>
|
||||||
|
FILTERS
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
startIcon={<HistoryIcon />}
|
||||||
|
sx={{ bgcolor: 'rgba(255,255,255,0.1)', color: '#fff', '&:hover': { bgcolor: 'rgba(255,255,255,0.2)' }, borderRadius: 2, textTransform: 'none', fontWeight: 'bold', boxShadow: 'none' }}
|
||||||
|
>
|
||||||
|
RECTIFICATION HISTORY
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{/* Audit Status — local state, debounced commit */}
|
||||||
|
<FormControl size="small" sx={{ bgcolor: 'rgba(255,255,255,0.1)', borderRadius: 2, minWidth: 140 }}>
|
||||||
|
<Select
|
||||||
|
value={localAuditStatus}
|
||||||
|
onChange={(e) => handleAuditChange(e.target.value as string)}
|
||||||
|
sx={{ '& .MuiSelect-select': { py: 1, px: 2 }, border: 'none', '& fieldset': { border: 'none' }, fontWeight: 'bold', color: '#fff' }}
|
||||||
|
>
|
||||||
|
<MenuItem value="Manual">Manual</MenuItem>
|
||||||
|
<MenuItem value="Auto Audits">Auto Audits</MenuItem>
|
||||||
|
<MenuItem value="False Audits">False Audits</MenuItem>
|
||||||
|
<MenuItem value="All">All</MenuItem>
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
{/* Site — local state, debounced commit */}
|
||||||
|
<FormControl size="small" sx={{ bgcolor: 'rgba(255,255,255,0.1)', borderRadius: 2, minWidth: 140 }}>
|
||||||
|
<Select
|
||||||
|
value={localSiteId}
|
||||||
|
onChange={(e) => handleSiteChange(e.target.value as string)}
|
||||||
|
sx={{ '& .MuiSelect-select': { py: 1, px: 2 }, border: 'none', '& fieldset': { border: 'none' }, fontWeight: 'bold', color: '#fff' }}
|
||||||
|
>
|
||||||
|
<MenuItem value="All Sites">All Sites</MenuItem>
|
||||||
|
{sites.map(s => (
|
||||||
|
<MenuItem key={s.site_id || Math.random()} value={s.site_id}>
|
||||||
|
{s.site_name || s.name || s.siteName || JSON.stringify(s)}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
sx={{ bgcolor: 'rgba(255,255,255,0.1)', color: '#fff', '&:hover': { bgcolor: 'rgba(255,255,255,0.2)' }, borderRadius: 2, textTransform: 'none', fontWeight: 'bold', boxShadow: 'none' }}
|
||||||
|
>
|
||||||
|
ENABLE RECTIFICATION
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<FeedFilters />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
128
src/components/layout/Header.tsx
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { AppBar, Toolbar, Typography, Box, IconButton, Menu, MenuItem, Button, Select, FormControl } from '@mui/material';
|
||||||
|
import MenuIcon from '@mui/icons-material/Menu';
|
||||||
|
import AccountCircle from '@mui/icons-material/AccountCircle';
|
||||||
|
import FilterListIcon from '@mui/icons-material/FilterList';
|
||||||
|
import HistoryIcon from '@mui/icons-material/History';
|
||||||
|
import { useAuthStore } from '../../store/authStore';
|
||||||
|
import { useFeedStore } from '../../store/feedStore';
|
||||||
|
import { useNavigate, useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
|
interface HeaderProps {
|
||||||
|
toggleSidebar?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Header: React.FC<HeaderProps> = ({ toggleSidebar }) => {
|
||||||
|
const { user, logout } = useAuthStore();
|
||||||
|
const { sites, selectedSite, setSelectedSite, auditStatus, setAuditStatus, setIsFiltersModalOpen } = useFeedStore();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
||||||
|
|
||||||
|
const orgName = user?.org_id || user?.db_name || 'TakeLeep'; // Adjust based on your User model
|
||||||
|
const showNav = !location.pathname.includes('dashboard');
|
||||||
|
const isActivityFeeds = location.pathname.includes('activity-feeds');
|
||||||
|
|
||||||
|
const handleMenu = (event: React.MouseEvent<HTMLElement>) => {
|
||||||
|
setAnchorEl(event.currentTarget);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
setAnchorEl(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleLogout = () => {
|
||||||
|
handleClose();
|
||||||
|
logout();
|
||||||
|
navigate('/login', { replace: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AppBar position="fixed" sx={{ zIndex: (theme) => theme.zIndex.drawer + 1, boxShadow: 1 }}>
|
||||||
|
<Toolbar sx={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||||
|
|
||||||
|
<Box sx={{ display: 'flex', alignItems: 'center' }}>
|
||||||
|
{showNav && toggleSidebar && (
|
||||||
|
<IconButton edge="start" color="inherit" aria-label="menu" onClick={toggleSidebar} sx={{ mr: 2 }}>
|
||||||
|
<MenuIcon />
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
<Box sx={{ display: 'flex', alignItems: 'center', ml: showNav && toggleSidebar ? 0 : 2 }}>
|
||||||
|
<img
|
||||||
|
src="/assets/images/logo/side-bar-logo.png"
|
||||||
|
alt="Dashboard Logo"
|
||||||
|
style={{ height: '32px', objectFit: 'contain' }}
|
||||||
|
onError={(e) => { e.currentTarget.style.display = 'none'; }}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Box sx={{ position: 'absolute', left: '50%', transform: 'translateX(-50%)', display: 'flex', gap: 1 }}>
|
||||||
|
<Button
|
||||||
|
onClick={() => navigate('/dashboard')}
|
||||||
|
sx={{
|
||||||
|
color: location.pathname.includes('dashboard') ? 'primary.main' : 'text.secondary',
|
||||||
|
fontWeight: 'bold',
|
||||||
|
borderBottom: location.pathname.includes('dashboard') ? '2px solid #3b82f6' : '2px solid transparent',
|
||||||
|
borderRadius: 0,
|
||||||
|
px: 2,
|
||||||
|
py: 1
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Dashboard
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => navigate('/activity-feeds')}
|
||||||
|
sx={{
|
||||||
|
color: location.pathname.includes('activity-feeds') ? 'primary.main' : 'text.secondary',
|
||||||
|
fontWeight: 'bold',
|
||||||
|
borderBottom: location.pathname.includes('activity-feeds') ? '2px solid #3b82f6' : '2px solid transparent',
|
||||||
|
borderRadius: 0,
|
||||||
|
px: 2,
|
||||||
|
py: 1
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Activity Feeds
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5 }}>
|
||||||
|
|
||||||
|
|
||||||
|
{user && (
|
||||||
|
<div>
|
||||||
|
<Button
|
||||||
|
size="large"
|
||||||
|
aria-label="account of current user"
|
||||||
|
aria-controls="menu-appbar"
|
||||||
|
aria-haspopup="true"
|
||||||
|
onClick={handleMenu}
|
||||||
|
color="inherit"
|
||||||
|
startIcon={<AccountCircle />}
|
||||||
|
>
|
||||||
|
{user.username}
|
||||||
|
</Button>
|
||||||
|
<Menu
|
||||||
|
id="menu-appbar"
|
||||||
|
anchorEl={anchorEl}
|
||||||
|
anchorOrigin={{
|
||||||
|
vertical: 'bottom',
|
||||||
|
horizontal: 'right',
|
||||||
|
}}
|
||||||
|
keepMounted
|
||||||
|
transformOrigin={{
|
||||||
|
vertical: 'top',
|
||||||
|
horizontal: 'right',
|
||||||
|
}}
|
||||||
|
open={Boolean(anchorEl)}
|
||||||
|
onClose={handleClose}
|
||||||
|
>
|
||||||
|
<MenuItem onClick={handleLogout}>Log out</MenuItem>
|
||||||
|
</Menu>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</Toolbar>
|
||||||
|
</AppBar>
|
||||||
|
);
|
||||||
|
};
|
||||||
24
src/components/layout/MainLayout.tsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Box, Toolbar, CssBaseline } from '@mui/material';
|
||||||
|
import { Outlet, useLocation } from 'react-router-dom';
|
||||||
|
import { Header } from './Header';
|
||||||
|
|
||||||
|
export const MainLayout: React.FC = () => {
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ display: 'flex', minHeight: '100vh', bgcolor: 'background.default' }}>
|
||||||
|
<CssBaseline />
|
||||||
|
|
||||||
|
<Header />
|
||||||
|
|
||||||
|
<Box component="main" sx={{ flexGrow: 1, p: location.pathname.includes('activity-feeds') ? 0 : 0, height: '100vh', display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
||||||
|
<Toolbar /> {/* Spacer for Header */}
|
||||||
|
|
||||||
|
{/* Child routes get injected here */}
|
||||||
|
<Outlet />
|
||||||
|
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
111
src/index.css
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
:root {
|
||||||
|
--text: #6b6375;
|
||||||
|
--text-h: #08060d;
|
||||||
|
--bg: #fff;
|
||||||
|
--border: #e5e4e7;
|
||||||
|
--code-bg: #f4f3ec;
|
||||||
|
--accent: #aa3bff;
|
||||||
|
--accent-bg: rgba(170, 59, 255, 0.1);
|
||||||
|
--accent-border: rgba(170, 59, 255, 0.5);
|
||||||
|
--social-bg: rgba(244, 243, 236, 0.5);
|
||||||
|
--shadow:
|
||||||
|
rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px;
|
||||||
|
|
||||||
|
--sans: system-ui, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
--heading: system-ui, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
--mono: ui-monospace, Consolas, monospace;
|
||||||
|
|
||||||
|
font: 18px/145% var(--sans);
|
||||||
|
letter-spacing: 0.18px;
|
||||||
|
color-scheme: light dark;
|
||||||
|
color: var(--text);
|
||||||
|
background: var(--bg);
|
||||||
|
font-synthesis: none;
|
||||||
|
text-rendering: optimizeLegibility;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--text: #9ca3af;
|
||||||
|
--text-h: #f3f4f6;
|
||||||
|
--bg: #16171d;
|
||||||
|
--border: #2e303a;
|
||||||
|
--code-bg: #1f2028;
|
||||||
|
--accent: #c084fc;
|
||||||
|
--accent-bg: rgba(192, 132, 252, 0.15);
|
||||||
|
--accent-border: rgba(192, 132, 252, 0.5);
|
||||||
|
--social-bg: rgba(47, 48, 58, 0.5);
|
||||||
|
--shadow:
|
||||||
|
rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#social .button-icon {
|
||||||
|
filter: invert(1) brightness(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#root {
|
||||||
|
width: 1126px;
|
||||||
|
max-width: 100%;
|
||||||
|
margin: 0 auto;
|
||||||
|
text-align: center;
|
||||||
|
border-inline: 1px solid var(--border);
|
||||||
|
min-height: 100svh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2 {
|
||||||
|
font-family: var(--heading);
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-h);
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 56px;
|
||||||
|
letter-spacing: -1.68px;
|
||||||
|
margin: 32px 0;
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
font-size: 36px;
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
font-size: 24px;
|
||||||
|
line-height: 118%;
|
||||||
|
letter-spacing: -0.24px;
|
||||||
|
margin: 0 0 8px;
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
code,
|
||||||
|
.counter {
|
||||||
|
font-family: var(--mono);
|
||||||
|
display: inline-flex;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: var(--text-h);
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 135%;
|
||||||
|
padding: 4px 8px;
|
||||||
|
background: var(--code-bg);
|
||||||
|
}
|
||||||
9
src/main.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { StrictMode } from 'react'
|
||||||
|
import { createRoot } from 'react-dom/client'
|
||||||
|
import App from './App.tsx'
|
||||||
|
|
||||||
|
createRoot(document.getElementById('root')!).render(
|
||||||
|
<StrictMode>
|
||||||
|
<App />
|
||||||
|
</StrictMode>,
|
||||||
|
)
|
||||||
59
src/pages/account/DbSelectionDialog.tsx
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { Dialog, DialogTitle, DialogContent, List, ListItem, ListItemButton, ListItemText, CircularProgress, Box } from '@mui/material';
|
||||||
|
import { accountService } from '../../api/accountService';
|
||||||
|
|
||||||
|
interface Organization {
|
||||||
|
org_name: string;
|
||||||
|
org_id: string;
|
||||||
|
db_name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DbSelectionDialogProps {
|
||||||
|
open: boolean;
|
||||||
|
onClose: (selectedOrg?: Organization) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DbSelectionDialog: React.FC<DbSelectionDialogProps> = ({ open, onClose }) => {
|
||||||
|
const [organizations, setOrganizations] = useState<Organization[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
setLoading(true);
|
||||||
|
accountService.getOrganizations()
|
||||||
|
.then((res: any) => {
|
||||||
|
const sorted = res.sort((a: Organization, b: Organization) =>
|
||||||
|
a.org_name.toLowerCase() > b.org_name.toLowerCase() ? 1 : -1
|
||||||
|
);
|
||||||
|
setOrganizations(sorted);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
})
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
}
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onClose={() => onClose()} maxWidth="xs" fullWidth>
|
||||||
|
<DialogTitle>Select the organization</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
{loading ? (
|
||||||
|
<Box sx={{ display: 'flex', justifyContent: 'center', p: 2 }}>
|
||||||
|
<CircularProgress />
|
||||||
|
</Box>
|
||||||
|
) : (
|
||||||
|
<List>
|
||||||
|
{organizations.map((org) => (
|
||||||
|
<ListItem disablePadding key={org.org_id || org.org_name}>
|
||||||
|
<ListItemButton onClick={() => onClose(org)}>
|
||||||
|
<ListItemText primary={org.org_name} />
|
||||||
|
</ListItemButton>
|
||||||
|
</ListItem>
|
||||||
|
))}
|
||||||
|
</List>
|
||||||
|
)}
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
163
src/pages/account/Login.tsx
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { Box, Button, TextField, Typography, Container, Alert } from '@mui/material';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { useAuthStore } from '../../store/authStore';
|
||||||
|
import { accountService } from '../../api/accountService';
|
||||||
|
import { DbSelectionDialog } from './DbSelectionDialog';
|
||||||
|
|
||||||
|
export const Login: React.FC = () => {
|
||||||
|
const [username, setUsername] = useState('');
|
||||||
|
const [password, setPassword] = useState('');
|
||||||
|
const [isInvalid, setIsInvalid] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [dialogOpen, setDialogOpen] = useState(false);
|
||||||
|
const [tempUserData, setTempUserData] = useState<any>(null);
|
||||||
|
|
||||||
|
const { login, isAuthenticated } = useAuthStore();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
// If already logged in, redirect
|
||||||
|
useEffect(() => {
|
||||||
|
if (isAuthenticated) {
|
||||||
|
navigate('/activity-feeds', { replace: true });
|
||||||
|
}
|
||||||
|
}, [isAuthenticated, navigate]);
|
||||||
|
|
||||||
|
const handleLogin = async () => {
|
||||||
|
setIsInvalid(false);
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const userData = await accountService.login(username, password);
|
||||||
|
|
||||||
|
if (!userData) {
|
||||||
|
setIsInvalid(true);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const roles = userData.user_roles ? userData.user_roles.toLowerCase().split(',') : [];
|
||||||
|
|
||||||
|
if (roles.includes('sr_auditor')) {
|
||||||
|
// Open DB Selection Dialog
|
||||||
|
setTempUserData(userData);
|
||||||
|
setDialogOpen(true);
|
||||||
|
} else if (roles.includes('auditor')) {
|
||||||
|
// Direct login
|
||||||
|
login(userData);
|
||||||
|
navigate('/activity-feeds', { replace: true });
|
||||||
|
} else if (roles.includes('video_uploader')) {
|
||||||
|
// Direct login for dashboard
|
||||||
|
login(userData);
|
||||||
|
navigate('/activity-feeds', { replace: true });
|
||||||
|
} else {
|
||||||
|
alert("Your account is not configured to use this website. Please contact your admin for more info.");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setIsInvalid(true);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDbSelection = (selectedOrg?: any) => {
|
||||||
|
setDialogOpen(false);
|
||||||
|
if (selectedOrg && tempUserData) {
|
||||||
|
// Merge selected org details into user object
|
||||||
|
const finalUserData = {
|
||||||
|
...tempUserData,
|
||||||
|
org_id: selectedOrg.org_id,
|
||||||
|
db_name: selectedOrg.db_name,
|
||||||
|
selected_org_name: selectedOrg.org_name
|
||||||
|
};
|
||||||
|
login(finalUserData);
|
||||||
|
navigate('/activity-feeds', { replace: true });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container component="main" maxWidth="xs">
|
||||||
|
<Box sx={{ marginTop: 8, display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
|
||||||
|
|
||||||
|
{/* Placeholder for Logo */}
|
||||||
|
<Box sx={{ mb: 6, display: 'flex', justifyContent: 'center' }}>
|
||||||
|
<img src="/images/SeekRightLogo.png" alt="Logo" width="250" onError={(e) => { e.currentTarget.style.display = 'none'; }} />
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Box component="form" sx={{ mt: 1, width: '100%' }}>
|
||||||
|
<TextField
|
||||||
|
margin="normal"
|
||||||
|
required
|
||||||
|
fullWidth
|
||||||
|
id="username"
|
||||||
|
placeholder="Admin"
|
||||||
|
name="username"
|
||||||
|
autoFocus
|
||||||
|
value={username}
|
||||||
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
|
onKeyDown={(e) => e.key === 'Enter' && handleLogin()}
|
||||||
|
InputProps={{
|
||||||
|
sx: { borderRadius: '50px', '& fieldset': { borderColor: '#738ab8' } }
|
||||||
|
}}
|
||||||
|
sx={{
|
||||||
|
mb: 1,
|
||||||
|
'& .MuiInputBase-input': { padding: '10px 14px', fontSize: '0.9rem', color: '#333' }
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
margin="normal"
|
||||||
|
required
|
||||||
|
fullWidth
|
||||||
|
name="password"
|
||||||
|
placeholder="Password"
|
||||||
|
type="password"
|
||||||
|
id="password"
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
onKeyDown={(e) => e.key === 'Enter' && handleLogin()}
|
||||||
|
InputProps={{
|
||||||
|
sx: { borderRadius: '50px', '& fieldset': { borderColor: '#738ab8' } }
|
||||||
|
}}
|
||||||
|
sx={{
|
||||||
|
mt: 1,
|
||||||
|
mb: 3,
|
||||||
|
'& .MuiInputBase-input': { padding: '10px 14px', fontSize: '0.9rem', color: '#333' }
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Box sx={{ display: 'flex', justifyContent: 'center', mt: 3, mb: 4 }}>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
disabled={!username || !password || loading}
|
||||||
|
onClick={handleLogin}
|
||||||
|
sx={{
|
||||||
|
borderRadius: '50px',
|
||||||
|
backgroundColor: '#738ab8',
|
||||||
|
width: '140px',
|
||||||
|
pt: 1, pb: 1,
|
||||||
|
boxShadow: 'none',
|
||||||
|
'&:hover': {
|
||||||
|
backgroundColor: '#5c729c',
|
||||||
|
boxShadow: 'none',
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{loading ? '...' : 'LOGIN'}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{isInvalid && (
|
||||||
|
<Alert severity="error" sx={{ mt: 2 }}>
|
||||||
|
Invalid Credentials
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Database Selection Dialog for SR_AUDITOR */}
|
||||||
|
<DbSelectionDialog open={dialogOpen} onClose={handleDbSelection} />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
};
|
||||||
60
src/pages/activity-feeds/AnomalyCard.tsx
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Card, CardMedia, CardContent, Typography, Box, Slider, Button } from '@mui/material';
|
||||||
|
|
||||||
|
interface AnomalyCardProps {
|
||||||
|
anomaly: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AnomalyCard: React.FC<AnomalyCardProps> = ({ anomaly }) => {
|
||||||
|
// Safe extraction of properties based on Angular's data structure
|
||||||
|
const assetName = anomaly?.Asset?.replace(/_/gi, ' ') || 'Unknown Asset';
|
||||||
|
const createdOn = anomaly?.Created_on || 'Unknown Date';
|
||||||
|
const confidence = anomaly?.Confidence || 0;
|
||||||
|
const imageSrc = anomaly?.Frame_Master || '/assets/images/placeholder.jpg';
|
||||||
|
const isAudited = anomaly?.IsAudited;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card sx={{ display: 'flex', mb: 2, height: 180 }}>
|
||||||
|
{/* Image Section */}
|
||||||
|
<CardMedia
|
||||||
|
component="img"
|
||||||
|
sx={{ width: 250, objectFit: 'cover' }}
|
||||||
|
image={imageSrc}
|
||||||
|
alt={assetName}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Details Section */}
|
||||||
|
<CardContent sx={{ flex: 1, display: 'flex', flexDirection: 'column', justifyContent: 'space-between' }}>
|
||||||
|
<Box>
|
||||||
|
<Typography variant="h6" component="div">
|
||||||
|
{assetName}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="body2" color="text.secondary">
|
||||||
|
Date: {createdOn} | Chainage: {anomaly?.Chainage || 'N/A'}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="body2" color="text.secondary">
|
||||||
|
Confidence: {confidence}% | Status: {isAudited ? 'Audited' : 'Unaudited'}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Sliders and Buttons (Placeholder logic for audit status) */}
|
||||||
|
<Box sx={{ display: 'flex', alignItems: 'center', mt: 2, gap: 2 }}>
|
||||||
|
<Typography variant="body2">True</Typography>
|
||||||
|
<Slider
|
||||||
|
value={anomaly?.anomaly_status_slider || 50}
|
||||||
|
step={100}
|
||||||
|
marks
|
||||||
|
min={0}
|
||||||
|
max={100}
|
||||||
|
sx={{ width: 100 }}
|
||||||
|
/>
|
||||||
|
<Typography variant="body2">False</Typography>
|
||||||
|
|
||||||
|
<Button variant="outlined" size="small" sx={{ ml: 'auto' }}>
|
||||||
|
{isAudited ? 'Edit' : 'Save'}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
37
src/pages/activity-feeds/AnomalyList.tsx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Box, Typography } from '@mui/material';
|
||||||
|
import { useFeedStore } from '../../store/feedStore';
|
||||||
|
import { AnomalyCard } from './AnomalyCard';
|
||||||
|
|
||||||
|
export const AnomalyList: React.FC = () => {
|
||||||
|
const { tabs, selectedTabIndex } = useFeedStore();
|
||||||
|
|
||||||
|
if (tabs.length === 0 || selectedTabIndex < 0) {
|
||||||
|
return <Typography>Loading feeds...</Typography>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeTab = tabs[selectedTabIndex];
|
||||||
|
const anomalies = activeTab.anomalies || [];
|
||||||
|
|
||||||
|
if (anomalies.length === 0) {
|
||||||
|
return (
|
||||||
|
<Box sx={{ p: 4, textAlign: 'center' }}>
|
||||||
|
<Typography variant="body1" color="textSecondary">
|
||||||
|
No anomalies found for the selected criteria.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||||
|
<Typography variant="subtitle2" color="textSecondary">
|
||||||
|
Showing {anomalies.length} / {activeTab.totalAnomalyCount} anomalies
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
{anomalies.map((anomaly: any, index: number) => (
|
||||||
|
<AnomalyCard key={anomaly._id || index} anomaly={anomaly} />
|
||||||
|
))}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
124
src/pages/activity-feeds/AnomalyTable.tsx
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Box, Typography, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper, Slider, Checkbox } from '@mui/material';
|
||||||
|
import { useFeedStore } from '../../store/feedStore';
|
||||||
|
|
||||||
|
export const AnomalyTable: React.FC = () => {
|
||||||
|
const { tabs, selectedTabIndex, updateTab } = useFeedStore();
|
||||||
|
|
||||||
|
if (tabs.length === 0 || selectedTabIndex < 0) {
|
||||||
|
return <Typography sx={{ p: 2 }}>Loading feeds...</Typography>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeTab = tabs[selectedTabIndex];
|
||||||
|
const anomalies = activeTab.anomalies || [];
|
||||||
|
|
||||||
|
if (anomalies.length === 0) {
|
||||||
|
return (
|
||||||
|
<Box sx={{ p: 4, textAlign: 'center' }}>
|
||||||
|
<Typography variant="body1" color="textSecondary">
|
||||||
|
No anomalies found for the selected criteria.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRowClick = (index: number) => {
|
||||||
|
updateTab(selectedTabIndex, { selectedAnomalyIndex: index });
|
||||||
|
};
|
||||||
|
|
||||||
|
const getRowColor = (index: number, _asset: string) => {
|
||||||
|
// Dark mode colors for table rows
|
||||||
|
const colors = ['rgba(255, 255, 255, 0.03)', 'rgba(255, 255, 255, 0.0)'];
|
||||||
|
return colors[index % colors.length];
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TableContainer component={Paper} sx={{ borderRadius: 0, boxShadow: 'none', height: 'calc(100vh - 180px)', bgcolor: 'transparent' }}>
|
||||||
|
<Table stickyHeader size="small" sx={{ minWidth: 1200 }}>
|
||||||
|
<TableHead>
|
||||||
|
<TableRow>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>#ID</TableCell>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>PLAZA</TableCell>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>ROAD</TableCell>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>DATE</TableCell>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>CHAINAGE</TableCell>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>LAT/LONG</TableCell>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>ANOMALY</TableCell>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>SIDE</TableCell>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>ANOMALY True/False</TableCell>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>FEATURES</TableCell>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>COMMENTS</TableCell>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>CHECKED</TableCell>
|
||||||
|
<TableCell sx={{ fontWeight: 'bold', bgcolor: 'background.paper', color: 'text.primary', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>AUTO AUDIT</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableHead>
|
||||||
|
<TableBody>
|
||||||
|
{anomalies.map((anomaly: any, index: number) => {
|
||||||
|
const isSelected = activeTab.selectedAnomalyIndex === index;
|
||||||
|
const assetName = anomaly?.Asset?.replace(/_/gi, ' ') || 'Unknown Asset';
|
||||||
|
const rowColor = getRowColor(index, assetName);
|
||||||
|
|
||||||
|
// Parse Position
|
||||||
|
let latStr = 'N/A';
|
||||||
|
let longStr = 'E/A';
|
||||||
|
if (anomaly?.Pos) {
|
||||||
|
const match = String(anomaly.Pos).match(/([NS][0-9.]+)([EW][0-9.]+)/i);
|
||||||
|
if (match) {
|
||||||
|
latStr = match[1];
|
||||||
|
longStr = match[2];
|
||||||
|
} else {
|
||||||
|
latStr = anomaly.Pos; // Fallback
|
||||||
|
longStr = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TableRow
|
||||||
|
key={anomaly._id || index}
|
||||||
|
onClick={() => handleRowClick(index)}
|
||||||
|
sx={{
|
||||||
|
bgcolor: isSelected ? 'rgba(59, 130, 246, 0.2)' : rowColor,
|
||||||
|
cursor: 'pointer',
|
||||||
|
'&:hover': { bgcolor: 'rgba(255,255,255,0.08)' },
|
||||||
|
borderLeft: isSelected ? '4px solid #3b82f6' : '4px solid transparent',
|
||||||
|
mb: 1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>#{anomaly.id || anomaly._id?.substring(0, 7) || 'N/A'}</TableCell>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.Plaza || 'N/A'}</TableCell>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.road || anomaly.Road || 'N/A'}</TableCell>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.Created_on ? new Date(anomaly.Created_on).toLocaleDateString() : 'N/A'}</TableCell>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.Chainage || 'N/A'}</TableCell>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)', fontSize: '0.75rem' }}>
|
||||||
|
{latStr}<br/>
|
||||||
|
{longStr}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{assetName}</TableCell>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.Side || 'N/A'}</TableCell>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)', width: 120 }}>
|
||||||
|
<Slider
|
||||||
|
size="small"
|
||||||
|
value={anomaly.Audit_status || anomaly.anomaly_status_slider || 50}
|
||||||
|
step={100}
|
||||||
|
marks
|
||||||
|
min={0}
|
||||||
|
max={100}
|
||||||
|
sx={{ color: '#ff4d4f' }}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.Features || 'N/A'}</TableCell>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>{anomaly.Comments || '-'}</TableCell>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>
|
||||||
|
<Checkbox size="small" checked={!!anomaly.IsAudited} />
|
||||||
|
</TableCell>
|
||||||
|
<TableCell sx={{ borderBottom: '1px solid rgba(255,255,255,0.05)' }}>
|
||||||
|
<Checkbox size="small" checked={!!anomaly.auto_audit} />
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</TableContainer>
|
||||||
|
);
|
||||||
|
};
|
||||||
324
src/pages/activity-feeds/FeedFilters.tsx
Normal file
@@ -0,0 +1,324 @@
|
|||||||
|
import React, { useState, useMemo, useEffect, useCallback, memo } from 'react';
|
||||||
|
import {
|
||||||
|
Box, TextField, Checkbox, FormControlLabel, Button, Typography, Dialog,
|
||||||
|
DialogContent, DialogActions, CircularProgress, Divider, InputAdornment, Chip
|
||||||
|
} from '@mui/material';
|
||||||
|
import SearchIcon from '@mui/icons-material/Search';
|
||||||
|
import { useFeedStore } from '../../store/feedStore';
|
||||||
|
import { activityFeedsService } from '../../api/activityFeedsService';
|
||||||
|
|
||||||
|
// ── Memoized asset row — only re-renders when ITS OWN checked state changes ──
|
||||||
|
const AssetRow = memo(({
|
||||||
|
assetId, assetName, checked, onToggle
|
||||||
|
}: {
|
||||||
|
assetId: number;
|
||||||
|
assetName: string;
|
||||||
|
checked: boolean;
|
||||||
|
onToggle: (id: number) => void;
|
||||||
|
}) => (
|
||||||
|
<FormControlLabel
|
||||||
|
control={
|
||||||
|
<Checkbox
|
||||||
|
size="small"
|
||||||
|
checked={checked}
|
||||||
|
onChange={() => onToggle(assetId)}
|
||||||
|
sx={{ color: '#475569', '&.Mui-checked': { color: '#3b82f6' }, py: 0.3 }}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
label={
|
||||||
|
<Typography variant="caption" sx={{ color: '#cbd5e1', fontSize: '0.72rem' }}>
|
||||||
|
{assetName.replace(/_/g, ' ')}
|
||||||
|
</Typography>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
|
||||||
|
// ── Memoized group header ──────────────────────────────────────────────────────
|
||||||
|
const GroupHeader = memo(({
|
||||||
|
typeName, assetCount, allGroupSelected, someGroupSelected, onToggle
|
||||||
|
}: {
|
||||||
|
typeName: string;
|
||||||
|
assetCount: number;
|
||||||
|
allGroupSelected: boolean;
|
||||||
|
someGroupSelected: boolean;
|
||||||
|
onToggle: () => void;
|
||||||
|
}) => (
|
||||||
|
<FormControlLabel
|
||||||
|
control={
|
||||||
|
<Checkbox
|
||||||
|
checked={allGroupSelected}
|
||||||
|
indeterminate={someGroupSelected}
|
||||||
|
onChange={onToggle}
|
||||||
|
size="small"
|
||||||
|
sx={{ color: '#64748b', '&.Mui-checked': { color: '#60a5fa' }, '&.MuiCheckbox-indeterminate': { color: '#60a5fa' } }}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
label={
|
||||||
|
<Typography variant="body2" sx={{ fontWeight: 'bold', color: '#60a5fa', textTransform: 'uppercase', fontSize: '0.7rem', letterSpacing: 1 }}>
|
||||||
|
{typeName?.replace(/_/g, ' ')} ({assetCount})
|
||||||
|
</Typography>
|
||||||
|
}
|
||||||
|
sx={{ mb: 0.5 }}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
|
||||||
|
export const FeedFilters: React.FC = () => {
|
||||||
|
const {
|
||||||
|
assetTypes, tabs, selectedTabIndex, updateTab,
|
||||||
|
isFiltersModalOpen, setIsFiltersModalOpen,
|
||||||
|
selectedAssetIds, setSelectedAssetIds,
|
||||||
|
filterFromDate, filterTillDate,
|
||||||
|
filterMinChainage, filterMaxChainage,
|
||||||
|
setFilterMinChainage, setFilterMaxChainage,
|
||||||
|
} = useFeedStore();
|
||||||
|
|
||||||
|
// ── Use a Set (stored in state) for O(1) has() lookups ────────────────────
|
||||||
|
// We store a Set but wrap it in an object so React detects the change
|
||||||
|
const [draftSet, setDraftSet] = useState<Set<number>>(() => new Set(selectedAssetIds));
|
||||||
|
const [draftFromDate, setDraftFromDate] = useState('');
|
||||||
|
const [draftTillDate, setDraftTillDate] = useState('');
|
||||||
|
const [draftMinChainage, setDraftMinChainage] = useState('');
|
||||||
|
const [draftMaxChainage, setDraftMaxChainage] = useState('');
|
||||||
|
const [assetSearch, setAssetSearch] = useState('');
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
// When dialog opens, seed ALL drafts from current store values — not empty strings!
|
||||||
|
const [prevOpen, setPrevOpen] = useState(false);
|
||||||
|
if (isFiltersModalOpen && !prevOpen) {
|
||||||
|
setPrevOpen(true);
|
||||||
|
setDraftSet(new Set(selectedAssetIds));
|
||||||
|
setDraftFromDate(filterFromDate); // ← seeded from store
|
||||||
|
setDraftTillDate(filterTillDate); // ← seeded from store
|
||||||
|
setDraftMinChainage(filterMinChainage); // ← seeded from store
|
||||||
|
setDraftMaxChainage(filterMaxChainage); // ← seeded from store
|
||||||
|
setAssetSearch('');
|
||||||
|
} else if (!isFiltersModalOpen && prevOpen) {
|
||||||
|
setPrevOpen(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const allAssetIds = useMemo(
|
||||||
|
() => assetTypes.flatMap((t: any) => t.assets.map((a: any) => a.asset_id as number)),
|
||||||
|
[assetTypes]
|
||||||
|
);
|
||||||
|
|
||||||
|
const filteredAssetTypes = useMemo(() => {
|
||||||
|
if (!assetSearch.trim()) return assetTypes;
|
||||||
|
const q = assetSearch.toLowerCase();
|
||||||
|
return assetTypes
|
||||||
|
.map((type: any) => ({
|
||||||
|
...type,
|
||||||
|
assets: type.assets.filter((a: any) => a.asset_name.toLowerCase().includes(q))
|
||||||
|
}))
|
||||||
|
.filter((type: any) => type.assets.length > 0);
|
||||||
|
}, [assetTypes, assetSearch]);
|
||||||
|
|
||||||
|
const allSelected = allAssetIds.length > 0 && allAssetIds.every(id => draftSet.has(id));
|
||||||
|
const someSelected = draftSet.size > 0 && !allSelected;
|
||||||
|
|
||||||
|
// ── Stable callbacks (useCallback so memoized children don't re-render) ───
|
||||||
|
const handleToggleAsset = useCallback((assetId: number) => {
|
||||||
|
setDraftSet(prev => {
|
||||||
|
const next = new Set(prev);
|
||||||
|
if (next.has(assetId)) next.delete(assetId); else next.add(assetId);
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleToggleAll = useCallback(() => {
|
||||||
|
setDraftSet(prev =>
|
||||||
|
prev.size === allAssetIds.length ? new Set() : new Set(allAssetIds)
|
||||||
|
);
|
||||||
|
}, [allAssetIds]);
|
||||||
|
|
||||||
|
const makeGroupToggle = useCallback((groupIds: number[]) => () => {
|
||||||
|
setDraftSet(prev => {
|
||||||
|
const allIn = groupIds.every(id => prev.has(id));
|
||||||
|
const next = new Set(prev);
|
||||||
|
if (allIn) groupIds.forEach(id => next.delete(id));
|
||||||
|
else groupIds.forEach(id => next.add(id));
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleClearAll = useCallback(() => {
|
||||||
|
setDraftSet(new Set());
|
||||||
|
setDraftFromDate('');
|
||||||
|
setDraftTillDate('');
|
||||||
|
setDraftMinChainage('');
|
||||||
|
setDraftMaxChainage('');
|
||||||
|
setAssetSearch('');
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// ── Apply — only now do we write to the store ────────────────────────────
|
||||||
|
const handleApplyFilter = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const { selectedSite, auditStatus, setFilterFromDate, setFilterTillDate } = useFeedStore.getState();
|
||||||
|
const draftAssetArr = Array.from(draftSet);
|
||||||
|
|
||||||
|
// Commit ALL filter state to the global store
|
||||||
|
setFilterFromDate(draftFromDate);
|
||||||
|
setFilterTillDate(draftTillDate);
|
||||||
|
setFilterMinChainage(draftMinChainage); // persist chainage globally
|
||||||
|
setFilterMaxChainage(draftMaxChainage); // persist chainage globally
|
||||||
|
setSelectedAssetIds(draftAssetArr);
|
||||||
|
|
||||||
|
if (selectedTabIndex >= 0) {
|
||||||
|
const activeTab = tabs[selectedTabIndex];
|
||||||
|
const siteIdParam = (!selectedSite || selectedSite?.site_id === 'All Sites')
|
||||||
|
? '' : String(selectedSite.site_id || '');
|
||||||
|
|
||||||
|
const historyRes: any = await activityFeedsService.getHistory({
|
||||||
|
date: activeTab.date,
|
||||||
|
fromDate: draftFromDate,
|
||||||
|
tillDate: draftTillDate,
|
||||||
|
pageNo: 0,
|
||||||
|
pageSize: 20,
|
||||||
|
siteIds: siteIdParam,
|
||||||
|
assetsIds: draftAssetArr.join(','),
|
||||||
|
isTrueFalse: auditStatus === 'False Audits' ? 'true' : 'both',
|
||||||
|
isRectificationEnabled: false,
|
||||||
|
auto_audit: false,
|
||||||
|
fromChainage: draftMinChainage,
|
||||||
|
toChainage: draftMaxChainage,
|
||||||
|
});
|
||||||
|
if (historyRes?.anomalies) {
|
||||||
|
updateTab(selectedTabIndex, {
|
||||||
|
anomalies: historyRes.anomalies,
|
||||||
|
anomaliesCopy: historyRes.anomalies,
|
||||||
|
totalAnomalyCount: historyRes.count || historyRes.anomalies.length,
|
||||||
|
filters: { fromDate: draftFromDate, tillDate: draftTillDate, fromChainage: draftMinChainage, toChainage: draftMaxChainage }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setIsFiltersModalOpen(false);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Filter apply failed', err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
open={isFiltersModalOpen}
|
||||||
|
onClose={() => setIsFiltersModalOpen(false)}
|
||||||
|
maxWidth="lg"
|
||||||
|
fullWidth
|
||||||
|
// Zero transition — opens instantly
|
||||||
|
transitionDuration={0}
|
||||||
|
PaperProps={{
|
||||||
|
sx: {
|
||||||
|
borderRadius: 3,
|
||||||
|
bgcolor: '#0f172a',
|
||||||
|
color: '#f8fafc',
|
||||||
|
border: '1px solid #1e293b',
|
||||||
|
maxHeight: '90vh'
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent sx={{ p: 3 }}>
|
||||||
|
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 2 }}>
|
||||||
|
<Typography variant="h6" sx={{ fontWeight: 'bold', color: '#f8fafc' }}>Filters</Typography>
|
||||||
|
{draftSet.size > 0 && (
|
||||||
|
<Chip
|
||||||
|
label={`${draftSet.size} asset${draftSet.size > 1 ? 's' : ''} selected`}
|
||||||
|
size="small" color="primary"
|
||||||
|
onDelete={() => setDraftSet(new Set())}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Date & Chainage */}
|
||||||
|
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 2, mb: 3, alignItems: 'center' }}>
|
||||||
|
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
|
||||||
|
<Typography variant="body2" sx={{ fontWeight: 'bold', color: '#94a3b8', whiteSpace: 'nowrap' }}>From Date</Typography>
|
||||||
|
<TextField size="small" type="date" value={draftFromDate} onChange={(e) => setDraftFromDate(e.target.value)}
|
||||||
|
sx={{ bgcolor: 'rgba(255,255,255,0.07)', borderRadius: 1, input: { color: '#f8fafc' }, '& fieldset': { borderColor: '#334155' } }} />
|
||||||
|
</Box>
|
||||||
|
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
|
||||||
|
<Typography variant="body2" sx={{ fontWeight: 'bold', color: '#94a3b8', whiteSpace: 'nowrap' }}>Till Date</Typography>
|
||||||
|
<TextField size="small" type="date" value={draftTillDate} onChange={(e) => setDraftTillDate(e.target.value)}
|
||||||
|
sx={{ bgcolor: 'rgba(255,255,255,0.07)', borderRadius: 1, input: { color: '#f8fafc' }, '& fieldset': { borderColor: '#334155' } }} />
|
||||||
|
</Box>
|
||||||
|
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
|
||||||
|
<Typography variant="body2" sx={{ fontWeight: 'bold', color: '#94a3b8', whiteSpace: 'nowrap' }}>Chainage</Typography>
|
||||||
|
<TextField size="small" placeholder="From" value={draftMinChainage} onChange={(e) => setDraftMinChainage(e.target.value)}
|
||||||
|
sx={{ width: 90, bgcolor: 'rgba(255,255,255,0.07)', borderRadius: 1, input: { color: '#f8fafc' }, '& fieldset': { borderColor: '#334155' } }} />
|
||||||
|
<Typography variant="body2" sx={{ color: '#64748b' }}>—</Typography>
|
||||||
|
<TextField size="small" placeholder="To" value={draftMaxChainage} onChange={(e) => setDraftMaxChainage(e.target.value)}
|
||||||
|
sx={{ width: 90, bgcolor: 'rgba(255,255,255,0.07)', borderRadius: 1, input: { color: '#f8fafc' }, '& fieldset': { borderColor: '#334155' } }} />
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Divider sx={{ borderColor: '#1e293b', mb: 2 }} />
|
||||||
|
|
||||||
|
<Typography variant="subtitle1" sx={{ fontWeight: 'bold', color: '#f8fafc', mb: 1 }}>Assets</Typography>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
placeholder="Search assets..."
|
||||||
|
variant="outlined" size="small" fullWidth
|
||||||
|
value={assetSearch}
|
||||||
|
onChange={(e) => setAssetSearch(e.target.value)}
|
||||||
|
sx={{ mb: 2, bgcolor: 'rgba(255,255,255,0.05)', borderRadius: 1, input: { color: '#f8fafc' }, '& fieldset': { borderColor: '#334155' } }}
|
||||||
|
slotProps={{ input: { startAdornment: <InputAdornment position="start"><SearchIcon sx={{ color: '#64748b' }} /></InputAdornment> } }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormControlLabel
|
||||||
|
control={
|
||||||
|
<Checkbox checked={allSelected} indeterminate={someSelected} onChange={handleToggleAll}
|
||||||
|
sx={{ color: '#64748b', '&.Mui-checked': { color: '#3b82f6' }, '&.MuiCheckbox-indeterminate': { color: '#3b82f6' } }} />
|
||||||
|
}
|
||||||
|
label={<Typography variant="body2" sx={{ color: '#94a3b8', fontWeight: 'bold' }}>Select All ({allAssetIds.length})</Typography>}
|
||||||
|
sx={{ mb: 1 }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Box sx={{ maxHeight: 350, overflowY: 'auto', pr: 1 }}>
|
||||||
|
{filteredAssetTypes.length === 0 ? (
|
||||||
|
<Typography variant="body2" sx={{ color: '#64748b' }}>No assets match your search.</Typography>
|
||||||
|
) : (
|
||||||
|
filteredAssetTypes.map((type: any) => {
|
||||||
|
const groupIds: number[] = type.assets.map((a: any) => a.asset_id);
|
||||||
|
const allGroupSelected = groupIds.every(id => draftSet.has(id));
|
||||||
|
const someGroupSelected = groupIds.some(id => draftSet.has(id)) && !allGroupSelected;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box key={type.type_id} sx={{ mb: 2 }}>
|
||||||
|
<GroupHeader
|
||||||
|
typeName={type.type_name}
|
||||||
|
assetCount={type.assets.length}
|
||||||
|
allGroupSelected={allGroupSelected}
|
||||||
|
someGroupSelected={someGroupSelected}
|
||||||
|
onToggle={makeGroupToggle(groupIds)}
|
||||||
|
/>
|
||||||
|
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 0, pl: 3 }}>
|
||||||
|
{type.assets.map((asset: any) => (
|
||||||
|
<AssetRow
|
||||||
|
key={asset.asset_id}
|
||||||
|
assetId={asset.asset_id}
|
||||||
|
assetName={asset.asset_name}
|
||||||
|
checked={draftSet.has(asset.asset_id)}
|
||||||
|
onToggle={handleToggleAsset}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</DialogContent>
|
||||||
|
|
||||||
|
<DialogActions sx={{ justifyContent: 'space-between', px: 3, pb: 3, borderTop: '1px solid #1e293b', pt: 2 }}>
|
||||||
|
<Button variant="outlined" onClick={handleClearAll}
|
||||||
|
sx={{ borderColor: '#334155', color: '#94a3b8', borderRadius: 2, '&:hover': { borderColor: '#64748b', bgcolor: 'rgba(255,255,255,0.05)' } }}>
|
||||||
|
Clear All
|
||||||
|
</Button>
|
||||||
|
<Button variant="contained" onClick={handleApplyFilter} disabled={loading}
|
||||||
|
sx={{ bgcolor: '#3b82f6', color: '#fff', width: 160, borderRadius: 2, '&:hover': { bgcolor: '#2563eb' } }}>
|
||||||
|
{loading ? <CircularProgress size={22} color="inherit" /> : 'Apply Filters'}
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
55
src/pages/activity-feeds/FeedTabs.tsx
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Tabs, Tab, Box, IconButton } from '@mui/material';
|
||||||
|
import CloseIcon from '@mui/icons-material/Close';
|
||||||
|
import { useFeedStore } from '../../store/feedStore';
|
||||||
|
|
||||||
|
export const FeedTabs: React.FC = () => {
|
||||||
|
const { tabs, selectedTabIndex, setSelectedTabIndex, closeTab } = useFeedStore();
|
||||||
|
|
||||||
|
const handleChange = (_event: React.SyntheticEvent, newValue: number) => {
|
||||||
|
setSelectedTabIndex(newValue);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (tabs.length === 0) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ bgcolor: 'background.paper', pt: 1, px: 2 }}>
|
||||||
|
<Tabs
|
||||||
|
value={selectedTabIndex}
|
||||||
|
onChange={handleChange}
|
||||||
|
variant="scrollable"
|
||||||
|
scrollButtons="auto"
|
||||||
|
sx={{ minHeight: 40, '& .MuiTabs-indicator': { display: 'none' } }}
|
||||||
|
>
|
||||||
|
{tabs.map((tab, index) => (
|
||||||
|
<Tab
|
||||||
|
key={index}
|
||||||
|
sx={{
|
||||||
|
bgcolor: selectedTabIndex === index ? 'background.default' : 'transparent',
|
||||||
|
color: selectedTabIndex === index ? 'text.primary' : 'text.secondary',
|
||||||
|
borderTopLeftRadius: 4,
|
||||||
|
borderTopRightRadius: 4,
|
||||||
|
minHeight: 40,
|
||||||
|
textTransform: 'none',
|
||||||
|
fontWeight: 'bold',
|
||||||
|
mr: 1,
|
||||||
|
'&.Mui-selected': {
|
||||||
|
color: 'text.primary',
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
label={
|
||||||
|
<Box sx={{ display: 'flex', alignItems: 'center' }}>
|
||||||
|
{tab.date === '' ? 'Unaudited' : tab.date}
|
||||||
|
{index !== 0 && ( // Don't allow closing the first tab usually
|
||||||
|
<IconButton size="small" onClick={(e) => { e.stopPropagation(); closeTab(index); }} sx={{ ml: 1, color: 'inherit', p: 0.5 }}>
|
||||||
|
<CloseIcon fontSize="small" />
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Tabs>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
283
src/pages/activity-feeds/GlobalFeed.tsx
Normal file
@@ -0,0 +1,283 @@
|
|||||||
|
import React, { useEffect } from 'react';
|
||||||
|
import { Box, Typography, TablePagination, Button, FormControl, Select, MenuItem } from '@mui/material';
|
||||||
|
import FilterListIcon from '@mui/icons-material/FilterList';
|
||||||
|
import HistoryIcon from '@mui/icons-material/History';
|
||||||
|
import { TopFilterBar } from '../../components/common/TopFilterBar';
|
||||||
|
import { FeedTabs } from './FeedTabs';
|
||||||
|
import { AnomalyTable } from './AnomalyTable';
|
||||||
|
import { PreviewPanel } from './PreviewPanel';
|
||||||
|
import { useFeedStore } from '../../store/feedStore';
|
||||||
|
import { useAuthStore } from '../../store/authStore';
|
||||||
|
import { activityFeedsService } from '../../api/activityFeedsService';
|
||||||
|
export const GlobalFeed: React.FC = () => {
|
||||||
|
const {
|
||||||
|
setAssets, setAssetTypes, addTab, tabs, selectedTabIndex, updateTab,
|
||||||
|
sites, setSites, selectedSite, setSelectedSite, auditStatus,
|
||||||
|
isInitialized, setIsInitialized,
|
||||||
|
lastFetchedFilterKey, setLastFetchedFilterKey
|
||||||
|
} = useFeedStore();
|
||||||
|
const { user } = useAuthStore();
|
||||||
|
// Ref to skip the first run of the site/auditStatus effect
|
||||||
|
const isFirstRender = React.useRef(true);
|
||||||
|
useEffect(() => {
|
||||||
|
// Initial Load
|
||||||
|
const loadInitialData = async () => {
|
||||||
|
try {
|
||||||
|
const assetRes: any = await activityFeedsService.getAssets();
|
||||||
|
if (assetRes && assetRes.asset_types) {
|
||||||
|
// Map assets mimicking the Angular logic
|
||||||
|
let flattenedAssets: any[] = [];
|
||||||
|
assetRes.asset_types.forEach((type: any) => {
|
||||||
|
const mapped = type.assets.map((a: any) => ({
|
||||||
|
id: a.asset_id,
|
||||||
|
name: a.asset_name,
|
||||||
|
asset_type_id: type.type_id
|
||||||
|
}));
|
||||||
|
flattenedAssets = [...flattenedAssets, ...mapped];
|
||||||
|
});
|
||||||
|
setAssets(flattenedAssets);
|
||||||
|
setAssetTypes(assetRes.asset_types); // store raw grouped data for filters dialog
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch Sites
|
||||||
|
let defaultSite = null;
|
||||||
|
if (user?.org_id) {
|
||||||
|
try {
|
||||||
|
const sitesRes: any = await activityFeedsService.getOrganizationSites(user.org_id);
|
||||||
|
let parsedSites: any[] = [];
|
||||||
|
if (sitesRes?.responseData?.[0]?.records) {
|
||||||
|
parsedSites = sitesRes.responseData[0].records;
|
||||||
|
// Handle nested array response [ [ {site1}, {site2} ] ]
|
||||||
|
if (parsedSites.length === 1 && Array.isArray(parsedSites[0])) {
|
||||||
|
parsedSites = parsedSites[0];
|
||||||
|
} else if (parsedSites.length > 0 && Array.isArray(parsedSites[0])) {
|
||||||
|
parsedSites = parsedSites.flat();
|
||||||
|
}
|
||||||
|
} else if (Array.isArray(sitesRes)) {
|
||||||
|
parsedSites = sitesRes;
|
||||||
|
} else if (sitesRes?.data && Array.isArray(sitesRes.data)) {
|
||||||
|
parsedSites = sitesRes.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsedSites.length > 0) {
|
||||||
|
// Filter to ensure we only show sites for the currently selected org
|
||||||
|
parsedSites = parsedSites.filter(site => {
|
||||||
|
let siteOrgId = site.org_id;
|
||||||
|
if (siteOrgId === undefined && site.sub_sites && site.sub_sites.length > 0) {
|
||||||
|
siteOrgId = site.sub_sites[0].org_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (siteOrgId !== undefined && siteOrgId !== null) {
|
||||||
|
return String(siteOrgId) === String(user.org_id);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}).map(site => {
|
||||||
|
// Normalize site_id: if missing, aggregate from sub_sites
|
||||||
|
if (!site.site_id && site.sub_sites && site.sub_sites.length > 0) {
|
||||||
|
site.site_id = site.sub_sites.map((sub: any) => sub.site_id).filter(Boolean).join(',');
|
||||||
|
}
|
||||||
|
return site;
|
||||||
|
});
|
||||||
|
|
||||||
|
setSites(parsedSites);
|
||||||
|
defaultSite = { site_id: 'All Sites', site_name: 'All Sites' };
|
||||||
|
setSelectedSite(defaultSite);
|
||||||
|
}
|
||||||
|
} catch (siteErr) {
|
||||||
|
console.error("Failed to fetch sites", siteErr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add default Unaudited tab if empty and fetch data
|
||||||
|
if (useFeedStore.getState().tabs.length === 0) {
|
||||||
|
addTab({
|
||||||
|
date: '', // Unaudited
|
||||||
|
isRectificationTab: false,
|
||||||
|
totalAnomalyCount: 0,
|
||||||
|
anomalies: [],
|
||||||
|
anomaliesCopy: [],
|
||||||
|
selectedAnomalyIndex: 0,
|
||||||
|
filters: {},
|
||||||
|
page: 0,
|
||||||
|
rowsPerPage: 20
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const historyRes: any = await activityFeedsService.getHistory({
|
||||||
|
date: '',
|
||||||
|
pageNo: 0,
|
||||||
|
pageSize: 20,
|
||||||
|
siteIds: defaultSite?.site_id === 'All Sites' ? '' : (defaultSite?.site_id || ''),
|
||||||
|
isTrueFalse: auditStatus === 'False Audits' ? 'true' : 'both',
|
||||||
|
auto_audit: false,
|
||||||
|
isRectificationEnabled: false
|
||||||
|
});
|
||||||
|
if (historyRes && historyRes.anomalies) {
|
||||||
|
updateTab(0, {
|
||||||
|
anomalies: historyRes.anomalies,
|
||||||
|
anomaliesCopy: historyRes.anomalies,
|
||||||
|
totalAnomalyCount: historyRes.count || historyRes.anomalies.length
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (historyErr) {
|
||||||
|
console.error("[GlobalFeed] Failed to load history", historyErr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load initial feed data", error);
|
||||||
|
} finally {
|
||||||
|
setIsInitialized(true); // Mark as initialized regardless, to prevent retry loops
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// GUARD: Only run initial load once across tab switches
|
||||||
|
if (useFeedStore.getState().isInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
loadInitialData();
|
||||||
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
|
// Fetch data when selectedSite or auditStatus changes
|
||||||
|
useEffect(() => {
|
||||||
|
// GUARD: Skip if tabs are not initialized (initial load hasn't finished)
|
||||||
|
if (useFeedStore.getState().tabs.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build a key for the current filter state
|
||||||
|
const filterKey = `${selectedSite?.site_id ?? ''}|${auditStatus}`;
|
||||||
|
|
||||||
|
// CACHE HIT: This exact filter combo was already fetched — skip re-fetch on remount
|
||||||
|
if (filterKey === lastFetchedFilterKey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchFilteredHistory = async () => {
|
||||||
|
const state = useFeedStore.getState();
|
||||||
|
const currentTabIndex = state.selectedTabIndex > -1 ? state.selectedTabIndex : 0;
|
||||||
|
const activeTab = state.tabs[currentTabIndex];
|
||||||
|
const siteIdParam = (!selectedSite || selectedSite?.site_id === 'All Sites')
|
||||||
|
? '' : String(selectedSite.site_id || '');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const historyRes: any = await activityFeedsService.getHistory({
|
||||||
|
date: activeTab?.date || '',
|
||||||
|
pageNo: 0,
|
||||||
|
pageSize: 20,
|
||||||
|
siteIds: siteIdParam,
|
||||||
|
isTrueFalse: auditStatus === 'False Audits' ? 'true' : 'both',
|
||||||
|
auto_audit: false,
|
||||||
|
isRectificationEnabled: false,
|
||||||
|
...(activeTab?.filters || {})
|
||||||
|
});
|
||||||
|
if (historyRes && historyRes.anomalies) {
|
||||||
|
useFeedStore.getState().updateTab(currentTabIndex, {
|
||||||
|
anomalies: historyRes.anomalies,
|
||||||
|
anomaliesCopy: historyRes.anomalies,
|
||||||
|
totalAnomalyCount: historyRes.count || historyRes.anomalies.length
|
||||||
|
});
|
||||||
|
setLastFetchedFilterKey(filterKey); // mark this combo as fetched
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[GlobalFeed] Failed to load history for site/audit status change', err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchFilteredHistory();
|
||||||
|
// Use primitive/stable values to avoid spurious re-runs.
|
||||||
|
// selectedSite?.site_id and auditStatus are both strings/primitives.
|
||||||
|
}, [selectedSite?.site_id, auditStatus]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
|
const handlePageChange = async (event: unknown, newPage: number) => {
|
||||||
|
if (selectedTabIndex < 0 || tabs.length === 0) return;
|
||||||
|
const activeTab = tabs[selectedTabIndex];
|
||||||
|
const allSiteIds = sites.map(s => s.site_id).filter(Boolean).join(',');
|
||||||
|
const rowsPerPage = activeTab.rowsPerPage || 20;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const historyRes: any = await activityFeedsService.getHistory({
|
||||||
|
date: activeTab?.date || '',
|
||||||
|
pageNo: newPage * rowsPerPage,
|
||||||
|
pageSize: rowsPerPage,
|
||||||
|
siteIds: selectedSite?.site_id === 'All Sites' ? '' : (selectedSite?.site_id || ''),
|
||||||
|
isTrueFalse: auditStatus === 'False Audits' ? 'true' : 'both',
|
||||||
|
auto_audit: false,
|
||||||
|
isRectificationEnabled: false,
|
||||||
|
...(activeTab?.filters || {})
|
||||||
|
});
|
||||||
|
if (historyRes && historyRes.anomalies) {
|
||||||
|
updateTab(selectedTabIndex, {
|
||||||
|
anomalies: historyRes.anomalies,
|
||||||
|
anomaliesCopy: historyRes.anomalies,
|
||||||
|
totalAnomalyCount: historyRes.count || historyRes.anomalies.length,
|
||||||
|
page: newPage,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Failed to load history for page change", err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRowsPerPageChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
if (selectedTabIndex < 0 || tabs.length === 0) return;
|
||||||
|
const activeTab = tabs[selectedTabIndex];
|
||||||
|
const allSiteIds = sites.map(s => s.site_id).filter(Boolean).join(',');
|
||||||
|
const newRowsPerPage = parseInt(event.target.value, 10);
|
||||||
|
const newPage = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const historyRes: any = await activityFeedsService.getHistory({
|
||||||
|
date: activeTab?.date || '',
|
||||||
|
pageNo: newPage * newRowsPerPage,
|
||||||
|
pageSize: newRowsPerPage,
|
||||||
|
siteIds: selectedSite?.site_id === 'All Sites' ? '' : (selectedSite?.site_id || ''),
|
||||||
|
isTrueFalse: auditStatus === 'False Audits' ? 'true' : 'both',
|
||||||
|
auto_audit: false,
|
||||||
|
isRectificationEnabled: false,
|
||||||
|
...(activeTab?.filters || {})
|
||||||
|
});
|
||||||
|
if (historyRes && historyRes.anomalies) {
|
||||||
|
updateTab(selectedTabIndex, {
|
||||||
|
anomalies: historyRes.anomalies,
|
||||||
|
anomaliesCopy: historyRes.anomalies,
|
||||||
|
totalAnomalyCount: historyRes.count || historyRes.anomalies.length,
|
||||||
|
page: newPage,
|
||||||
|
rowsPerPage: newRowsPerPage,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Failed to load history for rowsPerPage change", err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ height: 'calc(100vh - 64px)', display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
||||||
|
|
||||||
|
<TopFilterBar />
|
||||||
|
<FeedTabs />
|
||||||
|
|
||||||
|
<Box sx={{ display: 'flex', flex: 1, overflow: 'hidden', bgcolor: 'background.default' }}>
|
||||||
|
{/* Left side Table */}
|
||||||
|
<Box sx={{ flex: 1, overflow: 'auto', px: 2, display: 'flex', flexDirection: 'column' }}>
|
||||||
|
<Box sx={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center', py: 0 }}>
|
||||||
|
<TablePagination
|
||||||
|
component="div"
|
||||||
|
count={tabs[selectedTabIndex]?.totalAnomalyCount || 0}
|
||||||
|
page={tabs[selectedTabIndex]?.page || 0}
|
||||||
|
onPageChange={handlePageChange}
|
||||||
|
rowsPerPage={tabs[selectedTabIndex]?.rowsPerPage || 20}
|
||||||
|
onRowsPerPageChange={handleRowsPerPageChange}
|
||||||
|
rowsPerPageOptions={[10, 20, 50, 100]}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Box sx={{ flex: 1, overflow: 'auto' }}>
|
||||||
|
<AnomalyTable />
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Right side Preview Panel */}
|
||||||
|
<PreviewPanel />
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
80
src/pages/activity-feeds/PreviewPanel.tsx
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Box, Typography, Button } from '@mui/material';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { useFeedStore } from '../../store/feedStore';
|
||||||
|
|
||||||
|
export const PreviewPanel: React.FC = () => {
|
||||||
|
const { tabs, selectedTabIndex } = useFeedStore();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
if (tabs.length === 0 || selectedTabIndex < 0) return null;
|
||||||
|
|
||||||
|
const activeTab = tabs[selectedTabIndex];
|
||||||
|
const anomalies = activeTab.anomalies || [];
|
||||||
|
const selectedIndex = activeTab.selectedAnomalyIndex || 0;
|
||||||
|
|
||||||
|
const anomaly = anomalies[selectedIndex];
|
||||||
|
|
||||||
|
if (!anomaly) {
|
||||||
|
return (
|
||||||
|
<Box sx={{ width: 350, p: 2, bgcolor: '#f4f6f8', height: '100%', borderLeft: '1px solid #ddd' }}>
|
||||||
|
<Typography>No anomaly selected</Typography>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const IMAGES_AWS_PREFIX = "https://auditor-master-images.seekright.com/SeekRight/";
|
||||||
|
const IMAGES_TEST_AUDIT_PREFIX = "https://dashboard-images.seekright.com/SeekRight/";
|
||||||
|
|
||||||
|
let masterImageSrc = '';
|
||||||
|
if (anomaly.Frame_Master) {
|
||||||
|
masterImageSrc = IMAGES_AWS_PREFIX + anomaly.Frame_Master;
|
||||||
|
} else if (!anomaly.Frame_Master && !anomaly.Frame_Test) {
|
||||||
|
masterImageSrc = '/assets/images/master_and_shift_image_not_available.png';
|
||||||
|
} else {
|
||||||
|
masterImageSrc = '/assets/images/only_master_image_not_available.png';
|
||||||
|
}
|
||||||
|
|
||||||
|
let anomalyImageSrc = '/assets/images/placeholder.jpg';
|
||||||
|
if (anomaly.Frame_Test) {
|
||||||
|
anomalyImageSrc = IMAGES_TEST_AUDIT_PREFIX + anomaly.Frame_Test;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ width: 400, p: 2, bgcolor: 'background.paper', height: 'calc(100vh - 120px)', borderLeft: '1px solid rgba(255,255,255,0.1)', overflowY: 'auto' }}>
|
||||||
|
|
||||||
|
<Box sx={{ mb: 2, border: '1px solid rgba(255,255,255,0.1)', borderRadius: 2, overflow: 'hidden' }}>
|
||||||
|
<img
|
||||||
|
src={masterImageSrc}
|
||||||
|
alt="Master"
|
||||||
|
style={{ width: '100%', height: 'auto', display: 'block' }}
|
||||||
|
/>
|
||||||
|
<Box sx={{ bgcolor: 'rgba(255,255,255,0.05)', color: 'text.primary', textAlign: 'center', py: 0.5 }}>
|
||||||
|
<Typography variant="body2" sx={{ fontWeight: 'bold' }}>MASTER IMAGE</Typography>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Box sx={{ mb: 2, border: '1px solid rgba(255,255,255,0.1)', borderRadius: 2, overflow: 'hidden' }}>
|
||||||
|
<img
|
||||||
|
src={anomalyImageSrc}
|
||||||
|
alt="Anomaly"
|
||||||
|
style={{ width: '100%', height: 'auto', display: 'block' }}
|
||||||
|
/>
|
||||||
|
<Box sx={{ bgcolor: 'rgba(255,255,255,0.05)', color: 'text.primary', textAlign: 'center', py: 0.5 }}>
|
||||||
|
<Typography variant="body2" sx={{ fontWeight: 'bold' }}>ANOMALY IMAGE</Typography>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
fullWidth
|
||||||
|
color="primary"
|
||||||
|
onClick={() => navigate('/audit-session', { state: { useExistingFeed: true, startIndex: selectedIndex } })}
|
||||||
|
sx={{ mt: 1, py: 1.5, fontWeight: 'bold', borderRadius: 2 }}
|
||||||
|
>
|
||||||
|
Audit Item
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
477
src/pages/audit-session/AuditSession.tsx
Normal file
@@ -0,0 +1,477 @@
|
|||||||
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
|
import { Box, Typography, Button, IconButton, Chip } from '@mui/material';
|
||||||
|
import { useNavigate, useLocation } from 'react-router-dom';
|
||||||
|
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
|
||||||
|
import { activityFeedsService } from '../../api/activityFeedsService';
|
||||||
|
import { useAuthStore } from '../../store/authStore';
|
||||||
|
import { useFeedStore } from '../../store/feedStore';
|
||||||
|
|
||||||
|
export const AuditSession: React.FC = () => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { user } = useAuthStore();
|
||||||
|
const [anomalies, setAnomalies] = useState<any[]>([]);
|
||||||
|
const [currentIndex, setCurrentIndex] = useState(0);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [carouselIndex, setCarouselIndex] = useState(0);
|
||||||
|
|
||||||
|
// For the right sidebar state
|
||||||
|
const [selectedCategory, setSelectedCategory] = useState<number | null>(null);
|
||||||
|
const [notes, setNotes] = useState('');
|
||||||
|
const [isAnomaly, setIsAnomaly] = useState<boolean | null>(null); // true = Anomaly, false = Safe
|
||||||
|
|
||||||
|
const location = useLocation();
|
||||||
|
const { tabs, selectedTabIndex } = useFeedStore();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const navState = location.state as any;
|
||||||
|
|
||||||
|
if (navState?.useExistingFeed) {
|
||||||
|
// Use anomalies from the global feed store
|
||||||
|
const activeTab = tabs[selectedTabIndex];
|
||||||
|
if (activeTab && activeTab.anomalies) {
|
||||||
|
setAnomalies(activeTab.anomalies);
|
||||||
|
setCurrentIndex(navState.startIndex || 0);
|
||||||
|
setLoading(false);
|
||||||
|
} else {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fetch 50 items for the session (default behavior from Dashboard)
|
||||||
|
const fetchSessionData = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
const res: any = await activityFeedsService.getHistory({
|
||||||
|
date: '',
|
||||||
|
pageNo: 0,
|
||||||
|
pageSize: 50,
|
||||||
|
isTrueFalse: 'false', // Fetch unaudited
|
||||||
|
auto_audit: false,
|
||||||
|
isRectificationEnabled: false,
|
||||||
|
});
|
||||||
|
if (res && res.anomalies) {
|
||||||
|
setAnomalies(res.anomalies);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to fetch session data', err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchSessionData();
|
||||||
|
}
|
||||||
|
}, [location.state, tabs, selectedTabIndex]);
|
||||||
|
|
||||||
|
const IMAGES_AWS_PREFIX = "https://auditor-master-images.seekright.com/SeekRight/";
|
||||||
|
const IMAGES_TEST_AUDIT_PREFIX = "https://dashboard-images.seekright.com/SeekRight/";
|
||||||
|
|
||||||
|
const currentAnomaly = anomalies[currentIndex];
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentAnomaly?.images && currentAnomaly.images.length > 0) {
|
||||||
|
const selectedIdx = currentAnomaly.images.findIndex((img: any) => img.selected);
|
||||||
|
setCarouselIndex(selectedIdx !== -1 ? selectedIdx : 0);
|
||||||
|
} else {
|
||||||
|
setCarouselIndex(0);
|
||||||
|
}
|
||||||
|
}, [currentAnomaly]);
|
||||||
|
|
||||||
|
let masterImageSrc = '';
|
||||||
|
let anomalyImageSrc = '';
|
||||||
|
let latStr = 'N/A';
|
||||||
|
let longStr = 'E/A';
|
||||||
|
|
||||||
|
if (currentAnomaly) {
|
||||||
|
if (currentAnomaly.Frame_Master) {
|
||||||
|
masterImageSrc = IMAGES_AWS_PREFIX + currentAnomaly.Frame_Master;
|
||||||
|
} else if (!currentAnomaly.Frame_Master && !currentAnomaly.Frame_Test) {
|
||||||
|
masterImageSrc = '/assets/images/master_and_shift_image_not_available.png';
|
||||||
|
} else {
|
||||||
|
masterImageSrc = '/assets/images/only_master_image_not_available.png';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse Position
|
||||||
|
if (currentAnomaly.Pos) {
|
||||||
|
const match = String(currentAnomaly.Pos).match(/([NS][0-9.]+)([EW][0-9.]+)/i);
|
||||||
|
if (match) {
|
||||||
|
latStr = match[1];
|
||||||
|
longStr = match[2];
|
||||||
|
} else {
|
||||||
|
latStr = currentAnomaly.Pos; // Fallback
|
||||||
|
longStr = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mediaItems: { type: 'image'|'video', url: string }[] = React.useMemo(() => {
|
||||||
|
if (!currentAnomaly) return [];
|
||||||
|
const items: { type: 'image'|'video', url: string }[] = [];
|
||||||
|
|
||||||
|
if (currentAnomaly.images && currentAnomaly.images.length > 0) {
|
||||||
|
currentAnomaly.images.forEach((img: any) => {
|
||||||
|
items.push({ type: 'image', url: IMAGES_TEST_AUDIT_PREFIX + img.src });
|
||||||
|
});
|
||||||
|
} else if (currentAnomaly.Frame_Test) {
|
||||||
|
items.push({ type: 'image', url: IMAGES_TEST_AUDIT_PREFIX + currentAnomaly.Frame_Test });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentAnomaly.video_url) {
|
||||||
|
items.push({ type: 'video', url: IMAGES_TEST_AUDIT_PREFIX + currentAnomaly.video_url });
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}, [currentAnomaly]);
|
||||||
|
|
||||||
|
const handleNext = () => {
|
||||||
|
if (currentIndex < anomalies.length - 1) {
|
||||||
|
setCurrentIndex(prev => prev + 1);
|
||||||
|
// Reset form
|
||||||
|
setSelectedCategory(null);
|
||||||
|
setNotes('');
|
||||||
|
setIsAnomaly(null);
|
||||||
|
} else {
|
||||||
|
// Done with session
|
||||||
|
const navState = location.state as any;
|
||||||
|
if (navState?.useExistingFeed) {
|
||||||
|
navigate('/activity-feeds');
|
||||||
|
} else {
|
||||||
|
navigate('/dashboard');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePrev = () => {
|
||||||
|
if (currentIndex > 0) {
|
||||||
|
setCurrentIndex(prev => prev - 1);
|
||||||
|
// We would ideally preserve form state for previously visited items
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSaveAndNext = async () => {
|
||||||
|
if (!currentAnomaly) return;
|
||||||
|
|
||||||
|
// Placeholder for save logic
|
||||||
|
// await activityFeedsService.updateAuditedAnomaly(...)
|
||||||
|
console.log('Saved:', { id: currentAnomaly.anomaly_id, isAnomaly, selectedCategory, notes });
|
||||||
|
handleNext();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Keyboard shortcuts
|
||||||
|
const handleKeyDown = useCallback((e: KeyboardEvent) => {
|
||||||
|
// Prevent default on shortcuts if focused on inputs?
|
||||||
|
if (document.activeElement?.tagName === 'TEXTAREA' || document.activeElement?.tagName === 'INPUT') {
|
||||||
|
return; // Don't trigger shortcuts when typing notes
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (e.key.toLowerCase()) {
|
||||||
|
case 'a':
|
||||||
|
setIsAnomaly(true);
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
setIsAnomaly(false);
|
||||||
|
break;
|
||||||
|
case '1': setSelectedCategory(1); break;
|
||||||
|
case '2': setSelectedCategory(2); break;
|
||||||
|
case '3': setSelectedCategory(3); break;
|
||||||
|
case '4': setSelectedCategory(4); break;
|
||||||
|
case '5': setSelectedCategory(5); break;
|
||||||
|
case 'enter':
|
||||||
|
handleSaveAndNext();
|
||||||
|
break;
|
||||||
|
case 'arrowright':
|
||||||
|
handleSaveAndNext();
|
||||||
|
break;
|
||||||
|
case 'arrowleft':
|
||||||
|
handlePrev();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, [currentIndex, anomalies, isAnomaly, selectedCategory, notes]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener('keydown', handleKeyDown);
|
||||||
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
||||||
|
}, [handleKeyDown]);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return <Box sx={{ p: 4, color: 'white' }}>Loading session...</Box>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (anomalies.length === 0) {
|
||||||
|
return (
|
||||||
|
<Box sx={{ p: 4, color: 'white' }}>
|
||||||
|
<Typography mb={2}>No unaudited anomalies found to audit.</Typography>
|
||||||
|
<Button variant="contained" onClick={() => {
|
||||||
|
const navState = location.state as any;
|
||||||
|
navigate(navState?.useExistingFeed ? '/activity-feeds' : '/dashboard');
|
||||||
|
}}>Back</Button>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const getSeverityBadge = () => {
|
||||||
|
// Placeholder badge logic
|
||||||
|
return <Chip label="HIGH" color="error" size="small" sx={{ borderRadius: 1, fontWeight: 'bold' }} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
position: 'fixed',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
bgcolor: '#0b1121',
|
||||||
|
color: '#f8fafc',
|
||||||
|
overflow: 'hidden',
|
||||||
|
zIndex: 9999
|
||||||
|
}}>
|
||||||
|
|
||||||
|
{/* Header */}
|
||||||
|
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', p: 1, px: 2, borderBottom: '1px solid #1e293b', bgcolor: '#0f172a' }}>
|
||||||
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
||||||
|
<Button
|
||||||
|
startIcon={<ArrowBackIcon fontSize="small" />}
|
||||||
|
onClick={() => {
|
||||||
|
const navState = location.state as any;
|
||||||
|
navigate(navState?.useExistingFeed ? '/activity-feeds' : '/dashboard');
|
||||||
|
}}
|
||||||
|
sx={{ color: '#94a3b8', textTransform: 'none', minWidth: 'auto', p: 0, '&:hover': { color: 'white', bgcolor: 'transparent' } }}
|
||||||
|
>
|
||||||
|
Back
|
||||||
|
</Button>
|
||||||
|
<Typography sx={{ fontWeight: 'bold', fontSize: '0.9rem' }}>
|
||||||
|
Item {currentIndex + 1} of {anomalies.length} <span style={{ color: '#64748b', fontWeight: 'normal' }}>(session)</span>
|
||||||
|
</Typography>
|
||||||
|
{getSeverityBadge()}
|
||||||
|
</Box>
|
||||||
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
||||||
|
<Typography sx={{ fontWeight: 'bold', fontSize: '0.9rem' }}>{user?.first_name} {user?.last_name}</Typography>
|
||||||
|
<Button size="small" sx={{ color: '#94a3b8', border: '1px solid #334155', textTransform: 'none', borderRadius: 2 }}>? Shortcuts</Button>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Main Content Area */}
|
||||||
|
<Box sx={{ display: 'flex', flex: 1, overflow: 'hidden', p: 2, gap: 2 }}>
|
||||||
|
|
||||||
|
{/* Left Side: Images & Overlay */}
|
||||||
|
<Box sx={{ display: 'flex', flexDirection: 'column', flex: 1, gap: 2, overflow: 'hidden' }}>
|
||||||
|
|
||||||
|
{/* Images Row */}
|
||||||
|
<Box sx={{ display: 'flex', flex: 1, gap: 2, overflow: 'hidden' }}>
|
||||||
|
{/* Previous Image Pane */}
|
||||||
|
<Box sx={{ flex: 1, bgcolor: '#0f172a', borderRadius: 2, border: '1px solid #1e293b', overflow: 'hidden', display: 'flex', flexDirection: 'column' }}>
|
||||||
|
<Box sx={{ px: 2, py: 1, borderBottom: '1px solid #1e293b', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', fontWeight: 'bold', color: '#94a3b8', letterSpacing: 1 }}>MASTER IMAGE</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box sx={{ flex: 1, position: 'relative' }}>
|
||||||
|
{masterImageSrc ? (
|
||||||
|
<img src={masterImageSrc} alt="Master" style={{ width: '100%', height: '100%', objectFit: 'contain' }} />
|
||||||
|
) : (
|
||||||
|
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%', color: '#334155' }}>No Master Image</Box>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Current Image Pane */}
|
||||||
|
<Box sx={{ flex: 1, bgcolor: '#0f172a', borderRadius: 2, border: '1px solid #1e293b', overflow: 'hidden', display: 'flex', flexDirection: 'column' }}>
|
||||||
|
<Box sx={{ px: 2, py: 1, borderBottom: '1px solid #1e293b', display: 'flex', justifyContent: 'space-between', alignItems: 'center', bgcolor: '#1e3a8a' }}>
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', fontWeight: 'bold', color: '#60a5fa', letterSpacing: 1 }}>ANOMALY IMAGE</Typography>
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', color: '#93c5fd' }}>{currentAnomaly?.date_of_audit || currentAnomaly?.Created_on}</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box sx={{ flex: 1, position: 'relative' }}>
|
||||||
|
{mediaItems.length > 0 ? (
|
||||||
|
<>
|
||||||
|
{mediaItems[carouselIndex]?.type === 'video' ? (
|
||||||
|
<video src={mediaItems[carouselIndex]?.url} controls autoPlay loop style={{ width: '100%', height: '100%', objectFit: 'contain' }} />
|
||||||
|
) : (
|
||||||
|
<img src={mediaItems[carouselIndex]?.url} alt="Anomaly" style={{ width: '100%', height: '100%', objectFit: 'contain' }} />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{mediaItems.length > 1 && (
|
||||||
|
<Box sx={{ position: 'absolute', bottom: 16, left: '50%', transform: 'translateX(-50%)', display: 'flex', gap: 1, bgcolor: 'rgba(0,0,0,0.6)', p: 0.5, borderRadius: 2 }}>
|
||||||
|
<Button size="small" variant="text" sx={{ color: 'white', minWidth: 'auto', px: 2, '&:hover': { bgcolor: 'rgba(255,255,255,0.1)' } }} onClick={() => setCarouselIndex(prev => prev > 0 ? prev - 1 : mediaItems.length - 1)}>
|
||||||
|
<
|
||||||
|
</Button>
|
||||||
|
<Typography sx={{ color: 'white', px: 1, display: 'flex', alignItems: 'center', fontSize: '0.875rem' }}>
|
||||||
|
{carouselIndex + 1} / {mediaItems.length}
|
||||||
|
</Typography>
|
||||||
|
<Button size="small" variant="text" sx={{ color: 'white', minWidth: 'auto', px: 2, '&:hover': { bgcolor: 'rgba(255,255,255,0.1)' } }} onClick={() => setCarouselIndex(prev => prev < mediaItems.length - 1 ? prev + 1 : 0)}>
|
||||||
|
>
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%', color: '#334155' }}>No Anomaly Media</Box>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Bottom Bar: Location Overlay */}
|
||||||
|
<Box sx={{ bgcolor: '#0f172a', borderRadius: 2, border: '1px solid #1e293b', p: 2, display: 'flex', alignItems: 'center', gap: 2 }}>
|
||||||
|
<Box sx={{ width: 12, height: 12, borderRadius: '50%', bgcolor: '#ef4444' }} />
|
||||||
|
<Box>
|
||||||
|
<Typography sx={{ fontWeight: 'bold', fontSize: '0.9rem' }}>{currentAnomaly?.Plaza || 'Unknown Location'}</Typography>
|
||||||
|
<Typography sx={{ fontSize: '0.8rem', color: '#94a3b8' }}>
|
||||||
|
{latStr}, {longStr} • ID #{currentAnomaly?.id || currentAnomaly?.anomaly_id || 'N/A'}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Right Side: Sidebar */}
|
||||||
|
<Box sx={{ width: 320, display: 'flex', flexDirection: 'column', gap: 3 }}>
|
||||||
|
|
||||||
|
{/* Anomaly/Safe Toggle */}
|
||||||
|
<Box>
|
||||||
|
<Box sx={{ display: 'flex', justifyContent: 'space-between', mb: 1 }}>
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', fontWeight: 'bold', color: '#94a3b8', letterSpacing: 1 }}>ANOMALY?</Typography>
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', color: '#64748b' }}>A / S</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box sx={{ display: 'flex', gap: 1 }}>
|
||||||
|
<Button
|
||||||
|
fullWidth
|
||||||
|
variant={isAnomaly === true ? "contained" : "outlined"}
|
||||||
|
color={isAnomaly === true ? "error" : "inherit"}
|
||||||
|
onClick={() => setIsAnomaly(true)}
|
||||||
|
sx={{ borderRadius: 2, textTransform: 'none', borderColor: '#334155', color: isAnomaly === true ? 'white' : '#cbd5e1' }}
|
||||||
|
>
|
||||||
|
⚠️ Anomaly
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
fullWidth
|
||||||
|
variant={isAnomaly === false ? "contained" : "outlined"}
|
||||||
|
color={isAnomaly === false ? "success" : "inherit"}
|
||||||
|
onClick={() => setIsAnomaly(false)}
|
||||||
|
sx={{ borderRadius: 2, textTransform: 'none', borderColor: '#334155', color: isAnomaly === false ? 'white' : '#cbd5e1' }}
|
||||||
|
>
|
||||||
|
✓ Safe
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Category */}
|
||||||
|
<Box>
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', fontWeight: 'bold', color: '#94a3b8', letterSpacing: 1, mb: 1 }}>CATEGORY</Typography>
|
||||||
|
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}>
|
||||||
|
{[
|
||||||
|
{ id: 1, label: 'No Issue', color: '#22c55e' },
|
||||||
|
{ id: 2, label: 'Minor Crack', color: '#eab308' },
|
||||||
|
{ id: 3, label: 'Major Crack', color: '#f97316' },
|
||||||
|
{ id: 4, label: 'Structural Damage', color: '#ef4444' },
|
||||||
|
{ id: 5, label: 'Needs Investigation', color: '#8b5cf6' },
|
||||||
|
].map(cat => (
|
||||||
|
<Button
|
||||||
|
key={cat.id}
|
||||||
|
onClick={() => setSelectedCategory(cat.id)}
|
||||||
|
sx={{
|
||||||
|
justifyContent: 'flex-start',
|
||||||
|
textTransform: 'none',
|
||||||
|
color: selectedCategory === cat.id ? 'white' : '#cbd5e1',
|
||||||
|
bgcolor: selectedCategory === cat.id ? 'rgba(255,255,255,0.05)' : 'transparent',
|
||||||
|
borderRadius: 2,
|
||||||
|
p: 1,
|
||||||
|
'&:hover': { bgcolor: 'rgba(255,255,255,0.1)' }
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box sx={{ width: 24, height: 24, borderRadius: '50%', bgcolor: cat.color, display: 'flex', alignItems: 'center', justifyContent: 'center', mr: 2, fontSize: '0.75rem', fontWeight: 'bold', color: 'white' }}>
|
||||||
|
{cat.id}
|
||||||
|
</Box>
|
||||||
|
{cat.label}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Notes */}
|
||||||
|
<Box sx={{ flex: 1, display: 'flex', flexDirection: 'column', minHeight: 0 }}>
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', fontWeight: 'bold', color: '#94a3b8', letterSpacing: 1, mb: 1 }}>NOTES</Typography>
|
||||||
|
<Box
|
||||||
|
component="textarea"
|
||||||
|
value={notes}
|
||||||
|
onChange={(e) => setNotes(e.target.value)}
|
||||||
|
placeholder="Optional observations..."
|
||||||
|
sx={{
|
||||||
|
width: '100%',
|
||||||
|
flex: 1,
|
||||||
|
minHeight: 60,
|
||||||
|
bgcolor: '#0f172a',
|
||||||
|
border: '1px solid #1e293b',
|
||||||
|
borderRadius: 2,
|
||||||
|
color: 'white',
|
||||||
|
p: 2,
|
||||||
|
fontFamily: 'inherit',
|
||||||
|
resize: 'none',
|
||||||
|
'&:focus': { outline: 'none', borderColor: '#3b82f6' }
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Actions */}
|
||||||
|
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={handleSaveAndNext}
|
||||||
|
sx={{ borderRadius: 2, py: 1.5, textTransform: 'none', fontWeight: 'bold', display: 'flex', justifyContent: 'space-between', px: 3 }}
|
||||||
|
>
|
||||||
|
Save & Next <Typography component="span" sx={{ fontSize: '0.75rem', opacity: 0.7 }}>Enter / →</Typography>
|
||||||
|
</Button>
|
||||||
|
<Box sx={{ display: 'flex', gap: 1 }}>
|
||||||
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
onClick={handlePrev}
|
||||||
|
disabled={currentIndex === 0}
|
||||||
|
sx={{ flex: 1, borderRadius: 2, textTransform: 'none', borderColor: '#1e293b', color: '#94a3b8', '&:hover': { borderColor: '#334155' } }}
|
||||||
|
>
|
||||||
|
← Prev
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
onClick={handleNext}
|
||||||
|
sx={{ flex: 1, borderRadius: 2, textTransform: 'none', borderColor: '#1e293b', color: '#94a3b8', '&:hover': { borderColor: '#334155' } }}
|
||||||
|
>
|
||||||
|
Skip <span style={{ fontSize: '0.75rem', opacity: 0.7, marginLeft: 8 }}>Tab</span>
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Footer Shortcuts */}
|
||||||
|
<Box sx={{ borderTop: '1px solid #1e293b', p: 1, px: 2, display: 'flex', gap: 3, alignItems: 'center', overflowX: 'auto', '& > div': { display: 'flex', alignItems: 'center', gap: 1, whiteSpace: 'nowrap' } }}>
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', color: '#64748b' }}>Keys:</Typography>
|
||||||
|
<Box>
|
||||||
|
<Chip label="A" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Anomaly</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Chip label="S" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Safe</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Chip label="1-5" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Category</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Chip label="Enter" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Save & Next</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Chip label="← →" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Navigate</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Chip label="Tab" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Skip</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Chip label="?" size="small" sx={{ height: 20, fontSize: '0.65rem', bgcolor: '#1e293b', color: '#cbd5e1' }} />
|
||||||
|
<Typography sx={{ fontSize: '0.75rem', color: '#94a3b8' }}>Help</Typography>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
205
src/pages/dashboard/Dashboard.tsx
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { Box, Typography, Button, Paper, LinearProgress, Container } from '@mui/material';
|
||||||
|
import WarningAmberIcon from '@mui/icons-material/WarningAmber';
|
||||||
|
import { activityFeedsService } from '../../api/activityFeedsService';
|
||||||
|
import { TopFilterBar } from '../../components/common/TopFilterBar';
|
||||||
|
import { useFeedStore } from '../../store/feedStore';
|
||||||
|
|
||||||
|
export const Dashboard: React.FC = () => {
|
||||||
|
const {
|
||||||
|
selectedSite, auditStatus, filterFromDate, filterTillDate,
|
||||||
|
filterMinChainage, filterMaxChainage,
|
||||||
|
selectedAssetIds, dashboardCache, setDashboardCache
|
||||||
|
} = useFeedStore();
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const selectedSiteId = selectedSite?.site_id ?? '';
|
||||||
|
const assetIdsKey = selectedAssetIds.join(',');
|
||||||
|
|
||||||
|
// Build a key that uniquely identifies the current filter state
|
||||||
|
const currentFilterKey = `${selectedSiteId}|${auditStatus}|${filterFromDate}|${filterTillDate}|${assetIdsKey}|${filterMinChainage}|${filterMaxChainage}`;
|
||||||
|
|
||||||
|
// Initialise stats from cache immediately (no flicker on tab switch)
|
||||||
|
const [stats, setStats] = useState(() =>
|
||||||
|
dashboardCache.stats ?? { total: 0, audited: 0, pending: 0, anomaliesFound: 0 }
|
||||||
|
);
|
||||||
|
// Only show loading spinner if there's no cached result for these filters
|
||||||
|
const [loading, setLoading] = useState(dashboardCache.stats === null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// CACHE HIT: filters unchanged since last fetch — skip API call entirely
|
||||||
|
if (dashboardCache.stats !== null && currentFilterKey === `${dashboardCache.siteId}|${dashboardCache.auditStatus}|${dashboardCache.fromDate}|${dashboardCache.tillDate}|${dashboardCache.assetIds}|${dashboardCache.minChainage}|${dashboardCache.maxChainage}`) {
|
||||||
|
setStats(dashboardCache.stats);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchStats = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
const res: any = await activityFeedsService.getHistory({
|
||||||
|
date: '',
|
||||||
|
pageNo: 0,
|
||||||
|
pageSize: 200,
|
||||||
|
sortByDateAsc: false,
|
||||||
|
isRectificationEnabled: false,
|
||||||
|
isTrueFalse: auditStatus === 'False Audits' ? 'true' : 'both',
|
||||||
|
auto_audit: false,
|
||||||
|
siteIds: (!selectedSiteId || selectedSiteId === 'All Sites') ? '' : selectedSiteId,
|
||||||
|
assetsIds: assetIdsKey,
|
||||||
|
fromDate: filterFromDate,
|
||||||
|
tillDate: filterTillDate,
|
||||||
|
fromChainage: filterMinChainage,
|
||||||
|
toChainage: filterMaxChainage,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
const anomalies = res.anomalies || [];
|
||||||
|
const newStats = {
|
||||||
|
total: res.count || anomalies.length,
|
||||||
|
audited: anomalies.filter((a: any) => a.IsAudited === 1).length,
|
||||||
|
pending: anomalies.filter((a: any) => a.IsAudited === 0).length,
|
||||||
|
anomaliesFound: anomalies.filter((a: any) => a.Audit_status === 1).length,
|
||||||
|
};
|
||||||
|
setStats(newStats);
|
||||||
|
// Persist to store cache so re-mounting the Dashboard skips this fetch
|
||||||
|
setDashboardCache({
|
||||||
|
siteId: selectedSiteId,
|
||||||
|
auditStatus,
|
||||||
|
fromDate: filterFromDate,
|
||||||
|
tillDate: filterTillDate,
|
||||||
|
assetIds: assetIdsKey,
|
||||||
|
minChainage: filterMinChainage,
|
||||||
|
maxChainage: filterMaxChainage,
|
||||||
|
stats: newStats,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to load dashboard stats', err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchStats();
|
||||||
|
}, [currentFilterKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
|
const progressPercent = stats.total > 0 ? Math.round((stats.audited / stats.total) * 100) : 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ width: '100%', maxWidth: '100vw', display: 'flex', flexDirection: 'column' }}>
|
||||||
|
<TopFilterBar />
|
||||||
|
<Box sx={{ px: 2, pt: 2, pb: 4, width: '100%' }}>
|
||||||
|
<Box sx={{ width: '100%' }}>
|
||||||
|
|
||||||
|
{/* Stats Row */}
|
||||||
|
<Box sx={{ display: 'flex', gap: 2, mb: 3 }}>
|
||||||
|
{/* Total Items */}
|
||||||
|
<Paper sx={{
|
||||||
|
flex: 1, p: 3, bgcolor: '#0f172a', border: '1px solid #1e293b', borderRadius: 2
|
||||||
|
}}>
|
||||||
|
<Typography variant="body2" sx={{ color: '#94a3b8', mb: 1 }}>Total Items</Typography>
|
||||||
|
<Typography variant="h4" sx={{ color: '#3b82f6', fontWeight: 'bold' }}>
|
||||||
|
{loading ? '...' : stats.total.toLocaleString()}
|
||||||
|
</Typography>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
{/* Audited */}
|
||||||
|
<Paper sx={{
|
||||||
|
flex: 1, p: 3, bgcolor: '#052e16', border: '1px solid #14532d', borderRadius: 2
|
||||||
|
}}>
|
||||||
|
<Typography variant="body2" sx={{ color: '#94a3b8', mb: 1 }}>Audited</Typography>
|
||||||
|
<Typography variant="h4" sx={{ color: '#22c55e', fontWeight: 'bold' }}>
|
||||||
|
{loading ? '...' : stats.audited.toLocaleString()}
|
||||||
|
</Typography>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
{/* Pending */}
|
||||||
|
<Paper sx={{
|
||||||
|
flex: 1, p: 3, bgcolor: '#422006', border: '1px solid #713f12', borderRadius: 2
|
||||||
|
}}>
|
||||||
|
<Typography variant="body2" sx={{ color: '#94a3b8', mb: 1 }}>Pending</Typography>
|
||||||
|
<Typography variant="h4" sx={{ color: '#eab308', fontWeight: 'bold' }}>
|
||||||
|
{loading ? '...' : stats.pending.toLocaleString()}
|
||||||
|
</Typography>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
{/* Anomalies Found */}
|
||||||
|
<Paper sx={{
|
||||||
|
flex: 1, p: 3, bgcolor: '#450a0a', border: '1px solid #7f1d1d', borderRadius: 2
|
||||||
|
}}>
|
||||||
|
<Typography variant="body2" sx={{ color: '#94a3b8', mb: 1 }}>Anomalies Found</Typography>
|
||||||
|
<Typography variant="h4" sx={{ color: '#ef4444', fontWeight: 'bold' }}>
|
||||||
|
{loading ? '...' : stats.anomaliesFound.toLocaleString()}
|
||||||
|
</Typography>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Overall Progress */}
|
||||||
|
<Paper sx={{ p: 3, bgcolor: '#0f172a', border: '1px solid #1e293b', borderRadius: 2, mb: 3 }}>
|
||||||
|
<Box sx={{ display: 'flex', justifyContent: 'space-between', mb: 1 }}>
|
||||||
|
<Typography variant="subtitle2" sx={{ fontWeight: 'bold', color: '#f8fafc' }}>Overall Progress</Typography>
|
||||||
|
<Typography variant="body2" sx={{ color: '#94a3b8' }}>{stats.audited} / {stats.total} completed</Typography>
|
||||||
|
</Box>
|
||||||
|
<LinearProgress
|
||||||
|
variant="determinate"
|
||||||
|
value={progressPercent}
|
||||||
|
sx={{
|
||||||
|
height: 10,
|
||||||
|
borderRadius: 5,
|
||||||
|
bgcolor: '#1e293b',
|
||||||
|
'& .MuiLinearProgress-bar': { bgcolor: '#3b82f6', borderRadius: 5 }
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Box sx={{ display: 'flex', justifyContent: 'space-between', mt: 1 }}>
|
||||||
|
<Typography variant="caption" sx={{ color: '#64748b' }}>{progressPercent}% complete</Typography>
|
||||||
|
<Typography variant="caption" sx={{ color: '#64748b' }}>~{Math.ceil(stats.pending / 50)} sessions remaining at 50/session</Typography>
|
||||||
|
</Box>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
{/* Next Session Info */}
|
||||||
|
<Paper sx={{ p: 2, px: 3, bgcolor: '#0f172a', border: '1px solid #1e293b', borderRadius: 2, mb: 2 }}>
|
||||||
|
<Typography variant="body1" sx={{ color: '#f8fafc' }}>
|
||||||
|
<Typography component="span" sx={{ color: '#3b82f6', fontWeight: 'bold' }}>Next session:</Typography> 50 items will be queued ({stats.pending} pending total)
|
||||||
|
</Typography>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
{/* Warning Box */}
|
||||||
|
<Paper sx={{ p: 2, px: 3, bgcolor: '#450a0a', border: '1px solid #7f1d1d', borderRadius: 2, mb: 4, display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||||
|
<WarningAmberIcon sx={{ color: '#ef4444', fontSize: 20 }} />
|
||||||
|
<Typography variant="body1" sx={{ color: '#f8fafc' }}>
|
||||||
|
<Typography component="span" sx={{ color: '#ef4444', fontWeight: 'bold' }}>181 high-priority items</Typography> will appear first in the queue
|
||||||
|
</Typography>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
{/* Start Button */}
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
fullWidth
|
||||||
|
onClick={() => navigate('/audit-session')}
|
||||||
|
sx={{
|
||||||
|
py: 2,
|
||||||
|
bgcolor: '#3b82f6',
|
||||||
|
'&:hover': { bgcolor: '#2563eb' },
|
||||||
|
textTransform: 'none',
|
||||||
|
fontSize: '1.1rem',
|
||||||
|
fontWeight: 'bold',
|
||||||
|
borderRadius: 2
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Start Session — Audit Next 50 Items
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{/* Footer links */}
|
||||||
|
<Box sx={{ display: 'flex', justifyContent: 'space-between', mt: 2 }}>
|
||||||
|
<Typography variant="caption" sx={{ color: '#475569' }}>Keyboard shortcuts available inside the audit view</Typography>
|
||||||
|
<Typography variant="caption" sx={{ color: '#64748b', textDecoration: 'underline', cursor: 'pointer', '&:hover': { color: '#f8fafc' } }}>Reset demo data</Typography>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
50
src/store/authStore.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { create } from 'zustand';
|
||||||
|
import { persist } from 'zustand/middleware';
|
||||||
|
import { useFeedStore } from './feedStore';
|
||||||
|
|
||||||
|
export interface User {
|
||||||
|
token: string;
|
||||||
|
access_token: string;
|
||||||
|
email: string;
|
||||||
|
username: string;
|
||||||
|
user_roles: string;
|
||||||
|
db_name?: string;
|
||||||
|
org_id?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AuthState {
|
||||||
|
user: User | null;
|
||||||
|
isAuthenticated: boolean;
|
||||||
|
login: (user: User) => void;
|
||||||
|
logout: () => void;
|
||||||
|
hasRole: (role: string) => boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useAuthStore = create<AuthState>()(
|
||||||
|
persist(
|
||||||
|
(set, get) => ({
|
||||||
|
user: null,
|
||||||
|
isAuthenticated: false,
|
||||||
|
login: (user) => {
|
||||||
|
useFeedStore.getState().resetStore();
|
||||||
|
set({ user, isAuthenticated: true });
|
||||||
|
},
|
||||||
|
logout: () => {
|
||||||
|
useFeedStore.getState().resetStore();
|
||||||
|
set({ user: null, isAuthenticated: false });
|
||||||
|
},
|
||||||
|
hasRole: (requiredRole: string) => {
|
||||||
|
const { user } = get();
|
||||||
|
if (!user || !user.user_roles) return false;
|
||||||
|
|
||||||
|
const userRoles = user.user_roles.split(',').map(r => r.trim().toLowerCase());
|
||||||
|
const neededRoles = requiredRole.split(',').map(r => r.trim().toLowerCase());
|
||||||
|
|
||||||
|
return neededRoles.some(role => userRoles.includes(role));
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
name: 'auth-storage', // saves to localStorage by default
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
138
src/store/feedStore.ts
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
import { create } from 'zustand';
|
||||||
|
|
||||||
|
export interface FeedTab {
|
||||||
|
date: string;
|
||||||
|
isRectificationTab: boolean;
|
||||||
|
totalAnomalyCount: number;
|
||||||
|
anomalies: any[];
|
||||||
|
anomaliesCopy: any[];
|
||||||
|
selectedAnomalyIndex: number;
|
||||||
|
filters: any;
|
||||||
|
page: number;
|
||||||
|
rowsPerPage: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tracks what filter params were last used to fetch dashboard stats
|
||||||
|
interface DashboardCache {
|
||||||
|
siteId: string;
|
||||||
|
auditStatus: string;
|
||||||
|
fromDate: string;
|
||||||
|
tillDate: string;
|
||||||
|
assetIds: string;
|
||||||
|
minChainage: string;
|
||||||
|
maxChainage: string;
|
||||||
|
stats: {
|
||||||
|
total: number;
|
||||||
|
audited: number;
|
||||||
|
pending: number;
|
||||||
|
anomaliesFound: number;
|
||||||
|
} | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FeedState {
|
||||||
|
tabs: FeedTab[];
|
||||||
|
selectedTabIndex: number;
|
||||||
|
assets: any[];
|
||||||
|
assetTypes: any[];
|
||||||
|
filterFromDate: string;
|
||||||
|
filterTillDate: string;
|
||||||
|
filterMinChainage: string;
|
||||||
|
filterMaxChainage: string;
|
||||||
|
selectedAssetIds: number[];
|
||||||
|
sites: any[];
|
||||||
|
auditStatus: string;
|
||||||
|
selectedSite: any;
|
||||||
|
isFiltersModalOpen: boolean;
|
||||||
|
isInitialized: boolean;
|
||||||
|
// Cache: last filter key used for the second GlobalFeed effect
|
||||||
|
lastFetchedFilterKey: string;
|
||||||
|
// Dashboard stats cache
|
||||||
|
dashboardCache: DashboardCache;
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
setTabs: (tabs: FeedTab[]) => void;
|
||||||
|
setSelectedTabIndex: (index: number) => void;
|
||||||
|
setAssets: (assets: any[]) => void;
|
||||||
|
setAssetTypes: (assetTypes: any[]) => void;
|
||||||
|
setSelectedAssetIds: (ids: number[]) => void;
|
||||||
|
setSites: (sites: any[]) => void;
|
||||||
|
setSelectedSite: (site: any) => void;
|
||||||
|
setAuditStatus: (status: string) => void;
|
||||||
|
setIsFiltersModalOpen: (isOpen: boolean) => void;
|
||||||
|
setIsInitialized: (val: boolean) => void;
|
||||||
|
setLastFetchedFilterKey: (key: string) => void;
|
||||||
|
setDashboardCache: (cache: DashboardCache) => void;
|
||||||
|
addTab: (tab: FeedTab) => void;
|
||||||
|
closeTab: (index: number) => void;
|
||||||
|
updateTab: (index: number, partialTab: Partial<FeedTab>) => void;
|
||||||
|
setFilterFromDate: (date: string) => void;
|
||||||
|
setFilterTillDate: (date: string) => void;
|
||||||
|
setFilterMinChainage: (val: string) => void;
|
||||||
|
setFilterMaxChainage: (val: string) => void;
|
||||||
|
resetStore: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EMPTY_DASHBOARD_CACHE: DashboardCache = {
|
||||||
|
siteId: '__unset__',
|
||||||
|
auditStatus: '__unset__',
|
||||||
|
fromDate: '__unset__',
|
||||||
|
tillDate: '__unset__',
|
||||||
|
assetIds: '__unset__',
|
||||||
|
minChainage: '__unset__',
|
||||||
|
maxChainage: '__unset__',
|
||||||
|
stats: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const initialFeedState = {
|
||||||
|
tabs: [],
|
||||||
|
selectedTabIndex: -1,
|
||||||
|
assets: [],
|
||||||
|
assetTypes: [],
|
||||||
|
filterFromDate: '',
|
||||||
|
filterTillDate: '',
|
||||||
|
filterMinChainage: '',
|
||||||
|
filterMaxChainage: '',
|
||||||
|
selectedAssetIds: [],
|
||||||
|
selectedSite: null,
|
||||||
|
sites: [],
|
||||||
|
auditStatus: 'Auto Audits',
|
||||||
|
isFiltersModalOpen: false,
|
||||||
|
isInitialized: false,
|
||||||
|
lastFetchedFilterKey: '',
|
||||||
|
dashboardCache: EMPTY_DASHBOARD_CACHE,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useFeedStore = create<FeedState>((set) => ({
|
||||||
|
...initialFeedState,
|
||||||
|
|
||||||
|
resetStore: () => set(initialFeedState),
|
||||||
|
|
||||||
|
setTabs: (tabs) => set({ tabs }),
|
||||||
|
setSelectedTabIndex: (index) => set({ selectedTabIndex: index }),
|
||||||
|
setAssets: (assets) => set({ assets }),
|
||||||
|
setAssetTypes: (assetTypes) => set({ assetTypes }),
|
||||||
|
setSelectedAssetIds: (selectedAssetIds) => set({ selectedAssetIds }),
|
||||||
|
setSites: (sites) => set({ sites }),
|
||||||
|
setSelectedSite: (selectedSite) => set({ selectedSite }),
|
||||||
|
setAuditStatus: (auditStatus) => set({ auditStatus }),
|
||||||
|
setIsFiltersModalOpen: (isFiltersModalOpen) => set({ isFiltersModalOpen }),
|
||||||
|
setIsInitialized: (isInitialized) => set({ isInitialized }),
|
||||||
|
setLastFetchedFilterKey: (lastFetchedFilterKey) => set({ lastFetchedFilterKey }),
|
||||||
|
setDashboardCache: (dashboardCache) => set({ dashboardCache }),
|
||||||
|
setFilterFromDate: (filterFromDate) => set({ filterFromDate }),
|
||||||
|
setFilterTillDate: (filterTillDate) => set({ filterTillDate }),
|
||||||
|
setFilterMinChainage: (filterMinChainage) => set({ filterMinChainage }),
|
||||||
|
setFilterMaxChainage: (filterMaxChainage) => set({ filterMaxChainage }),
|
||||||
|
addTab: (tab) => set((state) => ({ tabs: [...state.tabs, tab], selectedTabIndex: state.tabs.length })),
|
||||||
|
closeTab: (index) => set((state) => {
|
||||||
|
const newTabs = [...state.tabs];
|
||||||
|
newTabs.splice(index, 1);
|
||||||
|
const newIndex = state.selectedTabIndex >= newTabs.length ? newTabs.length - 1 : state.selectedTabIndex;
|
||||||
|
return { tabs: newTabs, selectedTabIndex: newIndex };
|
||||||
|
}),
|
||||||
|
updateTab: (index, partialTab) => set((state) => {
|
||||||
|
const newTabs = [...state.tabs];
|
||||||
|
newTabs[index] = { ...newTabs[index], ...partialTab };
|
||||||
|
return { tabs: newTabs };
|
||||||
|
})
|
||||||
|
}));
|
||||||
25
tsconfig.app.json
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||||
|
"target": "es2023",
|
||||||
|
"lib": ["ES2023", "DOM"],
|
||||||
|
"module": "esnext",
|
||||||
|
"types": ["vite/client"],
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"erasableSyntaxOnly": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
||||||
7
tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
24
tsconfig.node.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||||
|
"target": "es2023",
|
||||||
|
"lib": ["ES2023"],
|
||||||
|
"module": "esnext",
|
||||||
|
"types": ["node"],
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"erasableSyntaxOnly": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
|
},
|
||||||
|
"include": ["vite.config.ts"]
|
||||||
|
}
|
||||||
21
vite.config.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import react from '@vitejs/plugin-react'
|
||||||
|
|
||||||
|
// https://vite.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react()],
|
||||||
|
server: {
|
||||||
|
proxy: {
|
||||||
|
'/api/dashboard': {
|
||||||
|
target: 'https://sr-backend-api.takeleap.in',
|
||||||
|
changeOrigin: true,
|
||||||
|
rewrite: (path) => path.replace(/^\/api\/dashboard/, ''),
|
||||||
|
},
|
||||||
|
'/api/audit': {
|
||||||
|
target: 'https://sr-audit.takeleap.in',
|
||||||
|
changeOrigin: true,
|
||||||
|
rewrite: (path) => path.replace(/^\/api\/audit/, ''),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||