mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 06:13:38 +00:00
PM-17187 Autofill new card information in the popout (#13688)
This commit is contained in:
@@ -440,6 +440,32 @@ const mapAddEditCipherInfoToInitialValues = (
|
|||||||
initialValues.name = cipher.name;
|
initialValues.name = cipher.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cipher.type === CipherType.Card) {
|
||||||
|
const card = cipher.card;
|
||||||
|
|
||||||
|
if (card != null) {
|
||||||
|
if (card.cardholderName != null) {
|
||||||
|
initialValues.cardholderName = card.cardholderName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (card.number != null) {
|
||||||
|
initialValues.number = card.number;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (card.expMonth != null) {
|
||||||
|
initialValues.expMonth = card.expMonth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (card.expYear != null) {
|
||||||
|
initialValues.expYear = card.expYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (card.code != null) {
|
||||||
|
initialValues.code = card.code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cipher.type === CipherType.Login) {
|
if (cipher.type === CipherType.Login) {
|
||||||
const login = cipher.login;
|
const login = cipher.login;
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ export type OptionalInitialValues = {
|
|||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
|
cardholderName?: string;
|
||||||
|
number?: string;
|
||||||
|
expMonth?: string;
|
||||||
|
expYear?: string;
|
||||||
|
code?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ describe("CardDetailsSectionComponent", () => {
|
|||||||
cardView.cardholderName = "Ron Burgundy";
|
cardView.cardholderName = "Ron Burgundy";
|
||||||
cardView.number = "4242 4242 4242 4242";
|
cardView.number = "4242 4242 4242 4242";
|
||||||
cardView.brand = "Visa";
|
cardView.brand = "Visa";
|
||||||
|
cardView.expMonth = "";
|
||||||
|
cardView.code = "";
|
||||||
|
|
||||||
expect(patchCipherSpy).toHaveBeenCalled();
|
expect(patchCipherSpy).toHaveBeenCalled();
|
||||||
const patchFn = patchCipherSpy.mock.lastCall[0];
|
const patchFn = patchCipherSpy.mock.lastCall[0];
|
||||||
@@ -79,6 +81,10 @@ describe("CardDetailsSectionComponent", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const cardView = new CardView();
|
const cardView = new CardView();
|
||||||
|
cardView.cardholderName = "";
|
||||||
|
cardView.number = "";
|
||||||
|
cardView.expMonth = "";
|
||||||
|
cardView.code = "";
|
||||||
cardView.expYear = "2022";
|
cardView.expYear = "2022";
|
||||||
|
|
||||||
expect(patchCipherSpy).toHaveBeenCalled();
|
expect(patchCipherSpy).toHaveBeenCalled();
|
||||||
|
|||||||
@@ -97,6 +97,10 @@ export class CardDetailsSectionComponent implements OnInit {
|
|||||||
|
|
||||||
EventType = EventType;
|
EventType = EventType;
|
||||||
|
|
||||||
|
get initialValues() {
|
||||||
|
return this.cipherFormContainer.config.initialValues;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private cipherFormContainer: CipherFormContainer,
|
private cipherFormContainer: CipherFormContainer,
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
@@ -139,7 +143,9 @@ export class CardDetailsSectionComponent implements OnInit {
|
|||||||
const prefillCipher = this.cipherFormContainer.getInitialCipherView();
|
const prefillCipher = this.cipherFormContainer.getInitialCipherView();
|
||||||
|
|
||||||
if (prefillCipher) {
|
if (prefillCipher) {
|
||||||
this.setInitialValues(prefillCipher);
|
this.initFromExistingCipher(prefillCipher.card);
|
||||||
|
} else {
|
||||||
|
this.initNewCipher();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.disabled) {
|
if (this.disabled) {
|
||||||
@@ -147,6 +153,26 @@ export class CardDetailsSectionComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private initFromExistingCipher(existingCard: CardView) {
|
||||||
|
this.cardDetailsForm.patchValue({
|
||||||
|
cardholderName: this.initialValues?.cardholderName ?? existingCard.cardholderName,
|
||||||
|
number: this.initialValues?.number ?? existingCard.number,
|
||||||
|
expMonth: this.initialValues?.expMonth ?? existingCard.expMonth,
|
||||||
|
expYear: this.initialValues?.expYear ?? existingCard.expYear,
|
||||||
|
code: this.initialValues?.code ?? existingCard.code,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private initNewCipher() {
|
||||||
|
this.cardDetailsForm.patchValue({
|
||||||
|
cardholderName: this.initialValues?.cardholderName || "",
|
||||||
|
number: this.initialValues?.number || "",
|
||||||
|
expMonth: this.initialValues?.expMonth || "",
|
||||||
|
expYear: this.initialValues?.expYear || "",
|
||||||
|
code: this.initialValues?.code || "",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** Get the section heading based on the card brand */
|
/** Get the section heading based on the card brand */
|
||||||
getSectionHeading(): string {
|
getSectionHeading(): string {
|
||||||
const { brand } = this.cardDetailsForm.value;
|
const { brand } = this.cardDetailsForm.value;
|
||||||
|
|||||||
Reference in New Issue
Block a user