mirror of
https://github.com/thedevs-network/kutt-extension.git
synced 2026-02-03 13:53:23 +00:00
fix: validate & add customurl & password fields as optional
This commit is contained in:
@@ -11,8 +11,8 @@ import api from '../api';
|
||||
|
||||
export type ShortenUrlBodyProperties = {
|
||||
target: string;
|
||||
password: string;
|
||||
customurl: string;
|
||||
password?: string;
|
||||
customurl?: string;
|
||||
reuse: boolean;
|
||||
domain: string;
|
||||
};
|
||||
|
||||
@@ -82,11 +82,11 @@ const PopupForm = withFormik<PopupFormProperties, FormValuesProperties>({
|
||||
validate: (values: FormValuesProperties) => {
|
||||
const errors: FormikErrors<FormValuesProperties> = {};
|
||||
|
||||
if (values.password && values.password.length < 3) {
|
||||
if (values.password && values.password.trim().length < 3) {
|
||||
errors.password = 'Password must be atleast 3 characters';
|
||||
}
|
||||
|
||||
if (values.customurl && values.customurl.length < 3) {
|
||||
if (values.customurl && values.customurl.trim().length < 3) {
|
||||
errors.customurl = 'Custom URL must be atleast 3 characters';
|
||||
}
|
||||
|
||||
@@ -94,14 +94,15 @@ const PopupForm = withFormik<PopupFormProperties, FormValuesProperties>({
|
||||
},
|
||||
|
||||
handleSubmit: async (values: FormValuesProperties, { setSubmitting }: FormikHelpers<FormValuesProperties>) => {
|
||||
console.log(values);
|
||||
setSubmitting(false);
|
||||
const { customurl, password, domain } = values;
|
||||
|
||||
const data: ShortenUrlBodyProperties = {
|
||||
// ToDo: get target link from browser.tabs
|
||||
target: 'https://long-url.com',
|
||||
reuse: false,
|
||||
...values,
|
||||
...(customurl.trim() !== '' && { customurl: customurl.trim() }), // add this key if field is not empty
|
||||
...(password.trim() !== '' && { password: password.trim() }),
|
||||
domain, // ToDo: validate this
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -109,6 +110,8 @@ const PopupForm = withFormik<PopupFormProperties, FormValuesProperties>({
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
setSubmitting(false);
|
||||
},
|
||||
|
||||
displayName: 'PopupForm',
|
||||
|
||||
Reference in New Issue
Block a user