Update Profile and Folder with FileBlob
This commit is contained in:
parent
f9f9739cbd
commit
24a8be727c
@ -20,15 +20,26 @@ function ProfileModal({ isOpen, onClose, onSubmit, initialData = {} }: ProfileMo
|
|||||||
postalCode: initialData.postalCode || '',
|
postalCode: initialData.postalCode || '',
|
||||||
city: initialData.city || '',
|
city: initialData.city || '',
|
||||||
country: initialData.country || '',
|
country: initialData.country || '',
|
||||||
idDocument: initialData.idDocument || '',
|
idDocument: initialData.idDocument || null,
|
||||||
|
idCertified: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const { name, value } = e.target;
|
const { name, type, files, value } = e.target;
|
||||||
setProfileData(prev => ({
|
|
||||||
...prev,
|
if (type === 'file' && files) {
|
||||||
[name]: value
|
// Assuming you want to handle a single file
|
||||||
}));
|
const file = files[0];
|
||||||
|
setProfileData(prev => ({
|
||||||
|
...prev,
|
||||||
|
[name]: file
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
setProfileData(prev => ({
|
||||||
|
...prev,
|
||||||
|
[name]: value
|
||||||
|
}));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent) => {
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
@ -157,12 +168,10 @@ function ProfileModal({ isOpen, onClose, onSubmit, initialData = {} }: ProfileMo
|
|||||||
<div className="form-field">
|
<div className="form-field">
|
||||||
<label htmlFor="idDocument">Document d'identité <span className="optional">(optionnel)</span></label>
|
<label htmlFor="idDocument">Document d'identité <span className="optional">(optionnel)</span></label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="file"
|
||||||
id="idDocument"
|
id="idDocument"
|
||||||
name="idDocument"
|
name="idDocument"
|
||||||
value={profileData.idDocument || ''}
|
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
placeholder="Numéro de document"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { isFileBlob, type FileBlob } from "./Data";
|
||||||
import type { RoleDefinition } from "./Roles";
|
import type { RoleDefinition } from "./Roles";
|
||||||
|
|
||||||
export interface FolderData {
|
export interface FolderData {
|
||||||
@ -10,7 +11,7 @@ export interface FolderData {
|
|||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
customers: string[];
|
customers: string[];
|
||||||
documents: string[];
|
documents: FileBlob[];
|
||||||
motes: string[];
|
motes: string[];
|
||||||
stakeholders: string[];
|
stakeholders: string[];
|
||||||
}
|
}
|
||||||
@ -35,7 +36,6 @@ export function isFolderData(data: any): data is FolderData {
|
|||||||
|
|
||||||
const requiredArrayFields = [
|
const requiredArrayFields = [
|
||||||
'customers',
|
'customers',
|
||||||
'documents',
|
|
||||||
'motes',
|
'motes',
|
||||||
'stakeholders'
|
'stakeholders'
|
||||||
];
|
];
|
||||||
@ -46,6 +46,15 @@ export function isFolderData(data: any): data is FolderData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const requiredFileBlobArrayFields = [
|
||||||
|
'documents',
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const field of requiredFileBlobArrayFields) {
|
||||||
|
if (!Array.isArray(data[field])) return false;
|
||||||
|
if (data[field].length > 0 && !data[field].every(isFileBlob)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import type { FileBlob } from "./Data";
|
||||||
|
import type { RoleDefinition } from "./Roles";
|
||||||
|
|
||||||
export interface ProfileData {
|
export interface ProfileData {
|
||||||
name: string;
|
name: string;
|
||||||
surname: string;
|
surname: string;
|
||||||
@ -7,11 +10,92 @@ export interface ProfileData {
|
|||||||
postalCode: string;
|
postalCode: string;
|
||||||
city: string;
|
city: string;
|
||||||
country: string;
|
country: string;
|
||||||
idDocument?: string;
|
idDocument: FileBlob | null;
|
||||||
|
idCertified: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isProfileData(data: any): data is ProfileData{
|
||||||
|
if (typeof data !== 'object' || data === null) return false;
|
||||||
|
|
||||||
|
const requiredStringFields = [
|
||||||
|
'folderNumber',
|
||||||
|
'name',
|
||||||
|
'deedType',
|
||||||
|
'description',
|
||||||
|
'archived_description',
|
||||||
|
'status',
|
||||||
|
'created_at',
|
||||||
|
'updated_at'
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const field of requiredStringFields) {
|
||||||
|
if (typeof data[field] !== 'string') return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const emptyProfileData: ProfileData = {
|
||||||
|
name: '',
|
||||||
|
surname: '',
|
||||||
|
email: '',
|
||||||
|
phone: '',
|
||||||
|
address: '',
|
||||||
|
postalCode: '',
|
||||||
|
city: '',
|
||||||
|
country: '',
|
||||||
|
idDocument: null,
|
||||||
|
idCertified: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
const profileDataFields: string[] = Object.keys(emptyProfileData);
|
||||||
|
|
||||||
|
const ProfilePublicFields: string[] = ['idCertified'];
|
||||||
|
|
||||||
|
export const ProfilePrivateFields = [
|
||||||
|
...profileDataFields.filter(key => !ProfilePublicFields.includes(key))
|
||||||
|
];
|
||||||
|
|
||||||
export interface ProfileCreated {
|
export interface ProfileCreated {
|
||||||
processId: string,
|
processId: string,
|
||||||
process: any, // Actually Process
|
process: any, // Process
|
||||||
profileData: ProfileData,
|
profileData: ProfileData,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setDefaultProfileRoles(ownerId: string[], validatorId: string): Record<string, RoleDefinition> {
|
||||||
|
return {
|
||||||
|
owner: {
|
||||||
|
members: ownerId,
|
||||||
|
validation_rules: [
|
||||||
|
{
|
||||||
|
quorum: 0.5,
|
||||||
|
fields: [...ProfilePrivateFields, 'roles'],
|
||||||
|
min_sig_member: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
storages: []
|
||||||
|
},
|
||||||
|
validator: {
|
||||||
|
members: [validatorId],
|
||||||
|
validation_rules: [
|
||||||
|
{
|
||||||
|
quorum: 0.5,
|
||||||
|
fields: ['idCertified', 'roles'],
|
||||||
|
min_sig_member: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
quorum: 0.0,
|
||||||
|
fields: [...profileDataFields],
|
||||||
|
min_sig_member: 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
storages: []
|
||||||
|
},
|
||||||
|
apophis: {
|
||||||
|
members: ownerId,
|
||||||
|
validation_rules: [],
|
||||||
|
storages: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user