Fixed
This commit is contained in:
parent
f5195f5c0a
commit
aae8463185
36
src/front/Api/LeCoffreApi/Customer/OfficeRib/OfficeRib.ts
Normal file
36
src/front/Api/LeCoffreApi/Customer/OfficeRib/OfficeRib.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import BaseNotary from "../BaseCustomer";
|
||||
|
||||
// TODO Type get query params -> Where + inclue + orderby
|
||||
export interface IGetFilesparams {
|
||||
where?: {};
|
||||
include?: {};
|
||||
}
|
||||
|
||||
// TODO Type getbyuid query params
|
||||
|
||||
export type IPutFilesParams = {};
|
||||
|
||||
export interface IPostFilesParams {}
|
||||
|
||||
export default class OfficeRib extends BaseNotary {
|
||||
private static instance: OfficeRib;
|
||||
private readonly baseURl = this.namespaceUrl.concat("/office");
|
||||
|
||||
private constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static getInstance() {
|
||||
return (this.instance ??= new this());
|
||||
}
|
||||
|
||||
public async getRibStream(uid: string) {
|
||||
const url = new URL(this.baseURl.concat(`/${uid}/rib`));
|
||||
try {
|
||||
return await this.getRequest<any>(url);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import BaseNotary from "../../Notary/BaseNotary";
|
||||
import BaseNotary from "../BaseNotary";
|
||||
|
||||
// TODO Type get query params -> Where + inclue + orderby
|
||||
export interface IGetFilesparams {
|
||||
@ -12,9 +12,9 @@ export type IPutFilesParams = {};
|
||||
|
||||
export interface IPostFilesParams {}
|
||||
|
||||
export default class Bucket extends BaseNotary {
|
||||
private static instance: Bucket;
|
||||
private readonly baseURl = this.namespaceUrl.concat("/bucket");
|
||||
export default class OfficeRib extends BaseNotary {
|
||||
private static instance: OfficeRib;
|
||||
private readonly baseURl = this.namespaceUrl.concat("/office/rib");
|
||||
|
||||
private constructor() {
|
||||
super();
|
||||
@ -24,8 +24,8 @@ export default class Bucket extends BaseNotary {
|
||||
return (this.instance ??= new this());
|
||||
}
|
||||
|
||||
public async getRibStream(uid: string) {
|
||||
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||
public async getRibStream() {
|
||||
const url = new URL(this.baseURl);
|
||||
try {
|
||||
return await this.getRequest<any>(url);
|
||||
} catch (err) {
|
||||
@ -50,8 +50,8 @@ export default class Bucket extends BaseNotary {
|
||||
/**
|
||||
* @description : Delete a File
|
||||
*/
|
||||
public async delete(uid: string) {
|
||||
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||
public async delete() {
|
||||
const url = new URL(this.baseURl);
|
||||
try {
|
||||
return await this.deleteRequest(url);
|
||||
} catch (err) {
|
@ -12,6 +12,7 @@ import { useRouter } from "next/router";
|
||||
import JwtService, { ICustomerJwtPayload } from "@Front/Services/JwtService/JwtService";
|
||||
import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDocument";
|
||||
import Folders from "@Front/Api/LeCoffreApi/Customer/Folders/Folders";
|
||||
import OfficeRib from "@Front/Api/LeCoffreApi/Customer/OfficeRib/OfficeRib";
|
||||
|
||||
type IProps = {};
|
||||
|
||||
@ -71,6 +72,20 @@ export default function ClientDashboard(props: IProps) {
|
||||
setIsAddDocumentModalVisible(true);
|
||||
}, []);
|
||||
|
||||
async function downloadFile() {
|
||||
if (!folder?.office?.uid) return;
|
||||
const blob = await OfficeRib.getInstance().getRibStream(folder.office.uid);
|
||||
const ribUrl = URL.createObjectURL(blob);
|
||||
|
||||
if (!ribUrl) return;
|
||||
const a = document.createElement("a");
|
||||
a.style.display = "none";
|
||||
a.href = ribUrl;
|
||||
a.download = "";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getDocuments();
|
||||
}, [folderUid, getDocuments]);
|
||||
@ -102,6 +117,8 @@ export default function ClientDashboard(props: IProps) {
|
||||
sélectionnez le document correspondant. <br /> En déposant un document, celui-ci est automatiquement enregistré et
|
||||
transmis à votre notaire.
|
||||
</Typography>
|
||||
|
||||
<Button onClick={downloadFile}>Télécharger le Rib</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
@ -5,7 +5,7 @@ import DefaultTemplate from "@Front/Components/LayoutTemplates/DefaultTemplate";
|
||||
import FilePreview from "@Front/Components/DesignSystem/FilePreview";
|
||||
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||
import { useRouter } from "next/router";
|
||||
import Bucket from "@Front/Api/LeCoffreApi/Notary/Bucket/Bucket";
|
||||
import OfficeRib from "@Front/Api/LeCoffreApi/Notary/OfficeRib/OfficeRib";
|
||||
import DepositRib from "@Front/Components/DesignSystem/DepositRib";
|
||||
import Confirm from "@Front/Components/DesignSystem/Modal/Confirm";
|
||||
|
||||
@ -22,11 +22,8 @@ export default function Rib() {
|
||||
//Put fetch data in a useCallback
|
||||
|
||||
const fetchData = useCallback(async () => {
|
||||
console.log("fetchData", officeUid);
|
||||
|
||||
if (!officeUid) return;
|
||||
try {
|
||||
const blob = await Bucket.getInstance().getRibStream(officeUid as string);
|
||||
const blob = await OfficeRib.getInstance().getRibStream();
|
||||
|
||||
const ribUrl = URL.createObjectURL(blob);
|
||||
|
||||
@ -60,7 +57,7 @@ export default function Rib() {
|
||||
const formData = new FormData();
|
||||
formData.append("file", documentList[0]!, documentList[0]!.name);
|
||||
|
||||
await Bucket.getInstance().post(formData);
|
||||
await OfficeRib.getInstance().post(formData);
|
||||
|
||||
onCloseRibModal();
|
||||
fetchData();
|
||||
@ -76,9 +73,7 @@ export default function Rib() {
|
||||
}
|
||||
|
||||
async function onDeleteModalAccepted() {
|
||||
if (!officeUid) return;
|
||||
const office = await Bucket.getInstance().delete(officeUid as string);
|
||||
console.log(office);
|
||||
await OfficeRib.getInstance().delete();
|
||||
|
||||
onCloseDeleteModal();
|
||||
fetchData();
|
||||
|
Loading…
x
Reference in New Issue
Block a user