🐛 Fixing other documents
This commit is contained in:
parent
9cb8a06849
commit
406a04bcfe
@ -39,6 +39,7 @@ type IState = {
|
|||||||
refusedReason?: string;
|
refusedReason?: string;
|
||||||
isShowRefusedReasonModalVisible: boolean;
|
isShowRefusedReasonModalVisible: boolean;
|
||||||
isAddDocumentModalVisible: boolean;
|
isAddDocumentModalVisible: boolean;
|
||||||
|
isLoading: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class DepositOtherDocument extends React.Component<IProps, IState> {
|
export default class DepositOtherDocument extends React.Component<IProps, IState> {
|
||||||
@ -54,6 +55,7 @@ export default class DepositOtherDocument extends React.Component<IProps, IState
|
|||||||
isDragOver: false,
|
isDragOver: false,
|
||||||
refusedReason: "",
|
refusedReason: "",
|
||||||
isShowRefusedReasonModalVisible: false,
|
isShowRefusedReasonModalVisible: false,
|
||||||
|
isLoading: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addDocument = this.addDocument.bind(this);
|
this.addDocument = this.addDocument.bind(this);
|
||||||
@ -65,45 +67,17 @@ export default class DepositOtherDocument extends React.Component<IProps, IState
|
|||||||
this.onAccept = this.onAccept.bind(this);
|
this.onAccept = this.onAccept.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onAccept() {
|
|
||||||
const filesArray = this.state.currentFiles;
|
|
||||||
|
|
||||||
if (!filesArray) return;
|
|
||||||
|
|
||||||
const documentCreated = await Documents.getInstance().post({
|
|
||||||
folder: {
|
|
||||||
uid: this.props.folder_uid,
|
|
||||||
},
|
|
||||||
depositor: {
|
|
||||||
uid: this.props.customer_uid,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(documentCreated);
|
|
||||||
|
|
||||||
filesArray.forEach(async (file) => {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("file", file.file, file.fileName);
|
|
||||||
const query = JSON.stringify({ document: { uid: documentCreated.uid } });
|
|
||||||
formData.append("q", query);
|
|
||||||
|
|
||||||
const newFile = await Files.getInstance().post(formData);
|
|
||||||
console.log(newFile);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.props.onClose!();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override render(): JSX.Element {
|
public override render(): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<Confirm
|
<Confirm
|
||||||
isOpen={this.state.isAddDocumentModalVisible}
|
isOpen={this.state.isAddDocumentModalVisible}
|
||||||
onClose={this.props.onClose!}
|
onClose={() => {}}
|
||||||
onAccept={this.onAccept}
|
onAccept={this.onAccept}
|
||||||
closeBtn
|
closeBtn
|
||||||
header={"Ajouter un document"}
|
header={"Ajouter un document"}
|
||||||
cancelText={"Annuler"}
|
cancelText={"Annuler"}
|
||||||
confirmText={"Déposer le document"}>
|
confirmText={this.state.isLoading ? "Chargement..." : "Déposer le document"}
|
||||||
|
canConfirm={!this.state.isLoading}>
|
||||||
<div className={classes["modal-content"]}>
|
<div className={classes["modal-content"]}>
|
||||||
<div className={classes["container"]}>
|
<div className={classes["container"]}>
|
||||||
<Typography typo={ITypo.P_16} className={classes["text"]}>
|
<Typography typo={ITypo.P_16} className={classes["text"]}>
|
||||||
@ -140,7 +114,7 @@ export default class DepositOtherDocument extends React.Component<IProps, IState
|
|||||||
</div>
|
</div>
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography color={ITypoColor.GREY} typo={ITypo.CAPTION_14}>
|
<Typography color={ITypoColor.GREY} typo={ITypo.CAPTION_14}>
|
||||||
Sélectionnez des TEST documents .jpg, .pdf ou .png
|
Sélectionnez des documents .jpg, .pdf ou .png
|
||||||
</Typography>
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -187,6 +161,38 @@ export default class DepositOtherDocument extends React.Component<IProps, IState
|
|||||||
|
|
||||||
public override componentDidMount(): void {}
|
public override componentDidMount(): void {}
|
||||||
|
|
||||||
|
private async onAccept() {
|
||||||
|
this.setState({
|
||||||
|
isLoading: true,
|
||||||
|
});
|
||||||
|
const filesArray = this.state.currentFiles;
|
||||||
|
|
||||||
|
if (!filesArray) return;
|
||||||
|
|
||||||
|
const documentCreated = await Documents.getInstance().post({
|
||||||
|
folder: {
|
||||||
|
uid: this.props.folder_uid,
|
||||||
|
},
|
||||||
|
depositor: {
|
||||||
|
uid: this.props.customer_uid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let i = 0; i < filesArray.length; i++) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("file", filesArray[i]!.file, filesArray[i]!.fileName);
|
||||||
|
const query = JSON.stringify({ document: { uid: documentCreated.uid } });
|
||||||
|
formData.append("q", query);
|
||||||
|
await Files.getInstance().post(formData);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
isLoading: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.props.onClose!();
|
||||||
|
}
|
||||||
|
|
||||||
private shortName(name: string): string {
|
private shortName(name: string): string {
|
||||||
const maxLength = 20;
|
const maxLength = 20;
|
||||||
if (name.length > maxLength) {
|
if (name.length > maxLength) {
|
||||||
|
@ -24,48 +24,47 @@ export default function ClientDashboard(props: IProps) {
|
|||||||
const [folder, setFolder] = useState<OfficeFolder | null>(null);
|
const [folder, setFolder] = useState<OfficeFolder | null>(null);
|
||||||
const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState<boolean>(false);
|
const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState<boolean>(false);
|
||||||
|
|
||||||
const onCloseModalAddDocument = useCallback(() => {
|
const getDocuments = useCallback(async () => {
|
||||||
console.log("Closing");
|
let jwt;
|
||||||
|
if (typeof document !== "undefined") {
|
||||||
|
jwt = JwtService.getInstance().decodeJwt();
|
||||||
|
}
|
||||||
|
if (!jwt || !jwt.email) return;
|
||||||
|
const customers = await Customers.getInstance().get({
|
||||||
|
where: { contact: { email: jwt.email }, office_folders: { some: { uid: folderUid } } },
|
||||||
|
});
|
||||||
|
const actualCustomer: Customer = customers[0]!;
|
||||||
|
|
||||||
|
const query: IGetDocumentsparams = {
|
||||||
|
where: { depositor: { uid: actualCustomer.uid }, folder_uid: folderUid as string },
|
||||||
|
include: {
|
||||||
|
files: true,
|
||||||
|
document_history: true,
|
||||||
|
document_type: true,
|
||||||
|
depositor: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const documentList = await Documents.getInstance().get(query);
|
||||||
|
|
||||||
|
const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true } });
|
||||||
|
setFolder(folder);
|
||||||
|
setDocuments(documentList);
|
||||||
|
setCustomer(actualCustomer);
|
||||||
|
}, [folderUid]);
|
||||||
|
|
||||||
|
const onCloseModalAddDocument = useCallback(() => {
|
||||||
setIsAddDocumentModalVisible(false);
|
setIsAddDocumentModalVisible(false);
|
||||||
}, []);
|
getDocuments();
|
||||||
|
}, [getDocuments]);
|
||||||
|
|
||||||
const onOpenModalAddDocument = useCallback(() => {
|
const onOpenModalAddDocument = useCallback(() => {
|
||||||
setIsAddDocumentModalVisible(true);
|
setIsAddDocumentModalVisible(true);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getDocuments() {
|
|
||||||
let jwt;
|
|
||||||
if (typeof document !== "undefined") {
|
|
||||||
jwt = JwtService.getInstance().decodeJwt();
|
|
||||||
}
|
|
||||||
if (!jwt || !jwt.email) return;
|
|
||||||
const customers = await Customers.getInstance().get({
|
|
||||||
where: { contact: { email: jwt.email }, office_folders: { some: { uid: folderUid } } },
|
|
||||||
});
|
|
||||||
const actualCustomer: Customer = customers[0]!;
|
|
||||||
|
|
||||||
const query: IGetDocumentsparams = {
|
|
||||||
where: { depositor: { uid: actualCustomer.uid }, folder_uid: folderUid as string },
|
|
||||||
include: {
|
|
||||||
files: true,
|
|
||||||
document_history: true,
|
|
||||||
document_type: true,
|
|
||||||
depositor: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const documentList = await Documents.getInstance().get(query);
|
|
||||||
|
|
||||||
const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true } });
|
|
||||||
setFolder(folder);
|
|
||||||
setDocuments(documentList);
|
|
||||||
setCustomer(actualCustomer);
|
|
||||||
}
|
|
||||||
|
|
||||||
getDocuments();
|
getDocuments();
|
||||||
}, [folderUid]);
|
}, [folderUid, getDocuments]);
|
||||||
|
|
||||||
const renderHeader = useCallback(() => {
|
const renderHeader = useCallback(() => {
|
||||||
console.log("Dossier : ", customer);
|
console.log("Dossier : ", customer);
|
||||||
@ -101,11 +100,9 @@ export default function ClientDashboard(props: IProps) {
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}, [customer]);
|
}, [customer, folder?.folder_number, folder?.name, folder?.office?.name]);
|
||||||
|
|
||||||
const renderBox = useCallback(() => {
|
const renderBox = useCallback(() => {
|
||||||
console.log(isAddDocumentModalVisible);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DepositOtherDocument
|
<DepositOtherDocument
|
||||||
folder_uid={folderUid!}
|
folder_uid={folderUid!}
|
||||||
@ -114,7 +111,7 @@ export default function ClientDashboard(props: IProps) {
|
|||||||
onClose={onCloseModalAddDocument}
|
onClose={onCloseModalAddDocument}
|
||||||
document={Document.hydrate<Document>({
|
document={Document.hydrate<Document>({
|
||||||
document_type: DocumentType.hydrate<DocumentType>({
|
document_type: DocumentType.hydrate<DocumentType>({
|
||||||
name: "Document annexe",
|
name: "Autres documents",
|
||||||
}),
|
}),
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
|
@ -71,7 +71,7 @@ export default class ClientDashboard extends Base<IProps, IState> {
|
|||||||
<DepositDocument
|
<DepositDocument
|
||||||
document={Document.hydrate<Document>({
|
document={Document.hydrate<Document>({
|
||||||
document_type: DocumentType.hydrate<DocumentType>({
|
document_type: DocumentType.hydrate<DocumentType>({
|
||||||
name: "Document annexe",
|
name: "Autres documents",
|
||||||
}),
|
}),
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user