diff --git a/apps/browser/src/tools/popup/send-v2/add-edit/send-add-edit.component.html b/apps/browser/src/tools/popup/send-v2/add-edit/send-add-edit.component.html
index b3783bfed3a0..40c942539f68 100644
--- a/apps/browser/src/tools/popup/send-v2/add-edit/send-add-edit.component.html
+++ b/apps/browser/src/tools/popup/send-v2/add-edit/send-add-edit.component.html
@@ -4,7 +4,8 @@
diff --git a/apps/browser/src/tools/popup/send-v2/add-edit/send-add-edit.component.ts b/apps/browser/src/tools/popup/send-v2/add-edit/send-add-edit.component.ts
index c84b9717df1a..20b472f97f30 100644
--- a/apps/browser/src/tools/popup/send-v2/add-edit/send-add-edit.component.ts
+++ b/apps/browser/src/tools/popup/send-v2/add-edit/send-add-edit.component.ts
@@ -2,12 +2,13 @@ import { CommonModule, Location } from "@angular/common";
import { Component } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { FormsModule } from "@angular/forms";
-import { ActivatedRoute, Params } from "@angular/router";
+import { ActivatedRoute, Params, Router } from "@angular/router";
import { map, switchMap } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
+import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction";
import { SendId } from "@bitwarden/common/types/guid";
import {
@@ -95,14 +96,25 @@ export class SendAddEditComponent {
private sendApiService: SendApiService,
private toastService: ToastService,
private dialogService: DialogService,
+ private router: Router,
) {
this.subscribeToParams();
}
/**
- * Handles the event when the send is saved.
+ * Handles the event when the send is created.
*/
- onSendSaved() {
+ async onSendCreated(send: SendView) {
+ await this.router.navigate(["/send-created"], {
+ queryParams: { sendId: send.id },
+ });
+ return;
+ }
+
+ /**
+ * Handles the event when the send is updated.
+ */
+ onSendUpdated(send: SendView) {
this.location.back();
}
diff --git a/apps/browser/src/tools/popup/send-v2/send-created/send-created.component.html b/apps/browser/src/tools/popup/send-v2/send-created/send-created.component.html
index 9b56fa74d915..c97d3da1396d 100644
--- a/apps/browser/src/tools/popup/send-v2/send-created/send-created.component.html
+++ b/apps/browser/src/tools/popup/send-v2/send-created/send-created.component.html
@@ -1,6 +1,11 @@
-
+
diff --git a/apps/browser/src/tools/popup/send-v2/send-created/send-created.component.spec.ts b/apps/browser/src/tools/popup/send-v2/send-created/send-created.component.spec.ts
index 413f22565e15..bcc4d2e2ccb3 100644
--- a/apps/browser/src/tools/popup/send-v2/send-created/send-created.component.spec.ts
+++ b/apps/browser/src/tools/popup/send-v2/send-created/send-created.component.spec.ts
@@ -1,6 +1,6 @@
import { CommonModule, Location } from "@angular/common";
import { ComponentFixture, TestBed } from "@angular/core/testing";
-import { ActivatedRoute, RouterLink } from "@angular/router";
+import { ActivatedRoute, Router, RouterLink } from "@angular/router";
import { RouterTestingModule } from "@angular/router/testing";
import { MockProxy, mock } from "jest-mock-extended";
import { of } from "rxjs";
@@ -33,6 +33,7 @@ describe("SendCreatedComponent", () => {
let location: MockProxy;
let activatedRoute: MockProxy;
let environmentService: MockProxy;
+ let router: MockProxy;
const sendId = "test-send-id";
const deletionDate = new Date();
@@ -52,6 +53,7 @@ describe("SendCreatedComponent", () => {
location = mock();
activatedRoute = mock();
environmentService = mock();
+ router = mock();
Object.defineProperty(environmentService, "environment$", {
configurable: true,
get: () => of(new SelfHostedEnvironment({ webVault: "https://example.com" })),
@@ -89,6 +91,7 @@ describe("SendCreatedComponent", () => {
{ provide: ConfigService, useValue: mock() },
{ provide: EnvironmentService, useValue: environmentService },
{ provide: PopupRouterCacheService, useValue: mock() },
+ { provide: Router, useValue: router },
],
}).compileComponents();
});
@@ -109,10 +112,10 @@ describe("SendCreatedComponent", () => {
expect(component["daysAvailable"]).toBe(7);
});
- it("should navigate back on close", () => {
+ it("should navigate back to send list on close", async () => {
fixture.detectChanges();
- component.close();
- expect(location.back).toHaveBeenCalled();
+ await component.close();
+ expect(router.navigate).toHaveBeenCalledWith(["/tabs/send"]);
});
describe("getDaysAvailable", () => {
diff --git a/apps/browser/src/tools/popup/send-v2/send-created/send-created.component.ts b/apps/browser/src/tools/popup/send-v2/send-created/send-created.component.ts
index 92339774d05d..4ed4da2f81d4 100644
--- a/apps/browser/src/tools/popup/send-v2/send-created/send-created.component.ts
+++ b/apps/browser/src/tools/popup/send-v2/send-created/send-created.component.ts
@@ -1,7 +1,7 @@
-import { CommonModule, Location } from "@angular/common";
+import { CommonModule } from "@angular/common";
import { Component } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
-import { ActivatedRoute, RouterLink } from "@angular/router";
+import { ActivatedRoute, Router, RouterLink, RouterModule } from "@angular/router";
import { firstValueFrom } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module";
@@ -30,6 +30,7 @@ import { PopupPageComponent } from "../../../../platform/popup/layout/popup-page
PopupHeaderComponent,
PopupPageComponent,
RouterLink,
+ RouterModule,
PopupFooterComponent,
IconModule,
],
@@ -45,10 +46,11 @@ export class SendCreatedComponent {
private sendService: SendService,
private route: ActivatedRoute,
private toastService: ToastService,
- private location: Location,
+ private router: Router,
private environmentService: EnvironmentService,
) {
const sendId = this.route.snapshot.queryParamMap.get("sendId");
+
this.sendService.sendViews$.pipe(takeUntilDestroyed()).subscribe((sendViews) => {
this.send = sendViews.find((s) => s.id === sendId);
if (this.send) {
@@ -62,8 +64,8 @@ export class SendCreatedComponent {
return Math.max(0, Math.ceil((send.deletionDate.getTime() - now) / (1000 * 60 * 60 * 24)));
}
- close() {
- this.location.back();
+ async close() {
+ await this.router.navigate(["/tabs/send"]);
}
async copyLink() {
diff --git a/libs/common/src/tools/send/services/send-api.service.abstraction.ts b/libs/common/src/tools/send/services/send-api.service.abstraction.ts
index 100985c48706..4109df196808 100644
--- a/libs/common/src/tools/send/services/send-api.service.abstraction.ts
+++ b/libs/common/src/tools/send/services/send-api.service.abstraction.ts
@@ -36,5 +36,5 @@ export abstract class SendApiService {
renewSendFileUploadUrl: (sendId: string, fileId: string) => Promise;
removePassword: (id: string) => Promise;
delete: (id: string) => Promise;
- save: (sendData: [Send, EncArrayBuffer]) => Promise;
+ save: (sendData: [Send, EncArrayBuffer]) => Promise;
}
diff --git a/libs/common/src/tools/send/services/send-api.service.ts b/libs/common/src/tools/send/services/send-api.service.ts
index 2cb2ff1c2f05..ff71408bce3c 100644
--- a/libs/common/src/tools/send/services/send-api.service.ts
+++ b/libs/common/src/tools/send/services/send-api.service.ts
@@ -135,11 +135,12 @@ export class SendApiService implements SendApiServiceAbstraction {
return this.apiService.send("DELETE", "/sends/" + id, null, true, false);
}
- async save(sendData: [Send, EncArrayBuffer]): Promise {
+ async save(sendData: [Send, EncArrayBuffer]): Promise {
const response = await this.upload(sendData);
const data = new SendData(response);
await this.sendService.upsert(data);
+ return new Send(data);
}
async delete(id: string): Promise {
diff --git a/libs/tools/send/send-ui/src/send-form/components/send-form.component.ts b/libs/tools/send/send-ui/src/send-form/components/send-form.component.ts
index 1d93804e11f1..07939ccb06c5 100644
--- a/libs/tools/send/send-ui/src/send-form/components/send-form.component.ts
+++ b/libs/tools/send/send-ui/src/send-form/components/send-form.component.ts
@@ -85,9 +85,14 @@ export class SendFormComponent implements AfterViewInit, OnInit, OnChanges, Send
submitBtn?: ButtonComponent;
/**
- * Event emitted when the send is saved successfully.
+ * Event emitted when the send is created successfully.
*/
- @Output() sendSaved = new EventEmitter();
+ @Output() onSendCreated = new EventEmitter();
+
+ /**
+ * Event emitted when the send is updated successfully.
+ */
+ @Output() onSendUpdated = new EventEmitter();
/**
* The original send being edited or cloned. Null for add mode.
@@ -200,22 +205,26 @@ export class SendFormComponent implements AfterViewInit, OnInit, OnChanges, Send
return;
}
+ const sendView = await this.addEditFormService.saveSend(
+ this.updatedSendView,
+ this.file,
+ this.config,
+ );
+
+ if (this.config.mode === "add") {
+ this.onSendCreated.emit(sendView);
+ return;
+ }
+
if (Utils.isNullOrWhitespace(this.updatedSendView.password)) {
this.updatedSendView.password = null;
}
- await this.addEditFormService.saveSend(this.updatedSendView, this.file, this.config);
-
this.toastService.showToast({
variant: "success",
title: null,
- message: this.i18nService.t(
- this.config.mode === "edit" || this.config.mode === "partial-edit"
- ? "editedItem"
- : "addedItem",
- ),
+ message: this.i18nService.t("editedItem"),
});
-
- this.sendSaved.emit(this.updatedSendView);
+ this.onSendUpdated.emit(this.updatedSendView);
};
}
diff --git a/libs/tools/send/send-ui/src/send-form/services/default-send-form.service.ts b/libs/tools/send/send-ui/src/send-form/services/default-send-form.service.ts
index 9b6a6360ac7f..9eb37b07e50a 100644
--- a/libs/tools/send/send-ui/src/send-form/services/default-send-form.service.ts
+++ b/libs/tools/send/send-ui/src/send-form/services/default-send-form.service.ts
@@ -19,6 +19,7 @@ export class DefaultSendFormService implements SendFormService {
async saveSend(send: SendView, file: File | ArrayBuffer, config: SendFormConfig) {
const sendData = await this.sendService.encrypt(send, file, send.password, null);
- return await this.sendApiService.save(sendData);
+ const newSend = await this.sendApiService.save(sendData);
+ return await this.decryptSend(newSend);
}
}