Parcours d'ancrage ok

This commit is contained in:
Maxime Lalo 2023-09-29 19:20:32 +02:00
parent add3d44e0b
commit 07a360f338
2 changed files with 39 additions and 18 deletions

View File

@ -24,7 +24,6 @@ export default function Navigation() {
redirectUrl: notification.notification.redirection_url,
});
});
console.log(notifications);
}, []);
useEffect(() => {

View File

@ -36,6 +36,7 @@ type IState = {
isValidateModalVisible: boolean;
hasValidateAnchoring: boolean;
isVerifDeleteModalVisible: boolean;
isAnchored: boolean | null;
};
class FolderInformationClass extends BasePage<IPropsClass, IState> {
public constructor(props: IPropsClass) {
@ -47,6 +48,7 @@ class FolderInformationClass extends BasePage<IPropsClass, IState> {
isValidateModalVisible: false,
hasValidateAnchoring: false,
isVerifDeleteModalVisible: false,
isAnchored: null,
};
this.onSelectedFolder = this.onSelectedFolder.bind(this);
this.openArchivedModal = this.openArchivedModal.bind(this);
@ -60,6 +62,7 @@ class FolderInformationClass extends BasePage<IPropsClass, IState> {
this.openValidateModal = this.openValidateModal.bind(this);
this.openVerifDeleteFolder = this.openVerifDeleteFolder.bind(this);
this.closeVerifDeleteFolder = this.closeVerifDeleteFolder.bind(this);
this.verifyAnchorStatus = this.verifyAnchorStatus.bind(this);
}
// TODO: Message if the user has not created any folder yet
@ -109,16 +112,20 @@ class FolderInformationClass extends BasePage<IPropsClass, IState> {
Archiver le dossier
</Button>
{this.everyDocumentValidated() && (
<Button variant={EButtonVariant.PRIMARY} onClick={this.openValidateModal}>
Ancrer le dossier
</Button>
)}
{this.everyDocumentValidated() && (
<Button
variant={EButtonVariant.PRIMARY}
onClick={() => this.downloadAnchoringProof(this.state.selectedFolder?.uid)}>
Télécharger la preuve d'ancrage
</Button>
<>
{this.state.isAnchored === null && (
<Button variant={EButtonVariant.PRIMARY} onClick={this.openValidateModal}>
Ancrer le dossier
</Button>
)}
{this.state.isAnchored === true && (
<Button
variant={EButtonVariant.PRIMARY}
onClick={() => this.downloadAnchoringProof(this.state.selectedFolder?.uid)}>
Télécharger la preuve d'ancrage
</Button>
)}
</>
)}
{!this.doesFolderHaveCustomer() && (
<span className={classes["delete-folder"]} onClick={this.openVerifDeleteFolder}>
@ -207,11 +214,30 @@ class FolderInformationClass extends BasePage<IPropsClass, IState> {
);
}
public override async componentDidMount() {
this.setState({
selectedFolder: (await this.getFolder()) as OfficeFolder,
});
const selectedFolder = await this.getFolder();
this.setState(
{
selectedFolder,
},
() => {
this.verifyAnchorStatus();
},
);
}
private async verifyAnchorStatus() {
if (!this.state.selectedFolder || !this.state.selectedFolder.uid) return;
try {
const anchorStatus = await OfficeFolderAnchors.getInstance().get(this.state.selectedFolder.uid!);
this.setState({
isAnchored: anchorStatus.status === "VERIFIED_ON_CHAIN",
});
} catch (e) {
this.setState({
isAnchored: null,
});
}
}
public openVerifDeleteFolder() {
this.setState({
isVerifDeleteModalVisible: true,
@ -267,15 +293,11 @@ class FolderInformationClass extends BasePage<IPropsClass, IState> {
private async anchorFolder() {
if (!this.state.selectedFolder?.uid) return;
const anchor = await OfficeFolderAnchors.getInstance().post(this.state.selectedFolder.uid);
console.log(anchor);
}
private async downloadAnchoringProof(uid?: string) {
if (!uid) return;
const anchor = await OfficeFolderAnchors.getInstance().get(uid);
if (anchor.status !== "VERIFIED_ON_CHAIN") return;
try {
const file: Blob = await OfficeFolderAnchors.getInstance().download(uid);
const url = window.URL.createObjectURL(file);