@djangocfg/ui-tools 2.1.231 → 2.1.233
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/README.md +6 -0
- package/package.json +6 -6
- package/src/tools/Uploader/README.md +46 -0
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/ui-tools",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.233",
|
|
4
4
|
"description": "Heavy React tools with lazy loading - for Electron, Vite, CRA, Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui-tools",
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"check": "tsc --noEmit"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
|
-
"@djangocfg/i18n": "^2.1.
|
|
82
|
-
"@djangocfg/ui-core": "^2.1.
|
|
81
|
+
"@djangocfg/i18n": "^2.1.233",
|
|
82
|
+
"@djangocfg/ui-core": "^2.1.233",
|
|
83
83
|
"lucide-react": "^0.545.0",
|
|
84
84
|
"react": "^19.1.0",
|
|
85
85
|
"react-dom": "^19.1.0",
|
|
@@ -112,10 +112,10 @@
|
|
|
112
112
|
"@maplibre/maplibre-gl-geocoder": "^1.7.0"
|
|
113
113
|
},
|
|
114
114
|
"devDependencies": {
|
|
115
|
-
"@djangocfg/i18n": "^2.1.
|
|
115
|
+
"@djangocfg/i18n": "^2.1.233",
|
|
116
116
|
"@djangocfg/playground": "workspace:*",
|
|
117
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
118
|
-
"@djangocfg/ui-core": "^2.1.
|
|
117
|
+
"@djangocfg/typescript-config": "^2.1.233",
|
|
118
|
+
"@djangocfg/ui-core": "^2.1.233",
|
|
119
119
|
"@types/mapbox__mapbox-gl-draw": "^1.4.8",
|
|
120
120
|
"@types/node": "^24.7.2",
|
|
121
121
|
"@types/react": "^19.1.0",
|
|
@@ -74,6 +74,52 @@ function MyUploader() {
|
|
|
74
74
|
}
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
### With Generated API Client (recommended for DjangoCFG apps)
|
|
78
|
+
|
|
79
|
+
When your project has a generated API client (from `generate_client`), use `UploadDropzone` with `uploadFn` that calls the generated mutation hook. Auth tokens are handled automatically by the API client — no manual headers needed.
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
import { useCallback } from 'react';
|
|
83
|
+
import { UploadDropzone } from '@djangocfg/ui-tools/upload';
|
|
84
|
+
|
|
85
|
+
import { myApi } from '@/api/BaseClient';
|
|
86
|
+
import type { API } from '@/api/generated/my_app';
|
|
87
|
+
import { useCreateMyAppUploadCreate } from '@/api/generated/my_app/_utils/hooks';
|
|
88
|
+
|
|
89
|
+
const client = myApi as unknown as API;
|
|
90
|
+
|
|
91
|
+
function DocumentUploader({ projectSlug }: { projectSlug: string }) {
|
|
92
|
+
const uploadMutation = useCreateMyAppUploadCreate();
|
|
93
|
+
|
|
94
|
+
const handleUpload = useCallback(
|
|
95
|
+
async (files: File[]) => {
|
|
96
|
+
for (const file of files) {
|
|
97
|
+
// Pass typed object — generated client builds FormData automatically
|
|
98
|
+
await uploadMutation(projectSlug, { file, title: file.name }, client);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
[projectSlug, uploadMutation],
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<UploadDropzone
|
|
106
|
+
accept={['document']}
|
|
107
|
+
maxSizeMB={50}
|
|
108
|
+
multiple
|
|
109
|
+
uploadFn={handleUpload}
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Why this pattern?**
|
|
116
|
+
- Generated client builds `FormData` from typed object (`{ file, title }`) — no manual `formData.append()`
|
|
117
|
+
- Auth token managed by API client — no `headers` prop, no localStorage access
|
|
118
|
+
- Same auth flow as all other API calls in the app
|
|
119
|
+
- Type-safe — generated hooks match Django serializers
|
|
120
|
+
|
|
121
|
+
> **Important:** Don't pass raw `FormData` to generated hooks. Pass a typed object matching the generated request interface (e.g. `{ file: File, title: string }`). The generated client handles `FormData` construction internally.
|
|
122
|
+
|
|
77
123
|
### Custom Composition (with rpldy)
|
|
78
124
|
|
|
79
125
|
```tsx
|