ptechcore_ui 1.0.25 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -249,6 +249,7 @@ interface Vendor {
249
249
  interface SessionContextType {
250
250
  isAuthenticated: boolean;
251
251
  token: string | null;
252
+ setToken: (token: string | null) => void;
252
253
  activeBusinessEntity: Entity | null;
253
254
  setActiveBusinessEntity: (entity: Entity | null) => void;
254
255
  loggedUser: User | null;
@@ -852,17 +853,437 @@ interface FileManagerContextValue {
852
853
  allowMultiSelect: boolean;
853
854
  texts: Required<FileManagerTexts>;
854
855
  }
856
+ /**
857
+ * Types d'entités supportées par la GED.
858
+ *
859
+ * Chaque type correspond à un modèle Django backend :
860
+ * - CLIENT → accounting.models.Client
861
+ * - VENDOR → accounting.models.Vendor
862
+ * - RFQ → procurement.models.RFQ
863
+ * - DEPT → core.models.Departments
864
+ * - PROJECT → core.models.Project
865
+ *
866
+ * POUR AJOUTER UN NOUVEAU TYPE :
867
+ * 1. Ajouter le type ici
868
+ * 2. Mettre à jour ENTITY_MODEL_MAP dans fileManagerApi.ts
869
+ * 3. Mettre à jour getRootName dans EntityFileManager.tsx
870
+ */
871
+ type EntityType = 'CLIENT' | 'VENDOR' | 'RFQ' | 'DEPT' | 'PROJECT';
872
+ /**
873
+ * Structure d'un dossier retourné par l'API backend.
874
+ * Correspond au FolderTreeSerializer Django.
875
+ */
876
+ interface BackendFolder {
877
+ id: number;
878
+ code: string;
879
+ name: string;
880
+ folder_type: string;
881
+ folder_type_display: string;
882
+ category_type?: string;
883
+ is_system_folder: boolean;
884
+ file_count: number;
885
+ total_size?: number;
886
+ children?: BackendFolder[];
887
+ files?: BackendFile[];
888
+ }
889
+ /**
890
+ * Structure d'un fichier retourné par l'API backend.
891
+ * Correspond au FileListSerializer Django.
892
+ */
893
+ interface BackendFile {
894
+ id: number;
895
+ code: string;
896
+ name: string;
897
+ file_url: string;
898
+ size: number;
899
+ mime_type: string;
900
+ extension: string;
901
+ folder: number;
902
+ folder_name?: string;
903
+ created_at: string;
904
+ updated_at?: string;
905
+ created_by?: string;
906
+ }
907
+ /**
908
+ * Props pour le composant EntityFileManager.
909
+ *
910
+ * Ce composant est un wrapper qui intègre FileManager avec l'API backend GED.
911
+ * Il charge automatiquement les dossiers de l'entité et gère les opérations CRUD.
912
+ *
913
+ * EXEMPLE D'UTILISATION :
914
+ * ```tsx
915
+ * <EntityFileManager
916
+ * entityType="VENDOR"
917
+ * entityId={vendor.id}
918
+ * businessEntityId={businessEntity.id}
919
+ * onFileSelect={(files) => console.log('Sélection:', files)}
920
+ * />
921
+ * ```
922
+ */
923
+ interface EntityFileManagerProps {
924
+ /** Type d'entité (CLIENT, VENDOR, RFQ, DEPT, PROJECT) */
925
+ entityType: EntityType;
926
+ /** ID de l'entité */
927
+ entityId: number | string;
928
+ /** ID du BusinessEntity (pour le contexte) */
929
+ businessEntityId: number | string;
930
+ /** Classes CSS additionnelles */
931
+ className?: string;
932
+ /** Hauteur du composant (défaut: '600px') */
933
+ height?: string;
934
+ /** Autoriser l'upload de fichiers (défaut: true) */
935
+ allowUpload?: boolean;
936
+ /** Autoriser la création de dossiers (défaut: true) */
937
+ allowCreateFolder?: boolean;
938
+ /** Autoriser le renommage (défaut: true) */
939
+ allowRename?: boolean;
940
+ /** Autoriser la suppression (défaut: true) */
941
+ allowDelete?: boolean;
942
+ /** Autoriser le téléchargement (défaut: true) */
943
+ allowDownload?: boolean;
944
+ /** Appelé quand l'utilisateur sélectionne des fichiers */
945
+ onFileSelect?: (files: FileItem[]) => void;
946
+ /** Appelé quand l'utilisateur ouvre un fichier */
947
+ onFileOpen?: (file: FileItem) => void;
948
+ /** Appelé après un upload réussi */
949
+ onUploadSuccess?: (files: FileItem[]) => void;
950
+ /** Appelé en cas d'erreur */
951
+ onError?: (error: Error) => void;
952
+ }
953
+ /**
954
+ * Valeur retournée par le hook useFileManagerApi.
955
+ */
956
+ interface UseFileManagerApiReturn {
957
+ /** Données transformées pour FileManager */
958
+ data: FileItem[];
959
+ /** État de chargement */
960
+ loading: boolean;
961
+ /** Erreur éventuelle */
962
+ error: Error | null;
963
+ /** Code du dossier racine de l'entité */
964
+ rootFolderCode: string | null;
965
+ /** Rafraîchir les données */
966
+ refresh: () => Promise<void>;
967
+ /** Handlers pour FileManager */
968
+ handlers: {
969
+ onCreateFolder: (name: string, parentId: string) => Promise<FileItem | void>;
970
+ onUploadFiles: (files: File[], parentId: string) => Promise<FileItem[] | void>;
971
+ onRename: (item: FileItem, newName: string) => Promise<void>;
972
+ onDelete: (item: FileItem) => Promise<void>;
973
+ onDownload: (item: FileItem) => void;
974
+ };
975
+ }
855
976
 
856
977
  declare const FileManager: React$1.FC<FileManagerProps>;
857
978
 
979
+ /**
980
+ * EntityFileManager - FileManager scopé à une entité métier.
981
+ *
982
+ * Ce composant encapsule le FileManager générique et l'intègre avec l'API
983
+ * backend GED pour afficher les documents d'une entité spécifique
984
+ * (Client, Vendor, RFQ, Département, Projet).
985
+ *
986
+ * FONCTIONNALITÉS :
987
+ * =================
988
+ * - Charge automatiquement les dossiers de l'entité au montage
989
+ * - Navigation limitée au dossier racine de l'entité (scopé)
990
+ * - Gestion des états loading/error/empty
991
+ * - Opérations CRUD complètes (upload, création, renommage, suppression)
992
+ * - Permissions configurables
993
+ *
994
+ * ARCHITECTURE :
995
+ * ==============
996
+ * EntityFileManager
997
+ * └── useFileManagerApi (hook)
998
+ * └── fileManagerApi (service)
999
+ * └── API Backend Django
1000
+ *
1001
+ * EXEMPLE D'UTILISATION :
1002
+ * =======================
1003
+ * ```tsx
1004
+ * // Dans la vue d'un Vendor
1005
+ * <EntityFileManager
1006
+ * entityType="VENDOR"
1007
+ * entityId={vendor.id}
1008
+ * businessEntityId={businessEntity.id}
1009
+ * />
1010
+ *
1011
+ * // Avec permissions limitées (lecture seule)
1012
+ * <EntityFileManager
1013
+ * entityType="CLIENT"
1014
+ * entityId={client.id}
1015
+ * businessEntityId={businessEntity.id}
1016
+ * allowUpload={false}
1017
+ * allowCreateFolder={false}
1018
+ * allowRename={false}
1019
+ * allowDelete={false}
1020
+ * />
1021
+ *
1022
+ * // Avec callbacks personnalisés
1023
+ * <EntityFileManager
1024
+ * entityType="RFQ"
1025
+ * entityId={rfq.id}
1026
+ * businessEntityId={businessEntity.id}
1027
+ * onFileSelect={(files) => console.log('Sélection:', files)}
1028
+ * onFileOpen={(file) => openPreview(file)}
1029
+ * />
1030
+ * ```
1031
+ */
1032
+
1033
+ /**
1034
+ * FileManager scopé à une entité métier.
1035
+ *
1036
+ * Ce composant charge automatiquement les dossiers de l'entité et fournit
1037
+ * une interface complète pour la gestion des documents.
1038
+ */
1039
+ declare const EntityFileManager: React$1.FC<EntityFileManagerProps>;
1040
+
858
1041
  declare const useFileManager: () => FileManagerContextValue;
859
1042
  interface FileManagerProviderProps extends FileManagerProps {
860
1043
  children: React$1.ReactNode;
861
1044
  }
862
1045
  declare const FileManagerProvider: React$1.FC<FileManagerProviderProps>;
863
1046
 
1047
+ /**
1048
+ * Hook pour intégrer le FileManager avec l'API backend GED.
1049
+ *
1050
+ * Ce hook gère :
1051
+ * - Le chargement des données depuis l'API
1052
+ * - La transformation des données backend → frontend
1053
+ * - Les opérations CRUD (création, renommage, suppression, upload)
1054
+ * - Le rafraîchissement des données après mutation
1055
+ *
1056
+ * ARCHITECTURE :
1057
+ * ==============
1058
+ * 1. Chargement initial :
1059
+ * - Récupère les dossiers de l'entité via /folders/for_entity/
1060
+ * - Trouve le dossier ENTITY (racine de l'entité)
1061
+ * - Charge l'arborescence complète via /folders/{code}/tree/
1062
+ *
1063
+ * 2. Transformation :
1064
+ * - Convertit BackendFolder/BackendFile → FileItem
1065
+ * - Construit les chemins (path) récursivement
1066
+ * - Aplatit la structure pour le FileManager
1067
+ *
1068
+ * 3. Mutations :
1069
+ * - Chaque mutation rafraîchit les données après succès
1070
+ * - Les erreurs sont capturées et exposées via l'état error
1071
+ *
1072
+ * EXEMPLE D'UTILISATION :
1073
+ * =======================
1074
+ * ```tsx
1075
+ * const { data, loading, error, handlers } = useFileManagerApi(
1076
+ * 'VENDOR',
1077
+ * vendor.id,
1078
+ * businessEntity.id
1079
+ * );
1080
+ *
1081
+ * if (loading) return <Spinner />;
1082
+ * if (error) return <Error message={error.message} />;
1083
+ *
1084
+ * return (
1085
+ * <FileManager
1086
+ * data={data}
1087
+ * onCreateFolder={handlers.onCreateFolder}
1088
+ * onUploadFiles={handlers.onUploadFiles}
1089
+ * ...
1090
+ * />
1091
+ * );
1092
+ * ```
1093
+ */
1094
+
1095
+ /**
1096
+ * Hook pour gérer l'intégration FileManager avec l'API GED.
1097
+ *
1098
+ * @param entityType - Type d'entité (CLIENT, VENDOR, RFQ, DEPT, PROJECT)
1099
+ * @param entityId - ID de l'entité
1100
+ * @param businessEntityId - ID du BusinessEntity
1101
+ * @returns État et handlers pour le FileManager
1102
+ */
1103
+ declare function useFileManagerApi(entityType: EntityType, entityId: string | number, businessEntityId: string | number): UseFileManagerApiReturn;
1104
+
1105
+ /**
1106
+ * Service API pour la GED (Gestion Électronique de Documents).
1107
+ *
1108
+ * Ce service gère toutes les communications avec le backend Django files_manager.
1109
+ *
1110
+ * ENDPOINTS UTILISÉS :
1111
+ * ====================
1112
+ * - GET /api/files_manager/folders/for_entity/?model=...&id=... → Dossiers d'une entité
1113
+ * - GET /api/files_manager/folders/{code}/tree/ → Arborescence d'un dossier
1114
+ * - GET /api/files_manager/folders/{code}/ → Détails d'un dossier
1115
+ * - POST /api/files_manager/folders/ → Créer un dossier
1116
+ * - PUT /api/files_manager/folders/{code}/ → Modifier un dossier
1117
+ * - DELETE /api/files_manager/folders/{code}/ → Supprimer un dossier
1118
+ * - GET /api/files_manager/files/ → Liste des fichiers
1119
+ * - POST /api/files_manager/files/ → Upload un fichier
1120
+ * - PUT /api/files_manager/files/{code}/ → Modifier un fichier
1121
+ * - DELETE /api/files_manager/files/{code}/ → Supprimer un fichier
1122
+ *
1123
+ * POUR AJOUTER UN NOUVEAU TYPE D'ENTITÉ :
1124
+ * =======================================
1125
+ * 1. Ajouter le type dans EntityType (types.ts)
1126
+ * 2. Ajouter le mapping dans ENTITY_MODEL_MAP ci-dessous
1127
+ */
1128
+
1129
+ /**
1130
+ * Récupère les dossiers d'une entité.
1131
+ *
1132
+ * Utilise l'endpoint /folders/for_entity/ pour récupérer tous les dossiers
1133
+ * associés à une entité spécifique (Client, Vendor, RFQ, etc.).
1134
+ *
1135
+ * @param entityType - Type d'entité (CLIENT, VENDOR, etc.)
1136
+ * @param entityId - ID de l'entité
1137
+ * @param folderType - Optionnel: filtrer par type de dossier
1138
+ * @returns Liste des dossiers
1139
+ *
1140
+ * @example
1141
+ * const folders = await fileManagerApi.getEntityFolders('VENDOR', 123);
1142
+ */
1143
+ declare function getEntityFolders(entityType: EntityType, entityId: string | number, folderType?: string): Promise<BackendFolder[]>;
1144
+ /**
1145
+ * Récupère l'arborescence complète d'un dossier.
1146
+ *
1147
+ * Retourne le dossier avec tous ses sous-dossiers et fichiers
1148
+ * de manière récursive.
1149
+ *
1150
+ * @param folderCode - Code du dossier (ex: 'FO000001')
1151
+ * @returns Structure hiérarchique du dossier
1152
+ *
1153
+ * @example
1154
+ * const tree = await fileManagerApi.getFolderTree('FO000001');
1155
+ */
1156
+ declare function getFolderTree(folderCode: string): Promise<BackendFolder>;
1157
+ /**
1158
+ * Récupère les détails d'un dossier.
1159
+ *
1160
+ * @param folderCode - Code du dossier
1161
+ * @returns Détails du dossier
1162
+ */
1163
+ declare function getFolder(folderCode: string): Promise<BackendFolder>;
1164
+ /**
1165
+ * Crée un nouveau dossier.
1166
+ *
1167
+ * @param name - Nom du dossier
1168
+ * @param parentCode - Code du dossier parent
1169
+ * @param businessEntityId - ID du BusinessEntity
1170
+ * @returns Dossier créé
1171
+ *
1172
+ * @example
1173
+ * const folder = await fileManagerApi.createFolder('Mon dossier', 'FO000001', 1);
1174
+ */
1175
+ declare function createFolder(name: string, parentCode: string, businessEntityId: string | number): Promise<BackendFolder>;
1176
+ /**
1177
+ * Renomme un dossier.
1178
+ *
1179
+ * @param folderCode - Code du dossier
1180
+ * @param newName - Nouveau nom
1181
+ * @returns Dossier mis à jour
1182
+ */
1183
+ declare function renameFolder(folderCode: string, newName: string): Promise<BackendFolder>;
1184
+ /**
1185
+ * Supprime un dossier.
1186
+ *
1187
+ * Note: Un dossier système (is_system_folder=true) ne peut pas être supprimé.
1188
+ *
1189
+ * @param folderCode - Code du dossier à supprimer
1190
+ */
1191
+ declare function deleteFolder(folderCode: string): Promise<void>;
1192
+ /**
1193
+ * Récupère les fichiers d'un dossier.
1194
+ *
1195
+ * @param folderId - ID du dossier
1196
+ * @returns Liste des fichiers
1197
+ */
1198
+ declare function getFolderFiles(folderId: number | string): Promise<BackendFile[]>;
1199
+ /**
1200
+ * Upload un fichier dans un dossier.
1201
+ *
1202
+ * @param file - Fichier à uploader
1203
+ * @param folderCode - Code du dossier de destination
1204
+ * @param options - Options additionnelles (nom, description, tags)
1205
+ * @returns Fichier créé
1206
+ *
1207
+ * @example
1208
+ * const uploadedFile = await fileManagerApi.uploadFile(
1209
+ * file,
1210
+ * 'FO000001',
1211
+ * { name: 'Mon document.pdf', description: 'Contrat 2024' }
1212
+ * );
1213
+ */
1214
+ declare function uploadFile(file: File, folderCode: string, options?: {
1215
+ name?: string;
1216
+ description?: string;
1217
+ tags?: string[];
1218
+ }): Promise<BackendFile>;
1219
+ /**
1220
+ * Upload plusieurs fichiers dans un dossier.
1221
+ *
1222
+ * @param files - Fichiers à uploader
1223
+ * @param folderCode - Code du dossier de destination
1224
+ * @returns Liste des fichiers créés
1225
+ */
1226
+ declare function uploadFiles(files: File[], folderCode: string): Promise<BackendFile[]>;
1227
+ /**
1228
+ * Renomme un fichier.
1229
+ *
1230
+ * @param fileCode - Code du fichier
1231
+ * @param newName - Nouveau nom
1232
+ * @returns Fichier mis à jour
1233
+ */
1234
+ declare function renameFile(fileCode: string, newName: string): Promise<BackendFile>;
1235
+ /**
1236
+ * Supprime un fichier.
1237
+ *
1238
+ * @param fileCode - Code du fichier à supprimer
1239
+ */
1240
+ declare function deleteFile(fileCode: string): Promise<void>;
1241
+ /**
1242
+ * Construit l'URL de téléchargement d'un fichier.
1243
+ *
1244
+ * @param fileCode - Code du fichier
1245
+ * @returns URL de téléchargement
1246
+ */
1247
+ declare function getDownloadUrl(fileCode: string): string;
1248
+ /**
1249
+ * Construit l'URL directe d'un fichier.
1250
+ *
1251
+ * @param fileUrl - URL relative du fichier depuis l'API
1252
+ * @returns URL complète
1253
+ */
1254
+ declare function getFileUrl(fileUrl: string): string;
1255
+ /**
1256
+ * Service API pour la GED.
1257
+ *
1258
+ * @example
1259
+ * // Récupérer les dossiers d'un vendor
1260
+ * const folders = await fileManagerApi.getEntityFolders('VENDOR', vendorId);
1261
+ *
1262
+ * // Récupérer l'arborescence
1263
+ * const tree = await fileManagerApi.getFolderTree(folders[0].code);
1264
+ *
1265
+ * // Uploader un fichier
1266
+ * const file = await fileManagerApi.uploadFile(myFile, 'FO000001');
1267
+ */
1268
+ declare const fileManagerApi: {
1269
+ getEntityFolders: typeof getEntityFolders;
1270
+ getFolderTree: typeof getFolderTree;
1271
+ getFolder: typeof getFolder;
1272
+ createFolder: typeof createFolder;
1273
+ renameFolder: typeof renameFolder;
1274
+ deleteFolder: typeof deleteFolder;
1275
+ getFolderFiles: typeof getFolderFiles;
1276
+ uploadFile: typeof uploadFile;
1277
+ uploadFiles: typeof uploadFiles;
1278
+ renameFile: typeof renameFile;
1279
+ deleteFile: typeof deleteFile;
1280
+ getDownloadUrl: typeof getDownloadUrl;
1281
+ getFileUrl: typeof getFileUrl;
1282
+ ENTITY_MODEL_MAP: Record<EntityType, string>;
1283
+ };
1284
+
864
1285
  declare const getFileIcon: (mimeType?: string, isFolder?: boolean, isOpen?: boolean) => LucideIcon;
865
1286
  declare const formatFileSize: (bytes?: number) => string;
866
1287
  declare const formatDate: (date?: Date | string) => string;
867
1288
 
868
- export { Alert, AlertProvider, ApprovalAnswerModal, ApprovalAnswerPage, ApprovalPreviewAnswer, ApprovalServices, ApprovalWorkflow, AuthServices, CHOICES, type ConfirmOptions, CountrySelector, DateInput, FDrawer, FetchApi, FileInput, type FileItem, FileManager, type FileManagerProps, FileManagerProvider, type FileManagerTexts, ForeignCurrencySelector, InputField, InvoiceTypeSelector, LegalFormSelector, type MenuItem, Modal, NumberInput, Pages, PaymentMethodSelector, PrimaryButton, RewiseLayout, SecondaryButton, SelectCostCenter, SelectDepartment, SelectInput, SelectUser, SelectVendor, SessionProvider, TaxSelector, TemplateFNESelector, TextInput, ThemeProvider, ToastContainer, ToastProvider, type User, UserServices, type ViewMode, formatDate, formatFileSize, getFileIcon, useAlert, useFileManager, useSession, useToast };
1289
+ export { Alert, AlertProvider, ApprovalAnswerModal, ApprovalAnswerPage, ApprovalPreviewAnswer, ApprovalServices, ApprovalWorkflow, AuthServices, type BackendFile, type BackendFolder, CHOICES, type ConfirmOptions, CountrySelector, DateInput, EntityFileManager, type EntityFileManagerProps, type EntityType, FDrawer, FetchApi, FileInput, type FileItem, FileManager, type FileManagerProps, FileManagerProvider, type FileManagerTexts, ForeignCurrencySelector, InputField, InvoiceTypeSelector, LegalFormSelector, type MenuItem, Modal, NumberInput, Pages, PaymentMethodSelector, PrimaryButton, RewiseLayout, SecondaryButton, SelectCostCenter, SelectDepartment, SelectInput, SelectUser, SelectVendor, SessionProvider, TaxSelector, TemplateFNESelector, TextInput, ThemeProvider, ToastContainer, ToastProvider, type UseFileManagerApiReturn, type User, UserServices, type ViewMode, fileManagerApi, formatDate, formatFileSize, getFileIcon, useAlert, useFileManager, useFileManagerApi, useSession, useToast };