Initial commit

This commit is contained in:
Anthony Janin 2025-06-05 09:40:35 +02:00
commit 2c329aa8a2
36 changed files with 6347 additions and 0 deletions

24
.gitignore vendored Normal file
View 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?

54
README.md Normal file
View File

@ -0,0 +1,54 @@
# 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 [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
## 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 tseslint.config({
extends: [
// 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,
],
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```
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 tseslint.config({
plugins: {
// Add the react-x and react-dom plugins
'react-x': reactX,
'react-dom': reactDom,
},
rules: {
// other rules...
// Enable its recommended typescript rules
...reactX.configs['recommended-typescript'].rules,
...reactDom.configs.recommended.rules,
},
})
```

28
eslint.config.js Normal file
View File

@ -0,0 +1,28 @@
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'
export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)

13
index.html Normal file
View File

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

2286
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

31
package.json Normal file
View File

@ -0,0 +1,31 @@
{
"name": "skeleton",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@types/uuid": "^10.0.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"uuid": "^11.1.0"
},
"devDependencies": {
"@eslint/js": "^9.25.0",
"@types/react": "^19.1.2",
"@types/react-dom": "^19.1.2",
"@vitejs/plugin-react": "^4.4.1",
"eslint": "^9.25.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
"typescript": "~5.8.3",
"typescript-eslint": "^8.30.1",
"vite": "^6.3.5"
}
}

1
public/vite.svg Normal file
View 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="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

1137
src/App.css Normal file

File diff suppressed because it is too large Load Diff

203
src/App.tsx Normal file
View File

@ -0,0 +1,203 @@
import { useState, useEffect, useCallback } from 'react'
import './App.css'
import MessageConsole from './components/MessageConsole'
import ControlPanel from './components/ControlPanel'
import ProfileModal from './components/ProfileModal'
import AuthModal from './sdk/AuthModal';
import MessageBus from './sdk/MessageBus';
import EventBus from './sdk/EventBus';
import UserStore from './sdk/UserStrore';
import Iframe from './sdk/Iframe'
import BlockchainViewer from './components/ProcessesViewer';
import FolderModal from './components/FolderModal';
import type { ProfileData } from './sdk/models/ProfileData'
import type { FolderData } from './sdk/models/FolderData'
const iframeUrl = 'https://dev3.4nkweb.com'
function App() {
const [receivedMessages, setReceivedMessages] = useState<{ timestamp: string; data: any }[]>([])
const [isConnected, setIsConnected] = useState(false)
const [showProfileModal, setShowProfileModal] = useState(false)
const [showAuthModal, setShowAuthModal] = useState(false)
const [showFolderModal, setShowFolderModal] = useState(false)
const [processes, setProcesses] = useState<any>(null)
useEffect(() => {
setIsConnected(UserStore.getInstance().isConnected());
});
useEffect(() => {
if (isConnected) {
const messageBus = MessageBus.getInstance(iframeUrl);
messageBus.isReady().then(() => {
messageBus.getProcesses().then((processes: any) => {
setProcesses(processes);
for (const key of Object.keys(processes)) {
try {
const process = processes[key];
if (Object.keys(process.states?.[0]?.keys).length === 0) {
continue;
}
console.log(key);
console.log(process);
} catch (error) {
console.error('Failed to retrieve data:', error);
}
}
messageBus.getData('467b005278cf516a42a54ba777fcbab29748072b52c01a988a596662e7b7844a:0', 'ada06b5c6e5add8a281b284a31a258355b33a9f0dbc4a5dcfe77dfd4eb904011').then((data: any) => {
console.log(data);
});
});
});
}
}, [isConnected, iframeUrl]);
// Gestionnaire pour afficher la modale de connexion
const handleLogin = useCallback(() => {
// Afficher la modale de connexion
setShowAuthModal(true);
}, []);
// Gestionnaire pour la déconnexion
const handleLogout = useCallback(() => {
// Déconnecter l'utilisateur
UserStore.getInstance().disconnect();
setIsConnected(false);
// Émettre un événement pour vider aussi les messages locaux dans MessageConsole
EventBus.getInstance().emit('CLEAR_CONSOLE');
// Vider les processes
setProcesses(null);
}, []);
// Gestionnaire pour ouvrir la modale de profil
const handleOpenProfileModal = useCallback(() => {
setShowProfileModal(true);
}, []);
// Gestionnaire pour ouvrir la modale de création de dossier
const handleOpenFolderModal = useCallback(() => {
setShowFolderModal(true);
}, []);
// Gestionnaire pour fermer la modale de création de dossier
const handleCloseFolderModal = useCallback(() => {
setShowFolderModal(false);
}, []);
// Gestionnaire pour fermer la modale de création de profil
const handleCloseProfileModal = useCallback(() => {
setShowProfileModal(false);
}, []);
// Gestionnaire pour soumettre les données du profil
const handleProfileSubmit = useCallback((profileData: ProfileData) => {
// Ajouter le validator fixe aux données du profil
const completeProfileData = {
...profileData,
validator: '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'
};
MessageBus.getInstance(iframeUrl).createProfile(completeProfileData).then((_profileData: ProfileData) => {
MessageBus.getInstance(iframeUrl).getProcesses().then((processes: any) => {
setProcesses(processes);
});
});
setShowProfileModal(false);
}, []);
// Gestionnaire pour soumettre les données du dossier
const handleFolderSubmit = useCallback((folderData: FolderData) => {
MessageBus.getInstance(iframeUrl).createFolder(folderData).then((_folderData: FolderData) => {
MessageBus.getInstance(iframeUrl).getProcesses().then((processes: any) => {
setProcesses(processes);
});
});
setShowFolderModal(false);
}, []);
// Gestionnaire du clic sur le bouton Vider les messages
const handleClearMessages = useCallback(() => {
setReceivedMessages([]);
}, []);
return (
<div className="home-container">
<header className="home-header">
<h1>[4NK]</h1>
</header>
<main className="home-main">
<div className="welcome-section">
{/* Panneau de contrôle avec iframe */}
<ControlPanel
isConnected={isConnected}
onLogin={handleLogin}
onLogout={handleLogout}
onCreateProfile={handleOpenProfileModal}
onCreateFolder={handleOpenFolderModal}
/>
{/* Structure flexible avec console à gauche et contenu à droite */}
<div className="app-content-layout">
{/* Console de messages (largeur fixe à gauche) */}
<MessageConsole
messages={receivedMessages}
onClearMessages={handleClearMessages}
/>
{/* Espace pour contenu supplémentaire à droite */}
<div className="content-area">
{/* Affichage des blocs de la blockchain */}
<BlockchainViewer processes={processes} />
</div>
</div>
{/* Modales */}
{showAuthModal && (
<AuthModal
isOpen={showAuthModal}
onConnect={() => {
setIsConnected(true);
setShowAuthModal(false);
}}
onClose={() => setShowAuthModal(false)}
iframeUrl={iframeUrl}
/>
)}
{showProfileModal && (
<ProfileModal
isOpen={showProfileModal}
onClose={handleCloseProfileModal}
onSubmit={handleProfileSubmit}
/>
)}
{showFolderModal && (
<FolderModal
isOpen={showFolderModal}
onClose={handleCloseFolderModal}
onSave={handleFolderSubmit}
onCancel={handleCloseFolderModal}
/>
)}
{/* N'afficher l'iframe que si l'utilisateur est connecté */}
{isConnected && <Iframe iframeUrl={iframeUrl} />}
</div>
</main>
</div>
)
}
export default App

1
src/assets/react.svg Normal file
View 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

View File

@ -0,0 +1,81 @@
import { memo, useState } from 'react';
interface ControlPanelProps {
onLogin?: () => void;
onLogout?: () => void;
onCreateProfile?: () => void;
onCreateFolder?: () => void;
isConnected?: boolean;
iframeUrl?: string;
}
/**
* Composant de panel de contrôle pour gérer les actions principales
*
* Fournit des boutons pour la connexion, la création de profil et le contrôle de visibilité
*/
function ControlPanel({
onLogin = () => console.log('Connexion demandée'),
onLogout = () => console.log('Déconnexion demandée'),
onCreateProfile = () => console.log('Création de profil demandée'),
onCreateFolder = () => console.log('Création de dossier demandée'),
isConnected = false,
iframeUrl = 'https://dev1.4nkweb.com'
}: ControlPanelProps) {
// État pour gérer l'affichage du tooltip
const [showTooltip, setShowTooltip] = useState(false);
return (
<div className="control-panel-container">
<div className="control-panel-row">
{/* Bouton d'information avec tooltip */}
<div className="url-tooltip-container button-container">
<button
className="info-button"
onMouseEnter={() => setShowTooltip(true)}
onMouseLeave={() => setShowTooltip(false)}
onClick={() => setShowTooltip(!showTooltip)}
>
💻
</button>
{showTooltip && (
<div className="url-tooltip">
{iframeUrl}
</div>
)}
</div>
{/* Boutons de contrôle */}
<div className="button-container">
<button
className={`control-button ${isConnected ? 'logout-button' : ''}`}
onClick={isConnected ? onLogout : onLogin}
>
{isConnected ? 'Se déconnecter' : 'Se connecter'}
</button>
</div>
<div className="button-container">
<button
className={`control-button ${!(isConnected) ? 'disabled' : ''}`}
onClick={onCreateProfile}
disabled={!(isConnected)}
>
Créer profil
</button>
</div>
<div className="button-container">
<button
className={`control-button ${!(isConnected) ? 'disabled' : ''}`}
onClick={onCreateFolder}
disabled={!(isConnected)}
>
Créer dossier
</button>
</div>
</div>
</div>
);
};
ControlPanel.displayName = 'ControlPanel';
export default memo(ControlPanel);

View File

@ -0,0 +1,294 @@
/* Styles pour le composant FolderModal */
.folder-container {
padding: 0;
width: 100%;
max-width: 900px;
margin: 0 auto;
}
.folder-form {
display: flex;
flex-direction: column;
gap: 1.5rem;
width: 100%;
}
.form-section {
background-color: rgba(255, 255, 255, 0.05);
border-radius: 0.5rem;
padding: 1.25rem;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease;
}
.form-section:hover {
background-color: rgba(255, 255, 255, 0.08);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.section-title {
margin: 0 0 1rem 0;
padding-bottom: 0.75rem;
font-size: 1rem;
font-weight: 600;
color: var(--primary-color);
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
letter-spacing: 0.5px;
text-transform: uppercase;
}
.form-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
width: 100%;
}
.form-field {
display: flex;
flex-direction: column;
margin-bottom: 1rem;
position: relative;
}
.form-field:last-child {
margin-bottom: 0;
}
.form-field label {
margin-bottom: 0.5rem;
font-size: 0.9rem;
font-weight: 500;
color: var(--text-100);
display: flex;
align-items: center;
}
.required {
color: #f44336;
margin-left: 0.25rem;
}
.optional {
color: #90a4ae;
font-size: 0.8rem;
font-weight: 400;
font-style: italic;
}
.form-field input,
.form-field select,
.form-field textarea {
background-color: rgba(255, 255, 255, 0.08);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 0.375rem;
padding: 0.75rem 1rem;
font-size: 0.95rem;
color: var(--text-100);
transition: all 0.3s ease;
width: 100%;
}
.form-field textarea {
resize: vertical;
min-height: 80px;
font-family: inherit;
}
.form-field select {
appearance: none;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='rgba(255, 255, 255, 0.6)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
background-position: right 1rem center;
background-repeat: no-repeat;
padding-right: 2.5rem;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
outline: none;
border-color: var(--primary-color);
background-color: rgba(255, 255, 255, 0.12);
box-shadow: 0 0 0 3px rgba(103, 58, 183, 0.25);
}
.form-field input::placeholder,
.form-field textarea::placeholder {
color: rgba(255, 255, 255, 0.3);
font-style: italic;
}
.form-field input:disabled,
.form-field select:disabled,
.form-field textarea:disabled {
opacity: 0.7;
cursor: not-allowed;
}
/* Tags styling */
.tag-list {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
margin-bottom: 1rem;
}
.tag-item {
background-color: rgba(103, 58, 183, 0.2);
color: var(--text-100);
border-radius: 0.25rem;
padding: 0.4rem 0.75rem;
font-size: 0.85rem;
display: flex;
align-items: center;
transition: all 0.2s ease;
}
.tag-item:hover {
background-color: rgba(103, 58, 183, 0.3);
}
.tag-remove {
background: none;
border: none;
color: var(--text-100);
margin-left: 0.5rem;
font-size: 1.2rem;
line-height: 0.8;
cursor: pointer;
padding: 0.1rem 0.3rem;
border-radius: 50%;
}
.tag-remove:hover {
background-color: rgba(255, 255, 255, 0.1);
color: #f44336;
}
.tag-input-container {
display: flex;
gap: 0.5rem;
}
.tag-input-container input {
flex: 1;
}
.btn-add-tag {
background: rgba(103, 58, 183, 0.3);
color: var(--text-100);
border: none;
border-radius: 0.375rem;
padding: 0 1rem;
font-size: 0.85rem;
cursor: pointer;
transition: all 0.2s ease;
}
.btn-add-tag:hover {
background: rgba(103, 58, 183, 0.5);
}
/* Form actions */
.form-actions {
display: flex;
justify-content: flex-end;
gap: 1rem;
margin-top: 1rem;
padding-top: 1.25rem;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.btn-cancel {
background: transparent;
color: var(--text-100);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 0.375rem;
padding: 0.75rem 1.5rem;
font-size: 0.9rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
}
.btn-cancel:hover {
background-color: rgba(255, 255, 255, 0.05);
border-color: rgba(255, 255, 255, 0.3);
}
.btn-submit {
background: var(--primary-color);
color: white;
border: none;
border-radius: 0.375rem;
padding: 0.75rem 2rem;
font-size: 0.9rem;
font-weight: 600;
cursor: pointer;
box-shadow: 0 2px 6px rgba(103, 58, 183, 0.3);
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.btn-submit::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.2), transparent);
transform: translateX(-100%);
transition: all 0.6s ease;
}
.btn-submit:hover {
background: var(--primary-color-dark);
box-shadow: 0 4px 10px rgba(103, 58, 183, 0.4);
transform: translateY(-2px);
}
.btn-submit:hover::before {
transform: translateX(100%);
}
.btn-submit:active {
transform: translateY(0);
box-shadow: 0 2px 4px rgba(103, 58, 183, 0.2);
}
/* Animation d'un folder qui vient d'être créé */
@keyframes highlight-new {
0% {
box-shadow: 0 0 0 2px rgba(103, 58, 183, 0.8);
}
100% {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
}
.folder-new {
animation: highlight-new 2s ease;
}
/* Styles adaptatifs pour les écrans plus petits */
@media (max-width: 768px) {
.form-row {
grid-template-columns: 1fr;
gap: 0.5rem;
}
.form-actions {
flex-direction: column;
}
.btn-cancel, .btn-submit {
width: 100%;
}
}
/* Styles spécifiques pour le composant FolderModal */
/* Les styles génériques de modal sont fournis par Modal.css */

View File

@ -0,0 +1,337 @@
import React, { useState, memo } from 'react';
import Modal from './modal/Modal';
import './FolderModal.css';
import type { FolderData } from '../sdk/models/FolderData';
interface FolderModalProps {
folder?: FolderData;
onSave?: (folderData: FolderData) => void;
onCancel?: () => void;
readOnly?: boolean;
isOpen: boolean;
onClose: () => void;
}
const defaultFolder: FolderData = {
folderNumber: '',
name: '',
deedType: '',
description: '',
archived_description: '',
status: 'active',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
customers: [],
documents: [],
motes: [],
stakeholders: []
};
function FolderModal({
folder = defaultFolder,
onSave,
onCancel,
readOnly = false,
isOpen,
onClose
}: FolderModalProps) {
const [folderData, setFolderData] = useState<FolderData>(folder);
const [currentCustomer, setCurrentCustomer] = useState<string>('');
const [currentStakeholder, setCurrentStakeholder] = useState<string>('');
if (!isOpen) return null;
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => {
const { name, value } = e.target;
setFolderData(prev => ({
...prev,
[name]: value
}));
};
const addCustomer = () => {
if (currentCustomer.trim() && !folderData.customers.includes(currentCustomer.trim())) {
setFolderData(prev => ({
...prev,
customers: [...prev.customers, currentCustomer.trim()]
}));
setCurrentCustomer('');
}
};
const removeCustomer = (customer: string) => {
setFolderData(prev => ({
...prev,
customers: prev.customers.filter(c => c !== customer)
}));
};
const addStakeholder = () => {
if (currentStakeholder.trim() && !folderData.stakeholders.includes(currentStakeholder.trim())) {
setFolderData(prev => ({
...prev,
stakeholders: [...prev.stakeholders, currentStakeholder.trim()]
}));
setCurrentStakeholder('');
}
};
const removeStakeholder = (stakeholder: string) => {
setFolderData(prev => ({
...prev,
stakeholders: prev.stakeholders.filter(s => s !== stakeholder)
}));
};
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (onSave) {
onSave({
...folderData,
updated_at: new Date().toISOString()
});
}
};
return (
<Modal isOpen={isOpen} onClose={onClose} title="Créer un nouveau dossier">
<div className="folder-container">
<form className="folder-form" onSubmit={handleSubmit}>
<div className="form-section">
<h3 className="section-title">Informations principales</h3>
<div className="form-row">
<div className="form-field">
<label>
Numéro de dossier <span className="required">*</span>
</label>
<input
type="text"
name="folderNumber"
value={folderData.folderNumber}
onChange={handleInputChange}
required
disabled={readOnly}
placeholder="ex: DOC-2025-001"
/>
</div>
<div className="form-field">
<label>
Nom <span className="required">*</span>
</label>
<input
type="text"
name="name"
value={folderData.name}
onChange={handleInputChange}
required
disabled={readOnly}
placeholder="Nom du dossier"
/>
</div>
</div>
<div className="form-row">
<div className="form-field">
<label>
Type d'acte <span className="required">*</span>
</label>
<select
name="deedType"
value={folderData.deedType}
onChange={handleInputChange}
required
disabled={readOnly}
>
<option value="">Sélectionnez le type d'acte</option>
<option value="vente">Vente</option>
<option value="achat">Achat</option>
<option value="succession">Succession</option>
<option value="donation">Donation</option>
<option value="autre">Autre</option>
</select>
</div>
<div className="form-field">
<label>
Statut <span className="required">*</span>
</label>
<select
name="status"
value={folderData.status}
onChange={handleInputChange}
required
disabled={readOnly}
>
<option value="active">Actif</option>
<option value="pending">En attente</option>
<option value="completed">Complété</option>
<option value="archived">Archivé</option>
</select>
</div>
</div>
<div className="form-field">
<label>Description</label>
<textarea
name="description"
value={folderData.description}
onChange={handleInputChange}
disabled={readOnly}
placeholder="Description du dossier"
rows={3}
/>
</div>
{folderData.status === 'archived' && (
<div className="form-field">
<label>Description d'archivage</label>
<textarea
name="archived_description"
value={folderData.archived_description}
onChange={handleInputChange}
disabled={readOnly}
placeholder="Raison d'archivage"
rows={2}
/>
</div>
)}
</div>
<div className="form-section">
<h3 className="section-title">Clients</h3>
<div className="tag-list">
{folderData.customers.map((customer, index) => (
<div key={index} className="tag-item">
<span>{customer}</span>
{!readOnly && (
<button
type="button"
className="tag-remove"
onClick={() => removeCustomer(customer)}
aria-label="Supprimer ce client"
>
×
</button>
)}
</div>
))}
</div>
{!readOnly && (
<div className="form-field tag-input-container">
<input
type="text"
value={currentCustomer}
onChange={(e) => setCurrentCustomer(e.target.value)}
placeholder="Ajouter un client"
/>
<button
type="button"
className="btn-add-tag"
onClick={addCustomer}
>
Ajouter
</button>
</div>
)}
</div>
<div className="form-section">
<h3 className="section-title">Parties prenantes</h3>
<div className="tag-list">
{folderData.stakeholders.map((stakeholder, index) => (
<div key={index} className="tag-item">
<span>{stakeholder}</span>
{!readOnly && (
<button
type="button"
className="tag-remove"
onClick={() => removeStakeholder(stakeholder)}
aria-label="Supprimer cette partie prenante"
>
×
</button>
)}
</div>
))}
</div>
{!readOnly && (
<div className="form-field tag-input-container">
<input
type="text"
value={currentStakeholder}
onChange={(e) => setCurrentStakeholder(e.target.value)}
placeholder="Ajouter une partie prenante"
/>
<button
type="button"
className="btn-add-tag"
onClick={addStakeholder}
>
Ajouter
</button>
</div>
)}
</div>
<div className="form-section">
<h3 className="section-title">Informations système</h3>
<div className="form-row">
<div className="form-field">
<label>Créé le</label>
<input
type="text"
value={new Date(folderData.created_at).toLocaleDateString('fr-FR', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit'
})}
disabled
readOnly
/>
</div>
<div className="form-field">
<label>Dernière mise à jour</label>
<input
type="text"
value={new Date(folderData.updated_at).toLocaleDateString('fr-FR', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit'
})}
disabled
readOnly
/>
</div>
</div>
</div>
<div className="form-actions">
{onCancel && (
<button
type="button"
className="btn-cancel"
onClick={onCancel}
>
Annuler
</button>
)}
<button
type="submit"
className="btn-submit"
>
Enregistrer
</button>
</div>
</form>
</div>
</Modal>
);
};
FolderModal.displayName = 'FolderModal';
export default memo(FolderModal);

View File

@ -0,0 +1,137 @@
import { memo, useRef, useEffect, useState } from 'react';
import EventBus from '../sdk/EventBus';
/**
* Formate une date ISO en format plus lisible et compact
*/
const formatTimestamp = (isoString: string): string => {
const date = new Date(isoString);
const now = new Date();
// Obtenir les composants de l'heure
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
const ms = String(date.getMilliseconds()).padStart(3, '0');
// Vérifier si c'est aujourd'hui
const isToday = date.getDate() === now.getDate() &&
date.getMonth() === now.getMonth() &&
date.getFullYear() === now.getFullYear();
if (isToday) {
// Format pour aujourd'hui: HH:MM:SS.ms
return `${hours}:${minutes}:${seconds}.${ms}`;
} else {
// Format pour les autres jours: JJ/MM HH:MM:SS
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0');
return `${day}/${month} ${hours}:${minutes}:${seconds}`;
}
};
interface MessageConsoleProps {
messages: {timestamp: string; data: any}[];
onClearMessages?: () => void;
}
/**
* Composant de console pour afficher des messages
*
* Affiche une liste de messages horodatés dans un panneau de console
* S'abonne automatiquement aux messages du EventBus
*/
function MessageConsole({
messages: externalMessages = [],
onClearMessages = () => console.log('Vidage des messages demandé')
}: MessageConsoleProps) {
// État local pour stocker les messages reçus via l'EventBus
const [localMessages, setLocalMessages] = useState<{timestamp: string; data: any}[]>([]);
// Tous les messages à afficher (externes + locaux), triés par timestamp
const allMessages = [...externalMessages, ...localMessages].sort((a, b) => {
return new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime();
});
// Gestionnaire de message reçu via EventBus
const handleMessageReceived = (message: any) => {
const newMessage = {
timestamp: new Date().toISOString(), // Conserver le format ISO pour le stockage
data: message
};
setLocalMessages(prev => [...prev, newMessage]);
};
// S'abonner aux événements
useEffect(() => {
const unsubscribeMessageReceived = EventBus.getInstance().on('MESSAGE_RECEIVED', handleMessageReceived);
// S'abonner à l'événement CLEAR_CONSOLE pour vider les messages locaux lors de la déconnexion
const unsubscribeClearConsole = EventBus.getInstance().on('CLEAR_CONSOLE', () => {
setLocalMessages([]);
});
// Se désabonner lors du nettoyage
return () => {
unsubscribeMessageReceived();
unsubscribeClearConsole();
};
}, []);
// Fonction pour vider les messages locaux et externes
const handleClearAll = () => {
setLocalMessages([]);
onClearMessages();
};
// Référence pour le conteneur de la console de messages
const consoleContentRef = useRef<HTMLDivElement>(null);
// Effet pour faire défiler automatiquement vers le bas quand de nouveaux messages arrivent
useEffect(() => {
if (consoleContentRef.current && allMessages.length > 0) {
consoleContentRef.current.scrollTop = consoleContentRef.current.scrollHeight;
}
}, [allMessages]);
return (
<div className="message-console-container">
<div className="console-panel">
<div className="console-header">
<h3>Console</h3>
<div className="console-controls">
<span className="message-count">{allMessages.length} message(s)</span>
<button
className="clear-console-button"
onClick={handleClearAll}
disabled={allMessages.length === 0}
title="Vider les messages"
>
🗑
</button>
</div>
</div>
<div className="console-content" ref={consoleContentRef}>
{allMessages.length === 0 ? (
<div className="no-messages">Aucun message reçu</div>
) : (
<ul className="message-list">
{allMessages.map((message, index) => (
<li key={index} className="message-item">
<div className="message-timestamp">{formatTimestamp(message.timestamp)}</div>
<pre className="message-data">
{typeof message.data === 'object'
? JSON.stringify(message.data, null, 2)
: String(message.data)}
</pre>
</li>
))}
</ul>
)}
</div>
</div>
</div>
);
};
MessageConsole.displayName = 'MessageConsole';
export default memo(MessageConsole);

View File

@ -0,0 +1,174 @@
.processes-viewer {
width: 100%;
height: 100%;
overflow-y: auto;
padding: 1rem;
color: var(--text-color);
scrollbar-width: thin;
scrollbar-color: var(--surface-400) var(--surface-200);
}
/* Styles pour les scrollbars dans Webkit (Chrome, Safari, etc.) */
.processes-viewer::-webkit-scrollbar {
width: 8px;
}
.processes-viewer::-webkit-scrollbar-track {
background: var(--surface-400);
}
.processes-viewer::-webkit-scrollbar-thumb {
background-color: var(--surface-200);
border-radius: 4px;
}
.processes-viewer::-webkit-scrollbar-thumb:hover {
background-color: var(--surface-300);
}
.processes-viewer h2 {
margin-bottom: 0.5rem;
color: var(--primary-color);
font-size: 1.5rem;
}
.processes-viewer-empty {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
color: var(--text-color-muted);
}
.block-count {
margin-bottom: 1rem;
color: var(--text-color-muted);
font-size: 0.9rem;
}
.block-list {
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.block-item {
background-color: rgba(255, 255, 255, 0.04);
border-radius: 8px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.1);
transition: all 0.3s ease;
}
.block-item:hover {
border-color: rgba(var(--primary-color-rgb), 0.4);
box-shadow: 0 0 10px rgba(var(--primary-color-rgb), 0.2);
}
.block-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.75rem 1rem;
cursor: pointer;
background-color: rgba(255, 255, 255, 0.02);
transition: background-color 0.3s ease;
user-select: none;
}
.block-header:hover {
background-color: rgba(var(--primary-color-rgb), 0.1);
}
.block-header.expanded {
background-color: rgba(var(--primary-color-rgb), 0.2);
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.block-id {
font-family: monospace;
font-weight: bold;
color: var(--primary-color);
}
.block-state-count {
color: var(--text-color-muted);
font-size: 0.85rem;
}
.block-toggle {
transition: transform 0.3s ease;
font-size: 0.85rem;
}
.block-header.expanded .block-toggle {
transform: rotate(0deg);
}
.block-details {
padding: 1rem;
background-color: rgba(0, 0, 0, 0.1);
border-radius: 0 0 8px 8px;
}
.block-complete-id {
font-family: monospace;
background-color: rgba(0, 0, 0, 0.2);
padding: 0.5rem;
border-radius: 4px;
margin-bottom: 1rem;
font-size: 0.85rem;
word-break: break-all;
}
.state-item {
margin-bottom: 1rem;
padding: 0.75rem;
background-color: rgba(255, 255, 255, 0.02);
border-radius: 6px;
border-left: 3px solid var(--primary-color);
}
.state-item h4 {
margin-top: 0;
color: var(--primary-color);
margin-bottom: 0.5rem;
}
.state-detail {
margin-bottom: 0.5rem;
font-size: 0.9rem;
}
.state-public-data {
margin-top: 0.75rem;
padding: 0.5rem;
background-color: rgba(0, 0, 0, 0.1);
border-radius: 4px;
}
.state-public-data h5 {
margin-top: 0;
margin-bottom: 0.5rem;
color: var(--text-color);
font-size: 0.9rem;
}
.public-data-item {
margin-bottom: 0.5rem;
font-size: 0.85rem;
}
.address-list {
margin: 0.25rem 0 0 0;
padding-left: 1rem;
list-style-type: none;
}
.address-list li {
font-family: monospace;
word-break: break-all;
margin-bottom: 0.25rem;
font-size: 0.8rem;
}

View File

@ -0,0 +1,162 @@
import { useState, memo } from 'react';
import './ProcessesViewer.css';
interface BlockState {
commited_in: string;
state_id: string;
public_data: {
memberPublicName?: string | number[];
pairedAddresses?: string[] | number[];
};
// Autres propriétés disponibles si nécessaires
}
interface Block {
states: BlockState[];
}
interface Processes {
[key: string]: Block;
}
interface ProcessesViewerProps {
processes: Processes | null;
}
function ProcessesViewer({ processes }: ProcessesViewerProps) {
const [expandedBlocks, setExpandedBlocks] = useState<string[]>([]);
// Si pas de données, afficher un message
if (!processes || Object.keys(processes).length === 0) {
return (
<div className="processes-viewer-empty">
<h3>Aucun processus disponible</h3>
<p>Connectez-vous</p>
</div>
);
}
const toggleBlock = (blockId: string) => {
setExpandedBlocks(prev =>
prev.includes(blockId)
? prev.filter(id => id !== blockId)
: [...prev, blockId]
);
};
const formatAddress = (address: string | number[] | undefined): string => {
if (!address) return "Adresse non disponible";
if (Array.isArray(address)) {
// Si c'est un tableau de nombres, on le convertit en chaîne de caractères
try {
// Convertir les codes ASCII en caractères
const chars = address.map(code => String.fromCharCode(Number(code)));
return chars.join('');
} catch (e) {
return "Adresse encodée (format non supporté)";
}
} else if (typeof address === 'string') {
// Si c'est déjà une chaîne, on la retourne telle quelle
return address;
}
return "Format d'adresse inconnu";
};
const formatName = (name: string | number[] | undefined): string => {
if (!name) return "Nom non disponible";
if (Array.isArray(name)) {
if (name.length === 1 && name[0] === 96) {
return "`"; // Caractère spécial
}
try {
const chars = name.map(code => String.fromCharCode(Number(code)));
return chars.join('');
} catch (e) {
return "Nom encodé (format non supporté)";
}
} else if (typeof name === 'string') {
return name;
}
return "Format de nom inconnu";
};
return (
<div className="processes-viewer">
<h2>Processus</h2>
<p className="block-count">{Object.keys(processes).length} processus disponible(s)</p>
<div className="block-list">
{Object.entries(processes).map(([blockId, block]) => {
const isExpanded = expandedBlocks.includes(blockId);
const stateCount = block.states.length;
// Le premier état est le plus récent
return (
<div key={blockId} className="block-item">
<div
className={`block-header ${isExpanded ? 'expanded' : ''}`}
onClick={() => toggleBlock(blockId)}
>
<div className="block-id">{blockId.substring(0, 8)}...{blockId.substring(blockId.length - 4)}</div>
<div className="block-state-count">{stateCount} état(s)</div>
<div className="block-toggle">{isExpanded ? '▼' : '▶'}</div>
</div>
{isExpanded && (
<div className="block-details">
<div className="block-complete-id">
<strong>ID complet:</strong> {blockId}
</div>
{block.states.map((state, index) => (
<div key={`${blockId}-state-${index}`} className="state-item">
<h4>État {index + 1}</h4>
<div className="state-detail">
<strong>State ID:</strong> {state.state_id}
</div>
<div className="state-detail">
<strong>Commited dans:</strong> {state.commited_in}
</div>
<div className="state-public-data">
<h5>Données publiques</h5>
<div className="public-data-item">
<strong>Nom:</strong> {formatName(state.public_data.memberPublicName)}
</div>
{state.public_data.pairedAddresses && (
<div className="public-data-item">
<strong>Adresses associées:</strong>
<ul className="address-list">
{Array.isArray(state.public_data.pairedAddresses) ?
(typeof state.public_data.pairedAddresses[0] === 'string' ? (
(state.public_data.pairedAddresses as string[]).map((addr, i) => (
<li key={i}>{addr}</li>
))
) : (
<li>{formatAddress(state.public_data.pairedAddresses as number[])}</li>
)) : (
<li>{String(state.public_data.pairedAddresses || '')}</li>
)
}
</ul>
</div>
)}
</div>
</div>
))}
</div>
)}
</div>
);
})}
</div>
</div>
);
};
ProcessesViewer.displayName = 'ProcessesViewer';
export default memo(ProcessesViewer);

View File

@ -0,0 +1,174 @@
/* Styles pour le formulaire de profil */
.profile-form-container {
padding: 0;
width: 100%;
}
.profile-form {
display: flex;
flex-direction: column;
gap: 1.5rem;
width: 100%;
}
.form-section {
background-color: rgba(255, 255, 255, 0.05);
border-radius: 0.5rem;
padding: 1.25rem;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease;
}
.form-section:hover {
background-color: rgba(255, 255, 255, 0.08);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.section-title {
margin: 0 0 1rem 0;
padding-bottom: 0.75rem;
font-size: 1rem;
font-weight: 600;
color: var(--primary-color);
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
letter-spacing: 0.5px;
text-transform: uppercase;
}
.form-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
width: 100%;
}
.form-field {
display: flex;
flex-direction: column;
margin-bottom: 1rem;
position: relative;
}
.form-field:last-child {
margin-bottom: 0;
}
.form-field label {
margin-bottom: 0.5rem;
font-size: 0.9rem;
font-weight: 500;
color: var(--text-100);
display: flex;
align-items: center;
}
.required {
color: #f44336;
margin-left: 0.25rem;
}
.optional {
color: #90a4ae;
font-size: 0.8rem;
font-weight: 400;
font-style: italic;
}
.form-field input {
background-color: rgba(255, 255, 255, 0.08);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 0.375rem;
padding: 0.75rem 1rem;
font-size: 0.95rem;
color: var(--text-100);
transition: all 0.3s ease;
}
.form-field input:focus {
outline: none;
border-color: var(--primary-color);
background-color: rgba(255, 255, 255, 0.12);
box-shadow: 0 0 0 3px rgba(103, 58, 183, 0.25);
}
.form-field input::placeholder {
color: rgba(255, 255, 255, 0.3);
font-style: italic;
}
.form-actions {
display: flex;
justify-content: flex-end;
gap: 1rem;
margin-top: 1rem;
padding-top: 1.25rem;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.btn-cancel {
background: transparent;
color: var(--text-100);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 0.375rem;
padding: 0.75rem 1.5rem;
font-size: 0.9rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
}
.btn-cancel:hover {
background-color: rgba(255, 255, 255, 0.05);
border-color: rgba(255, 255, 255, 0.3);
}
.btn-submit {
background: var(--primary-color);
color: white;
border: none;
border-radius: 0.375rem;
padding: 0.75rem 2rem;
font-size: 0.9rem;
font-weight: 600;
cursor: pointer;
box-shadow: 0 2px 6px rgba(103, 58, 183, 0.3);
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.btn-submit::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.2), transparent);
transform: translateX(-100%);
transition: all 0.6s ease;
}
.btn-submit:hover {
background: var(--primary-color-dark);
box-shadow: 0 4px 10px rgba(103, 58, 183, 0.4);
transform: translateY(-2px);
}
.btn-submit:hover::before {
transform: translateX(100%);
}
.btn-submit:active {
transform: translateY(0);
box-shadow: 0 2px 4px rgba(103, 58, 183, 0.2);
}
/* Styles adaptatifs pour les écrans plus petits */
@media (max-width: 768px) {
.form-row {
grid-template-columns: 1fr;
gap: 0.5rem;
}
}

View File

@ -0,0 +1,181 @@
import React, { useState, memo } from 'react';
import Modal from './modal/Modal';
import './ProfileModal.css';
import type { ProfileData } from '../sdk/models/ProfileData';
interface ProfileModalProps {
isOpen: boolean;
onClose: () => void;
onSubmit: (profileData: ProfileData) => void;
initialData?: Partial<ProfileData>;
}
function ProfileModal({ isOpen, onClose, onSubmit, initialData = {} }: ProfileModalProps) {
const [profileData, setProfileData] = useState<ProfileData>({
name: initialData.name || '',
surname: initialData.surname || '',
email: initialData.email || '',
phone: initialData.phone || '',
address: initialData.address || '',
postalCode: initialData.postalCode || '',
city: initialData.city || '',
country: initialData.country || '',
idDocument: initialData.idDocument || '',
});
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
setProfileData(prev => ({
...prev,
[name]: value
}));
};
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
onSubmit(profileData);
};
return (
<Modal isOpen={isOpen} onClose={onClose} title="Créer un profil">
<div className="profile-form-container">
<form onSubmit={handleSubmit} className="profile-form">
<div className="form-section">
<h3 className="section-title">Informations personnelles</h3>
<div className="form-row">
<div className="form-field">
<label htmlFor="surname">Prénom<span className="required">*</span></label>
<input
type="text"
id="surname"
name="surname"
value={profileData.surname}
onChange={handleChange}
placeholder="Votre prénom"
required
/>
</div>
<div className="form-field">
<label htmlFor="name">Nom<span className="required">*</span></label>
<input
type="text"
id="name"
name="name"
value={profileData.name}
onChange={handleChange}
placeholder="Votre nom"
required
/>
</div>
</div>
<div className="form-field">
<label htmlFor="email">Email<span className="required">*</span></label>
<input
type="email"
id="email"
name="email"
value={profileData.email}
onChange={handleChange}
placeholder="exemple@email.com"
required
/>
</div>
<div className="form-field">
<label htmlFor="phone">Téléphone<span className="required">*</span></label>
<input
type="tel"
id="phone"
name="phone"
value={profileData.phone}
onChange={handleChange}
placeholder="+33 6 12 34 56 78"
required
/>
</div>
</div>
<div className="form-section">
<h3 className="section-title">Adresse</h3>
<div className="form-field">
<label htmlFor="address">Adresse complète<span className="required">*</span></label>
<input
type="text"
id="address"
name="address"
value={profileData.address}
onChange={handleChange}
placeholder="123 rue de Paris"
required
/>
</div>
<div className="form-row">
<div className="form-field">
<label htmlFor="postalCode">Code postal<span className="required">*</span></label>
<input
type="text"
id="postalCode"
name="postalCode"
value={profileData.postalCode}
onChange={handleChange}
placeholder="75001"
required
/>
</div>
<div className="form-field">
<label htmlFor="city">Ville<span className="required">*</span></label>
<input
type="text"
id="city"
name="city"
value={profileData.city}
onChange={handleChange}
placeholder="Paris"
required
/>
</div>
</div>
<div className="form-field">
<label htmlFor="country">Pays<span className="required">*</span></label>
<input
type="text"
id="country"
name="country"
value={profileData.country}
onChange={handleChange}
placeholder="France"
required
/>
</div>
</div>
<div className="form-section">
<h3 className="section-title">Document</h3>
<div className="form-field">
<label htmlFor="idDocument">Document d'identité&nbsp;<span className="optional">(optionnel)</span></label>
<input
type="text"
id="idDocument"
name="idDocument"
value={profileData.idDocument || ''}
onChange={handleChange}
placeholder="Numéro de document"
/>
</div>
</div>
<div className="form-actions">
<button type="button" className="btn-cancel" onClick={onClose}>Annuler</button>
<button type="submit" className="btn-submit">Créer le profil</button>
</div>
</form>
</div>
</Modal>
);
};
ProfileModal.displayName = 'ProfileModal';
export default memo(ProfileModal);

View File

@ -0,0 +1,163 @@
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(35, 36, 42, 0.82);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
animation: modal-fadein 0.33s cubic-bezier(.4, 0, .2, 1);
backdrop-filter: blur(3.5px);
-webkit-backdrop-filter: blur(3.5px);
}
@keyframes modal-fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.modal-container {
background: #23242a;
border-radius: 18px;
min-width: 340px;
max-width: 95vw;
min-height: 0;
padding: 0 0 24px 0;
position: relative;
box-shadow: 0 12px 48px 0 rgba(0, 0, 0, 0.34), 0 2px 12px 0 rgba(30, 34, 44, 0.10);
overflow: hidden;
animation: modal-popin 0.34s cubic-bezier(.4, 0, .2, 1);
transition: box-shadow 0.2s, opacity 0.25s cubic-bezier(.4, 0, .2, 1);
}
.modal-container.modal-closing {
opacity: 0;
transform: translateY(32px) scale(0.97);
pointer-events: none;
}
@keyframes modal-popin {
from {
opacity: 0;
transform: translateY(32px) scale(0.97);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
.modal-header {
background: linear-gradient(90deg, #23242a 85%, #23242aEE 100%);
color: #fff;
padding: 22px 30px 14px 30px;
border-radius: 18px 18px 0 0;
box-shadow: 0 2px 12px 0 rgba(30, 34, 44, 0.06);
position: relative;
display: flex;
align-items: center;
min-height: 52px;
}
.modal-header h2 {
margin: 0;
font-size: 1.3rem;
font-weight: 600;
letter-spacing: 0.01em;
color: #fff;
}
.modal-close {
position: absolute;
top: 10px;
right: 16px;
background: transparent;
border: none;
font-size: 2rem;
color: #e3e4e8;
width: 36px;
height: 36px;
min-width: 36px;
min-height: 36px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: background 0.18s, color 0.18s;
z-index: 2;
border-radius: 6px;
padding: 0;
}
.modal-close svg {
display: block;
width: 24px;
height: 24px;
background: none;
pointer-events: none;
}
.modal-close:hover,
.modal-close:focus {
background: rgba(255, 255, 255, 0.10);
color: #fff;
}
.modal-close:active {
background: rgba(67, 160, 71, 0.13);
}
.modal-close:active {
background: rgba(67, 160, 71, 0.13);
}
.modal-body {
padding: 28px 28px 0 28px;
max-height: 70vh;
overflow-y: auto;
color: #e3e4e8;
font-size: 1rem;
}
@media (max-width: 600px) {
.modal-container {
min-width: 0;
width: 98vw;
padding: 0 0 12px 0;
border-radius: 12px;
}
.modal-header {
padding: 16px 10px 10px 14px;
border-radius: 12px 12px 0 0;
}
.modal-body {
padding: 14px 8px 0 8px;
}
.modal-close {
top: 6px;
right: 6px;
width: 30px;
height: 30px;
font-size: 1.2rem;
}
}
.modal-body {
width: 100%;
}

View File

@ -0,0 +1,38 @@
import React, { memo } from 'react';
import './Modal.css';
interface ModalProps {
isOpen: boolean;
onClose: () => void;
title?: string;
children: React.ReactNode;
}
function Modal({ isOpen, onClose, title, children }: ModalProps) {
if (!isOpen) {
return null;
}
return (
<div className="modal-overlay modal-fadein">
<div className="modal-container modal-popin">
<button className="close-button modal-close" onClick={onClose} aria-label="Fermer">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path d="M6 6L18 18M18 6L6 18" stroke="#fff" strokeWidth="2.4" strokeLinecap="round" filter="url(#shadow)" />
<defs>
<filter id="shadow" x="-2" y="-2" width="28" height="28" filterUnits="userSpaceOnUse">
<feDropShadow dx="0" dy="0" stdDeviation="1.2" floodColor="#23242a" />
</filter>
</defs>
</svg>
</button>
{title && <div className="modal-header modal-header"><h2>{title}</h2></div>}
<div className="modal-body modal-body">
{children}
</div>
</div>
</div>
);
}
Modal.displayName = 'Modal';
export default memo(Modal);

68
src/index.css Normal file
View File

@ -0,0 +1,68 @@
:root {
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}

10
src/main.tsx Normal file
View File

@ -0,0 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)

101
src/sdk/AuthModal.tsx Normal file
View File

@ -0,0 +1,101 @@
import { useState, useEffect, memo } from 'react';
import Iframe from './Iframe';
import MessageBus from './MessageBus';
import Loader from './Loader';
import Modal from '../components/modal/Modal';
interface AuthModalProps {
isOpen: boolean;
onConnect: () => void;
onClose: () => void;
iframeUrl: string;
}
function AuthModal({ isOpen, onConnect, onClose, iframeUrl }: AuthModalProps) {
const [isIframeReady, setIsIframeReady] = useState(false);
const [showIframe, setShowIframe] = useState(false);
const [authSuccess, setAuthSuccess] = useState(false);
useEffect(() => {
MessageBus.getInstance(iframeUrl).isReady().then(() => {
setIsIframeReady(true);
});
}, [iframeUrl]);
useEffect(() => {
if (!isOpen) {
setShowIframe(false);
setIsIframeReady(false);
setAuthSuccess(false);
}
}, [isOpen]);
useEffect(() => {
if (isIframeReady && !showIframe) {
setShowIframe(true);
MessageBus.getInstance(iframeUrl).requestLink().then(() => {
setAuthSuccess(true);
setTimeout(() => onConnect(), 500);
}).catch((_error: string) => {
setShowIframe(false);
setIsIframeReady(false);
setAuthSuccess(false);
onClose();
});
}
}, [isIframeReady, showIframe]);
return (
<Modal
isOpen={isOpen}
onClose={onClose}
title='Authentification 4nk'
>
{!isIframeReady && (
<div style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '400px',
gap: 16
}}>
<Loader width={40} />
<div style={{ fontWeight: 600, fontSize: 18 }}>Chargement de l'authentification...</div>
</div>
)}
{authSuccess ? (
<div style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '400px',
gap: 20
}}>
<div style={{ fontWeight: 600, fontSize: 18, color: '#43a047' }}>
Authentification réussie !
</div>
</div>
) : (
<div style={{
display: showIframe ? 'flex' : 'none',
justifyContent: 'center',
alignItems: 'center',
width: '100%'
}}>
<Iframe
iframeUrl={iframeUrl}
showIframe={showIframe}
/>
</div>
)}
</Modal>
);
}
AuthModal.displayName = 'AuthModal';
export default memo(AuthModal);

33
src/sdk/EventBus.ts Normal file
View File

@ -0,0 +1,33 @@
export default class EventBus {
private static instance: EventBus;
private listeners: Record<string, Array<(...args: any[]) => void>> = {};
private constructor() {}
public static getInstance(): EventBus {
if (!EventBus.instance) {
EventBus.instance = new EventBus();
}
return EventBus.instance;
}
public on(event: string, callback: (...args: any[]) => void): () => void {
if (!this.listeners[event]) {
this.listeners[event] = [];
}
this.listeners[event].push(callback);
return () => {
if (this.listeners[event]) {
this.listeners[event] = this.listeners[event].filter(cb => cb !== callback);
}
};
}
public emit(event: string, ...args: any[]): void {
if (this.listeners[event]) {
this.listeners[event].forEach(callback => {
callback(...args);
});
}
}
}

32
src/sdk/Iframe.tsx Normal file
View File

@ -0,0 +1,32 @@
import { useRef, useEffect, memo } from 'react';
import IframeReference from './IframeReference';
function Iframe({ iframeUrl, showIframe = false }: { iframeUrl: string; showIframe?: boolean }) {
const iframeRef = useRef<HTMLIFrameElement>(null);
useEffect(() => {
if (iframeRef.current) {
IframeReference.setIframe(iframeRef.current);
}
return () => {
IframeReference.setIframe(null);
};
}, [iframeRef.current]);
return (
<iframe
ref={iframeRef}
src={iframeUrl}
style={{
display: showIframe ? 'block' : 'none',
width: '400px',
height: '400px',
border: 'none',
overflow: 'hidden'
}}
/>
);
}
Iframe.displayName = 'Iframe';
export default memo(Iframe);

View File

@ -0,0 +1,13 @@
export default class IframeReference {
private static iframe: HTMLIFrameElement | null = null;
private constructor() { }
public static setIframe(iframe: HTMLIFrameElement | null): void {
this.iframe = iframe;
}
public static getIframe(): HTMLIFrameElement | null {
return this.iframe;
}
}

23
src/sdk/Loader.tsx Normal file
View File

@ -0,0 +1,23 @@
import { memo } from 'react';
function Loader({ width = 40 }: { width?: number }) {
return (
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', width: width }}>
<div
className='loader'
style={{
width,
height: width,
border: '4px solid #eee',
borderTop: '4px solid #333',
borderRadius: '50%',
animation: 'spin 1s linear infinite',
}}
/>
<style>{`@keyframes spin { 0% { transform: rotate(0deg);} 100% { transform: rotate(360deg);} }`}</style>
</div>
);
}
Loader.displayName = 'Loader';
export default memo(Loader);

422
src/sdk/MessageBus.ts Normal file
View File

@ -0,0 +1,422 @@
import IframeReference from './IframeReference';
import EventBus from './EventBus';
import UserStore from './UserStrore';
import type { ProfileData } from './models/ProfileData';
import type { FolderData } from './models/FolderData';
import { v4 as uuidv4 } from 'uuid';
export default class MessageBus {
private static instance: MessageBus;
private readonly origin: string;
private messageListener: ((event: MessageEvent) => void) | null = null;
private errors: { [key: string]: string } = {};
private constructor(origin: string) {
this.origin = origin;
}
public static getInstance(origin: string): MessageBus {
if (!MessageBus.instance) {
MessageBus.instance = new MessageBus(origin);
}
return MessageBus.instance;
}
public isReady(): Promise<void> {
return new Promise<void>((resolve: () => void) => {
const correlationId = uuidv4();
this.initMessageListener(correlationId);
const unsubscribe = EventBus.getInstance().on('IS_READY', (responseId: string) => {
if (responseId !== correlationId) {
return;
}
unsubscribe();
this.destroyMessageListener();
resolve();
});
});
}
public requestLink(): Promise<void> {
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => {
const correlationId = uuidv4();
this.initMessageListener(correlationId);
const unsubscribe = EventBus.getInstance().on('LINK_ACCEPTED', (responseId: string, accessToken: string, refreshToken: string) => {
if (responseId !== correlationId) {
return;
}
unsubscribe();
this.destroyMessageListener();
UserStore.getInstance().connect(accessToken, refreshToken);
resolve();
});
const unsubscribeError = EventBus.getInstance().on('ERROR_LINK_ACCEPTED', (responseId: string, error: string) => {
if (responseId !== correlationId) {
return;
}
unsubscribeError();
this.destroyMessageListener();
reject(error);
});
this.sendMessage({
type: 'REQUEST_LINK'
});
});
}
public validateToken(): Promise<boolean> {
return new Promise<boolean>((resolve: (isValid: boolean) => void, reject: (error: string) => void) => {
const userStore = UserStore.getInstance();
if (!userStore.isConnected()) {
reject('User is not connected');
return;
}
const accessToken = userStore.getAccessToken()!;
const refreshToken = userStore.getRefreshToken()!;
const correlationId = uuidv4();
this.initMessageListener(correlationId);
const unsubscribe = EventBus.getInstance().on('TOKEN_VALIDATED', (responseId: string, isValid: boolean) => {
if (responseId !== correlationId) {
return;
}
unsubscribe();
this.destroyMessageListener();
resolve(isValid);
});
const unsubscribeError = EventBus.getInstance().on('ERROR_TOKEN_VALIDATED', (responseId: string, error: string) => {
if (responseId !== correlationId) {
return;
}
unsubscribeError();
this.destroyMessageListener();
reject(error);
});
this.sendMessage({
type: 'VALIDATE_TOKEN',
accessToken,
refreshToken
});
});
}
public renewToken(): Promise<void> {
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => {
const userStore = UserStore.getInstance();
if (!userStore.isConnected()) {
reject('User is not connected');
return;
}
const refreshToken = userStore.getRefreshToken()!;
const correlationId = uuidv4();
this.initMessageListener(correlationId);
const unsubscribe = EventBus.getInstance().on('TOKEN_RENEWED', (responseId: string, accessToken: string, refreshToken: string) => {
if (responseId !== correlationId) {
return;
}
unsubscribe();
this.destroyMessageListener();
UserStore.getInstance().connect(accessToken, refreshToken);
resolve();
});
const unsubscribeError = EventBus.getInstance().on('ERROR_TOKEN_RENEWED', (responseId: string, error: string) => {
if (responseId !== correlationId) {
return;
}
unsubscribeError();
this.destroyMessageListener();
reject(error);
});
this.sendMessage({
type: 'RENEW_TOKEN',
refreshToken
});
});
}
public getProcesses(): Promise<any> {
return new Promise<any>((resolve: (processes: any) => void, reject: (error: string) => void) => {
this.checkToken().then(() => {
const correlationId = uuidv4();
this.initMessageListener(correlationId);
const unsubscribe = EventBus.getInstance().on('PROCESSES_RETRIEVED', (responseId: string, processes: any) => {
if (responseId !== correlationId) {
return;
}
unsubscribe();
this.destroyMessageListener();
resolve(processes);
});
const unsubscribeError = EventBus.getInstance().on('ERROR_PROCESSES_RETRIEVED', (responseId: string, error: string) => {
if (responseId !== correlationId) {
return;
}
unsubscribeError();
this.destroyMessageListener();
reject(error);
});
this.sendMessage({
type: 'GET_PROCESSES'
});
}).catch(console.error);
});
}
public getData(processId: string, stateId: string): Promise<any> {
return new Promise<any>((resolve: (data: any) => void, reject: (error: string) => void) => {
this.checkToken().then(() => {
const userStore = UserStore.getInstance();
const accessToken = userStore.getAccessToken()!;
const correlationId = uuidv4();
this.initMessageListener(correlationId);
const unsubscribe = EventBus.getInstance().on('DATA_RETRIEVED', (responseId: string, data: any) => {
if (responseId !== correlationId) {
return;
}
unsubscribe();
this.destroyMessageListener();
resolve(data);
});
const unsubscribeError = EventBus.getInstance().on('ERROR_DATA_RETRIEVED', (responseId: string, error: string) => {
if (responseId !== correlationId) {
return;
}
unsubscribeError();
this.destroyMessageListener();
reject(error);
});
this.sendMessage({
type: 'RETRIEVE_DATA',
processId,
stateId,
token: accessToken
});
}).catch(console.error);
});
}
public createProfile(profileData: ProfileData): Promise<ProfileData> {
return new Promise<ProfileData>((resolve: (profileData: ProfileData) => void, reject: (error: string) => void) => {
this.checkToken().then(() => {
const userStore = UserStore.getInstance();
const accessToken = userStore.getAccessToken()!;
const refreshToken = userStore.getRefreshToken()!;
const correlationId = uuidv4();
this.initMessageListener(correlationId);
const unsubscribe = EventBus.getInstance().on('PROFILE_CREATED', (responseId: string, profileData: ProfileData) => {
if (responseId !== correlationId) {
return;
}
unsubscribe();
this.destroyMessageListener();
resolve(profileData);
});
const unsubscribeError = EventBus.getInstance().on('ERROR_PROFILE_CREATED', (responseId: string, error: string) => {
if (responseId !== correlationId) {
return;
}
unsubscribeError();
this.destroyMessageListener();
reject(error);
});
this.sendMessage({
type: 'CREATE_PROFILE',
profileData,
accessToken,
refreshToken
});
}).catch(console.error);
});
}
public createFolder(folderData: FolderData): Promise<FolderData> {
return new Promise<FolderData>((resolve: (folderData: FolderData) => void, reject: (error: string) => void) => {
this.checkToken().then(() => {
const userStore = UserStore.getInstance();
const accessToken = userStore.getAccessToken()!;
const correlationId = uuidv4();
this.initMessageListener(correlationId);
const unsubscribe = EventBus.getInstance().on('FOLDER_CREATED', (responseId: string, folderData: FolderData) => {
if (responseId !== correlationId) {
return;
}
unsubscribe();
this.destroyMessageListener();
resolve(folderData);
});
const unsubscribeError = EventBus.getInstance().on('ERROR_FOLDER_CREATED', (responseId: string, error: string) => {
if (responseId !== correlationId) {
return;
}
unsubscribeError();
this.destroyMessageListener();
reject(error);
});
this.sendMessage({
type: 'CREATE_FOLDER',
folderData,
token: accessToken
});
}).catch(console.error);
});
}
private checkToken(): Promise<void> {
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => {
this.validateToken().then((isValid: boolean) => {
if (!isValid) {
this.renewToken().then(resolve).catch(reject);
} else {
resolve();
}
}).catch(reject);
});
}
private sendMessage(message: any): void {
const iframe = IframeReference.getIframe();
if (!iframe) {
console.error('[MessageBus] sendMessage: iframe not found');
return;
}
console.log('[MessageBus] sendMessage:', message);
iframe.contentWindow?.postMessage(message, this.origin);
}
private initMessageListener(correlationId: string): void {
this.destroyMessageListener();
this.messageListener = this.handleMessage.bind(this, correlationId);
window.addEventListener('message', this.messageListener);
}
private destroyMessageListener(): void {
if (this.messageListener) {
window.removeEventListener('message', this.messageListener);
this.messageListener = null;
}
}
private handleMessage(correlationId: string, event: MessageEvent): void {
if (event.origin !== this.origin) {
return;
}
if (!event.data || typeof event.data !== 'object') {
return;
}
const message = event.data;
switch (message.type) {
case 'LISTENING':
EventBus.getInstance().emit('IS_READY', correlationId);
break;
case 'LINK_ACCEPTED':
if (this.errors[correlationId]) {
const error = this.errors[correlationId];
delete this.errors[correlationId];
EventBus.getInstance().emit('ERROR_LINK_ACCEPTED', correlationId, error);
return;
}
EventBus.getInstance().emit('MESSAGE_RECEIVED', message);
EventBus.getInstance().emit('LINK_ACCEPTED', correlationId, message.accessToken, message.refreshToken);
break;
case 'VALIDATE_TOKEN':
if (this.errors[correlationId]) {
const error = this.errors[correlationId];
delete this.errors[correlationId];
EventBus.getInstance().emit('ERROR_TOKEN_VALIDATED', correlationId, error);
return;
}
EventBus.getInstance().emit('MESSAGE_RECEIVED', message);
EventBus.getInstance().emit('TOKEN_VALIDATED', correlationId, message.isValid);
break;
case 'RENEW_TOKEN':
if (this.errors[correlationId]) {
const error = this.errors[correlationId];
delete this.errors[correlationId];
EventBus.getInstance().emit('ERROR_TOKEN_RENEWED', correlationId, error);
return;
}
EventBus.getInstance().emit('MESSAGE_RECEIVED', message);
EventBus.getInstance().emit('TOKEN_RENEWED', correlationId, message.accessToken, message.refreshToken);
break;
case 'PROCESSES_RETRIEVED': // GET_PROCESSES
if (this.errors[correlationId]) {
const error = this.errors[correlationId];
delete this.errors[correlationId];
EventBus.getInstance().emit('ERROR_PROCESSES_RETRIEVED', correlationId, error);
return;
}
EventBus.getInstance().emit('PROCESSES_RETRIEVED', correlationId, message.processes);
break;
case 'PROFILE_CREATED': // CREATE_PROFILE
if (this.errors[correlationId]) {
const error = this.errors[correlationId];
delete this.errors[correlationId];
EventBus.getInstance().emit('ERROR_PROFILE_CREATED', correlationId, error);
return;
}
EventBus.getInstance().emit('MESSAGE_RECEIVED', message);
EventBus.getInstance().emit('PROFILE_CREATED', correlationId, message.profileData);
break;
case 'FOLDER_CREATED': // CREATE_FOLDER
if (this.errors[correlationId]) {
const error = this.errors[correlationId];
delete this.errors[correlationId];
EventBus.getInstance().emit('ERROR_FOLDER_CREATED', correlationId, error);
return;
}
EventBus.getInstance().emit('MESSAGE_RECEIVED', message);
break;
case 'DATA_RETRIEVED': // RETRIEVE_DATA
if (this.errors[correlationId]) {
const error = this.errors[correlationId];
delete this.errors[correlationId];
EventBus.getInstance().emit('ERROR_DATA_RETRIEVED', correlationId, error);
return;
}
EventBus.getInstance().emit('MESSAGE_RECEIVED', message);
EventBus.getInstance().emit('DATA_RETRIEVED', correlationId, message.data);
break;
case 'ERROR':
console.error('Error:', message);
this.errors[correlationId] = message.error;
break;
}
}
}

34
src/sdk/UserStrore.ts Normal file
View File

@ -0,0 +1,34 @@
export default class UserStore {
private static instance: UserStore;
private constructor() { }
public static getInstance(): UserStore {
if (!UserStore.instance) {
UserStore.instance = new UserStore();
}
return UserStore.instance;
}
public connect(accessToken: string, refreshToken: string): void {
sessionStorage.setItem('accessToken', accessToken);
sessionStorage.setItem('refreshToken', refreshToken);
}
public isConnected(): boolean {
return sessionStorage.getItem('accessToken') !== null && sessionStorage.getItem('refreshToken') !== null;
}
public disconnect(): void {
sessionStorage.removeItem('accessToken');
sessionStorage.removeItem('refreshToken');
}
public getAccessToken(): string | null {
return sessionStorage.getItem('accessToken');
}
public getRefreshToken(): string | null {
return sessionStorage.getItem('refreshToken');
}
}

View File

@ -0,0 +1,14 @@
export interface FolderData {
folderNumber: string;
name: string;
deedType: string;
description: string;
archived_description: string;
status: string;
created_at: string;
updated_at: string;
customers: string[];
documents: string[];
motes: string[];
stakeholders: string[];
}

View File

@ -0,0 +1,11 @@
export interface ProfileData {
name: string;
surname: string;
email: string;
phone: string;
address: string;
postalCode: string;
city: string;
country: string;
idDocument?: string;
}

1
src/vite-env.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="vite/client" />

27
tsconfig.app.json Normal file
View File

@ -0,0 +1,27 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}

7
tsconfig.json Normal file
View File

@ -0,0 +1,7 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}

25
tsconfig.node.json Normal file
View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}

7
vite.config.ts Normal file
View File

@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
})