1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

fix send text details form

This commit is contained in:
jaasen-livefront
2024-09-12 13:50:58 -07:00
parent 3b968c0c99
commit 83587ca022
8 changed files with 98 additions and 24 deletions

View File

@@ -23,6 +23,7 @@ export function extensionRefreshSwap(
defaultComponent,
refreshedComponent,
async () => {
return true;
const configService = inject(ConfigService);
return configService.getFeatureFlag(FeatureFlag.ExtensionRefresh);
},

View File

@@ -26,6 +26,7 @@ export class SendView implements View {
password: string = null;
disabled = false;
hideEmail = false;
hideText = false;
constructor(s?: Send) {
if (!s) {

View File

@@ -9,10 +9,10 @@ import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
import { SendFormConfig } from "../../abstractions/send-form-config.service";
import { SendFormContainer } from "../../send-form-container";
export interface BaseSendDetailsForm {
export type BaseSendDetailsForm = FormGroup<{
name: FormControl<string>;
selectedDeletionDatePreset: FormControl<string | number>;
}
}>;
// Value = hours
export enum DatePreset {
@@ -36,9 +36,9 @@ export interface DatePresetSelectOption {
})
export class BaseSendDetailsComponent implements OnInit {
@Input() config: SendFormConfig;
@Input() originalSendView: SendView;
@Input() originalSendView?: SendView;
sendDetailsForm: FormGroup<BaseSendDetailsForm>;
sendDetailsForm: BaseSendDetailsForm;
customDeletionDateOption: DatePresetSelectOption | null = null;
datePresetOptions: DatePresetSelectOption[] = [];
@@ -52,7 +52,7 @@ export class BaseSendDetailsComponent implements OnInit {
this.sendDetailsForm = this.formBuilder.group({
name: new FormControl("", Validators.required),
selectedDeletionDatePreset: new FormControl(DatePreset.SevenDays || "", Validators.required),
}) as FormGroup<BaseSendDetailsForm>;
});
this.sendDetailsForm.valueChanges.pipe(takeUntilDestroyed()).subscribe((value) => {
this.sendFormContainer.patchSend((send) => {

View File

@@ -13,6 +13,7 @@
*ngIf="config.sendType === TextSendType"
[config]="config"
[originalSendView]="originalSendView"
[sendDetailsForm]="sendDetailsForm"
></tools-send-text-details>
<bit-form-field>

View File

@@ -1,11 +1,10 @@
import { CommonModule, DatePipe } from "@angular/common";
import { Component, Input, OnInit } from "@angular/core";
import { Component, OnInit } from "@angular/core";
import { FormBuilder, ReactiveFormsModule } from "@angular/forms";
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 {
SectionComponent,
SectionHeaderComponent,
@@ -17,7 +16,6 @@ import {
SelectModule,
} from "@bitwarden/components";
import { SendFormConfig } from "../../abstractions/send-form-config.service";
import { SendFormContainer } from "../../send-form-container";
import { BaseSendDetailsComponent } from "./base-send-details.component";
@@ -43,9 +41,6 @@ import { SendTextDetailsComponent } from "./send-text-details.component";
],
})
export class SendDetailsComponent extends BaseSendDetailsComponent implements OnInit {
@Input() config: SendFormConfig;
@Input() originalSendView: SendView;
FileSendType = SendType.File;
TextSendType = SendType.Text;

View File

@@ -1,9 +1,11 @@
<bit-form-field>
<bit-label>{{ "sendTypeTextToShare" | i18n }}</bit-label>
<textarea bitInput id="text" rows="6" formControlName="textToShare"></textarea>
<bit-hint>{{ "sendTextDesc" | i18n }}</bit-hint>
</bit-form-field>
<bit-form-control>
<input bitCheckbox type="checkbox" formControlName="hideTextByDefault" />
<bit-label>{{ "hideTextByDefault" | i18n }}</bit-label>
</bit-form-control>
<bit-section [formGroup]="sendTextDetailsForm">
<bit-form-field>
<bit-label>{{ "sendTypeTextToShare" | i18n }}</bit-label>
<textarea bitInput id="text" rows="6" formControlName="text"></textarea>
<bit-hint>{{ "sendTextDesc" | i18n }}</bit-hint>
</bit-form-field>
<bit-form-control>
<input bitCheckbox type="checkbox" formControlName="hidden" />
<bit-label>{{ "hideTextByDefault" | i18n }}</bit-label>
</bit-form-control>
</bit-section>

View File

@@ -1,15 +1,87 @@
import { Component, Input } from "@angular/core";
import { CommonModule } from "@angular/common";
import { Component, Input, OnInit } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import {
FormBuilder,
FormControl,
FormGroup,
Validators,
ReactiveFormsModule,
} from "@angular/forms";
import { JslibModule } from "@bitwarden/angular/jslib.module";
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
import { CheckboxModule, FormFieldModule, SectionComponent } from "@bitwarden/components";
import { SendFormConfig } from "../../abstractions/send-form-config.service";
import { SendFormContainer } from "../../send-form-container";
import { BaseSendDetailsForm } from "./base-send-details.component";
type BaseSendTextDetailsForm = FormGroup<{
text: FormControl<string>;
hidden: FormControl<boolean>;
}>;
export type SendTextDetailsForm = BaseSendTextDetailsForm & BaseSendDetailsForm;
@Component({
selector: "tools-send-text-details",
template: "send-text-details.component.html",
templateUrl: "./send-text-details.component.html",
standalone: true,
imports: [
CheckboxModule,
CommonModule,
JslibModule,
ReactiveFormsModule,
FormFieldModule,
SectionComponent,
],
})
export class SendTextDetailsComponent {
export class SendTextDetailsComponent implements OnInit {
@Input() config: SendFormConfig;
@Input() originalSendView: SendView;
@Input() originalSendView?: SendView;
@Input() sendDetailsForm: BaseSendDetailsForm;
baseSendTextDetailsForm: BaseSendTextDetailsForm;
sendTextDetailsForm: SendTextDetailsForm;
constructor(
private formBuilder: FormBuilder,
protected sendFormContainer: SendFormContainer,
) {
// Subscribe to form value changes and update the parent SendView accordingly
this.sendTextDetailsForm.valueChanges.pipe(takeUntilDestroyed()).subscribe((value) => {
this.sendFormContainer.patchSend((send) => {
// Update the send object with the form values
return Object.assign(send, {
text: {
text: value.text,
hidden: value.hidden,
},
});
});
});
}
ngOnInit() {
// Define the nested form group for `text`
this.baseSendTextDetailsForm = this.formBuilder.group({
text: new FormControl("", Validators.required),
hidden: new FormControl(false),
});
this.sendTextDetailsForm = Object.assign(this.baseSendTextDetailsForm, this.sendDetailsForm);
// Register this form with the parent form
this.sendFormContainer.registerChildForm("sendTextDetailsForm", this.sendTextDetailsForm);
// If editing or cloning an existing SendView, populate the form
if (this.originalSendView) {
this.baseSendTextDetailsForm.patchValue({
text: this.originalSendView.text?.text || "",
hidden: this.originalSendView.text?.hidden || false,
});
}
}
}

View File

@@ -2,12 +2,14 @@ import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
import { SendFormConfig } from "./abstractions/send-form-config.service";
import { SendDetailsComponent } from "./components/send-details/send-details.component";
import { SendTextDetailsForm } from "./components/send-details/send-text-details.component";
/**
* The complete form for a send. Includes all the sub-forms from their respective section components.
* TODO: Add additional form sections as they are implemented.
*/
export type SendForm = {
sendDetailsForm?: SendDetailsComponent["sendDetailsForm"];
sendTextDetailsForm?: SendTextDetailsForm;
};
/**