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 || '',
|
||||
city: initialData.city || '',
|
||||
country: initialData.country || '',
|
||||
idDocument: initialData.idDocument || '',
|
||||
idDocument: initialData.idDocument || null,
|
||||
idCertified: false,
|
||||
});
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const { name, value } = e.target;
|
||||
const { name, type, files, value } = e.target;
|
||||
|
||||
if (type === 'file' && files) {
|
||||
// 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) => {
|
||||
@ -157,12 +168,10 @@ function ProfileModal({ isOpen, onClose, onSubmit, initialData = {} }: ProfileMo
|
||||
<div className="form-field">
|
||||
<label htmlFor="idDocument">Document d'identité <span className="optional">(optionnel)</span></label>
|
||||
<input
|
||||
type="text"
|
||||
type="file"
|
||||
id="idDocument"
|
||||
name="idDocument"
|
||||
value={profileData.idDocument || ''}
|
||||
onChange={handleChange}
|
||||
placeholder="Numéro de document"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { isFileBlob, type FileBlob } from "./Data";
|
||||
import type { RoleDefinition } from "./Roles";
|
||||
|
||||
export interface FolderData {
|
||||
@ -10,7 +11,7 @@ export interface FolderData {
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
customers: string[];
|
||||
documents: string[];
|
||||
documents: FileBlob[];
|
||||
motes: string[];
|
||||
stakeholders: string[];
|
||||
}
|
||||
@ -35,7 +36,6 @@ export function isFolderData(data: any): data is FolderData {
|
||||
|
||||
const requiredArrayFields = [
|
||||
'customers',
|
||||
'documents',
|
||||
'motes',
|
||||
'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;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
import type { FileBlob } from "./Data";
|
||||
import type { RoleDefinition } from "./Roles";
|
||||
|
||||
export interface ProfileData {
|
||||
name: string;
|
||||
surname: string;
|
||||
@ -7,11 +10,92 @@ export interface ProfileData {
|
||||
postalCode: string;
|
||||
city: 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 {
|
||||
processId: string,
|
||||
process: any, // Actually Process
|
||||
process: any, // Process
|
||||
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