mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
fix send text details form
This commit is contained in:
@@ -23,6 +23,7 @@ export function extensionRefreshSwap(
|
|||||||
defaultComponent,
|
defaultComponent,
|
||||||
refreshedComponent,
|
refreshedComponent,
|
||||||
async () => {
|
async () => {
|
||||||
|
return true;
|
||||||
const configService = inject(ConfigService);
|
const configService = inject(ConfigService);
|
||||||
return configService.getFeatureFlag(FeatureFlag.ExtensionRefresh);
|
return configService.getFeatureFlag(FeatureFlag.ExtensionRefresh);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export class SendView implements View {
|
|||||||
password: string = null;
|
password: string = null;
|
||||||
disabled = false;
|
disabled = false;
|
||||||
hideEmail = false;
|
hideEmail = false;
|
||||||
|
hideText = false;
|
||||||
|
|
||||||
constructor(s?: Send) {
|
constructor(s?: Send) {
|
||||||
if (!s) {
|
if (!s) {
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
|
|||||||
import { SendFormConfig } from "../../abstractions/send-form-config.service";
|
import { SendFormConfig } from "../../abstractions/send-form-config.service";
|
||||||
import { SendFormContainer } from "../../send-form-container";
|
import { SendFormContainer } from "../../send-form-container";
|
||||||
|
|
||||||
export interface BaseSendDetailsForm {
|
export type BaseSendDetailsForm = FormGroup<{
|
||||||
name: FormControl<string>;
|
name: FormControl<string>;
|
||||||
selectedDeletionDatePreset: FormControl<string | number>;
|
selectedDeletionDatePreset: FormControl<string | number>;
|
||||||
}
|
}>;
|
||||||
|
|
||||||
// Value = hours
|
// Value = hours
|
||||||
export enum DatePreset {
|
export enum DatePreset {
|
||||||
@@ -36,9 +36,9 @@ export interface DatePresetSelectOption {
|
|||||||
})
|
})
|
||||||
export class BaseSendDetailsComponent implements OnInit {
|
export class BaseSendDetailsComponent implements OnInit {
|
||||||
@Input() config: SendFormConfig;
|
@Input() config: SendFormConfig;
|
||||||
@Input() originalSendView: SendView;
|
@Input() originalSendView?: SendView;
|
||||||
|
|
||||||
sendDetailsForm: FormGroup<BaseSendDetailsForm>;
|
sendDetailsForm: BaseSendDetailsForm;
|
||||||
customDeletionDateOption: DatePresetSelectOption | null = null;
|
customDeletionDateOption: DatePresetSelectOption | null = null;
|
||||||
datePresetOptions: DatePresetSelectOption[] = [];
|
datePresetOptions: DatePresetSelectOption[] = [];
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ export class BaseSendDetailsComponent implements OnInit {
|
|||||||
this.sendDetailsForm = this.formBuilder.group({
|
this.sendDetailsForm = this.formBuilder.group({
|
||||||
name: new FormControl("", Validators.required),
|
name: new FormControl("", Validators.required),
|
||||||
selectedDeletionDatePreset: new FormControl(DatePreset.SevenDays || "", Validators.required),
|
selectedDeletionDatePreset: new FormControl(DatePreset.SevenDays || "", Validators.required),
|
||||||
}) as FormGroup<BaseSendDetailsForm>;
|
});
|
||||||
|
|
||||||
this.sendDetailsForm.valueChanges.pipe(takeUntilDestroyed()).subscribe((value) => {
|
this.sendDetailsForm.valueChanges.pipe(takeUntilDestroyed()).subscribe((value) => {
|
||||||
this.sendFormContainer.patchSend((send) => {
|
this.sendFormContainer.patchSend((send) => {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
*ngIf="config.sendType === TextSendType"
|
*ngIf="config.sendType === TextSendType"
|
||||||
[config]="config"
|
[config]="config"
|
||||||
[originalSendView]="originalSendView"
|
[originalSendView]="originalSendView"
|
||||||
|
[sendDetailsForm]="sendDetailsForm"
|
||||||
></tools-send-text-details>
|
></tools-send-text-details>
|
||||||
|
|
||||||
<bit-form-field>
|
<bit-form-field>
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { CommonModule, DatePipe } from "@angular/common";
|
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 { FormBuilder, ReactiveFormsModule } from "@angular/forms";
|
||||||
|
|
||||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
|
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
|
||||||
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
|
|
||||||
import {
|
import {
|
||||||
SectionComponent,
|
SectionComponent,
|
||||||
SectionHeaderComponent,
|
SectionHeaderComponent,
|
||||||
@@ -17,7 +16,6 @@ import {
|
|||||||
SelectModule,
|
SelectModule,
|
||||||
} from "@bitwarden/components";
|
} from "@bitwarden/components";
|
||||||
|
|
||||||
import { SendFormConfig } from "../../abstractions/send-form-config.service";
|
|
||||||
import { SendFormContainer } from "../../send-form-container";
|
import { SendFormContainer } from "../../send-form-container";
|
||||||
|
|
||||||
import { BaseSendDetailsComponent } from "./base-send-details.component";
|
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 {
|
export class SendDetailsComponent extends BaseSendDetailsComponent implements OnInit {
|
||||||
@Input() config: SendFormConfig;
|
|
||||||
@Input() originalSendView: SendView;
|
|
||||||
|
|
||||||
FileSendType = SendType.File;
|
FileSendType = SendType.File;
|
||||||
TextSendType = SendType.Text;
|
TextSendType = SendType.Text;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<bit-form-field>
|
<bit-section [formGroup]="sendTextDetailsForm">
|
||||||
<bit-label>{{ "sendTypeTextToShare" | i18n }}</bit-label>
|
<bit-form-field>
|
||||||
<textarea bitInput id="text" rows="6" formControlName="textToShare"></textarea>
|
<bit-label>{{ "sendTypeTextToShare" | i18n }}</bit-label>
|
||||||
<bit-hint>{{ "sendTextDesc" | i18n }}</bit-hint>
|
<textarea bitInput id="text" rows="6" formControlName="text"></textarea>
|
||||||
</bit-form-field>
|
<bit-hint>{{ "sendTextDesc" | i18n }}</bit-hint>
|
||||||
<bit-form-control>
|
</bit-form-field>
|
||||||
<input bitCheckbox type="checkbox" formControlName="hideTextByDefault" />
|
<bit-form-control>
|
||||||
<bit-label>{{ "hideTextByDefault" | i18n }}</bit-label>
|
<input bitCheckbox type="checkbox" formControlName="hidden" />
|
||||||
</bit-form-control>
|
<bit-label>{{ "hideTextByDefault" | i18n }}</bit-label>
|
||||||
|
</bit-form-control>
|
||||||
|
</bit-section>
|
||||||
|
|||||||
@@ -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 { 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 { 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({
|
@Component({
|
||||||
selector: "tools-send-text-details",
|
selector: "tools-send-text-details",
|
||||||
template: "send-text-details.component.html",
|
templateUrl: "./send-text-details.component.html",
|
||||||
standalone: true,
|
standalone: true,
|
||||||
|
imports: [
|
||||||
|
CheckboxModule,
|
||||||
|
CommonModule,
|
||||||
|
JslibModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
FormFieldModule,
|
||||||
|
SectionComponent,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class SendTextDetailsComponent {
|
export class SendTextDetailsComponent implements OnInit {
|
||||||
@Input() config: SendFormConfig;
|
@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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
|
|||||||
|
|
||||||
import { SendFormConfig } from "./abstractions/send-form-config.service";
|
import { SendFormConfig } from "./abstractions/send-form-config.service";
|
||||||
import { SendDetailsComponent } from "./components/send-details/send-details.component";
|
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.
|
* 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.
|
* TODO: Add additional form sections as they are implemented.
|
||||||
*/
|
*/
|
||||||
export type SendForm = {
|
export type SendForm = {
|
||||||
sendDetailsForm?: SendDetailsComponent["sendDetailsForm"];
|
sendDetailsForm?: SendDetailsComponent["sendDetailsForm"];
|
||||||
|
sendTextDetailsForm?: SendTextDetailsForm;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user