mirror of
https://github.com/Skyvern-AI/skyvern.git
synced 2025-09-02 18:50:24 +00:00
Show error for empty fields in credential creation (#1935)
This commit is contained in:
parent
4c6a65059f
commit
43daf3da48
1 changed files with 55 additions and 12 deletions
|
@ -86,21 +86,64 @@ function CredentialsModal({ onCredentialCreated }: Props) {
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
|
const name =
|
||||||
|
type === CredentialModalTypes.PASSWORD
|
||||||
|
? passwordCredentialValues.name.trim()
|
||||||
|
: creditCardCredentialValues.name.trim();
|
||||||
|
if (name === "") {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: "Name is required",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (type === CredentialModalTypes.PASSWORD) {
|
if (type === CredentialModalTypes.PASSWORD) {
|
||||||
|
const username = passwordCredentialValues.username.trim();
|
||||||
|
const password = passwordCredentialValues.password.trim();
|
||||||
|
const totp = passwordCredentialValues.totp.trim();
|
||||||
|
|
||||||
|
if (username === "" || password === "") {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: "Username and password are required",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
createCredentialMutation.mutate({
|
createCredentialMutation.mutate({
|
||||||
name: passwordCredentialValues.name,
|
name,
|
||||||
credential_type: "password",
|
credential_type: "password",
|
||||||
credential: {
|
credential: {
|
||||||
username: passwordCredentialValues.username,
|
username,
|
||||||
password: passwordCredentialValues.password,
|
password,
|
||||||
totp:
|
totp: totp === "" ? null : totp,
|
||||||
passwordCredentialValues.totp === ""
|
|
||||||
? null
|
|
||||||
: passwordCredentialValues.totp,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (type === CredentialModalTypes.CREDIT_CARD) {
|
} else if (type === CredentialModalTypes.CREDIT_CARD) {
|
||||||
const cardExpirationDate = creditCardCredentialValues.cardExpirationDate;
|
const cardNumber = creditCardCredentialValues.cardNumber.trim();
|
||||||
|
const cardCode = creditCardCredentialValues.cardCode.trim();
|
||||||
|
const cardExpirationDate =
|
||||||
|
creditCardCredentialValues.cardExpirationDate.trim();
|
||||||
|
const cardBrand = creditCardCredentialValues.cardBrand.trim();
|
||||||
|
const cardHolderName = creditCardCredentialValues.cardHolderName.trim();
|
||||||
|
|
||||||
|
if (
|
||||||
|
cardNumber === "" ||
|
||||||
|
cardCode === "" ||
|
||||||
|
cardExpirationDate === "" ||
|
||||||
|
cardBrand === "" ||
|
||||||
|
cardHolderName === ""
|
||||||
|
) {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: "All credit card fields are required",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const cardExpirationDateParts = cardExpirationDate.split("/");
|
const cardExpirationDateParts = cardExpirationDate.split("/");
|
||||||
if (cardExpirationDateParts.length !== 2) {
|
if (cardExpirationDateParts.length !== 2) {
|
||||||
toast({
|
toast({
|
||||||
|
@ -123,15 +166,15 @@ function CredentialsModal({ onCredentialCreated }: Props) {
|
||||||
// remove all spaces from the card number
|
// remove all spaces from the card number
|
||||||
const number = creditCardCredentialValues.cardNumber.replace(/\s/g, "");
|
const number = creditCardCredentialValues.cardNumber.replace(/\s/g, "");
|
||||||
createCredentialMutation.mutate({
|
createCredentialMutation.mutate({
|
||||||
name: creditCardCredentialValues.name,
|
name,
|
||||||
credential_type: "credit_card",
|
credential_type: "credit_card",
|
||||||
credential: {
|
credential: {
|
||||||
card_number: number,
|
card_number: number,
|
||||||
card_cvv: creditCardCredentialValues.cardCode,
|
card_cvv: cardCode,
|
||||||
card_exp_month: cardExpirationMonth,
|
card_exp_month: cardExpirationMonth,
|
||||||
card_exp_year: cardExpirationYear,
|
card_exp_year: cardExpirationYear,
|
||||||
card_brand: creditCardCredentialValues.cardBrand,
|
card_brand: cardBrand,
|
||||||
card_holder_name: creditCardCredentialValues.cardHolderName,
|
card_holder_name: cardHolderName,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue