mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 00:48:25 +00:00
parent
2f6d384621
commit
5e9366bfe4
3 changed files with 6 additions and 22 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useRef, useEffect, useState } from 'react';
|
||||
import { ToolTip } from '@/_components';
|
||||
import { appService } from '@/_services';
|
||||
import { handleHttpErrorMessages, validateAppName, validateName } from '@/_helpers/utils';
|
||||
import { handleHttpErrorMessages, validateName } from '@/_helpers/utils';
|
||||
import InfoOrErrorBox from './InfoOrErrorBox';
|
||||
import { toast } from 'react-hot-toast';
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ function EditAppName({ appId, appName = '', onNameChanged }) {
|
|||
|
||||
const saveAppName = async (newName) => {
|
||||
const trimmedName = newName.trim();
|
||||
if (validateName(trimmedName, 'App name', true)?.errorMsg) {
|
||||
if (validateName(trimmedName, 'App', false, true)?.errorMsg) {
|
||||
setName(appName);
|
||||
clearError();
|
||||
setIsEditing(false);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { toast } from 'react-hot-toast';
|
|||
import Modal from '../HomePage/Modal';
|
||||
import { ButtonSolid } from '@/_ui/AppButton/AppButton';
|
||||
import _ from 'lodash';
|
||||
import { validateAppName } from '@/_helpers/utils';
|
||||
import { validateName } from '@/_helpers/utils';
|
||||
|
||||
export function AppModal({
|
||||
closeModal,
|
||||
|
|
@ -105,7 +105,7 @@ export function AppModal({
|
|||
setInfoText('Maximum length has been reached');
|
||||
} else {
|
||||
setInfoText('');
|
||||
const error = validateAppName(trimmedName);
|
||||
const error = validateName(trimmedName, 'App', false);
|
||||
setErrorText(error?.errorMsg || '');
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -920,26 +920,10 @@ export function isExpectedDataType(data, expectedDataType) {
|
|||
return data;
|
||||
}
|
||||
|
||||
export const validateAppName = (name, showError = false) => {
|
||||
export const validateName = (name, nameType, emptyCheck = true, showError = false, allowSpecialChars = true) => {
|
||||
const newName = name.trim();
|
||||
let errorMsg = '';
|
||||
if (newName.length > 50) {
|
||||
errorMsg = `Maximum length has been reached`;
|
||||
showError &&
|
||||
toast.error(errorMsg, {
|
||||
id: '1',
|
||||
});
|
||||
}
|
||||
return {
|
||||
status: !(errorMsg.length > 0),
|
||||
errorMsg,
|
||||
};
|
||||
};
|
||||
|
||||
export const validateName = (name, nameType, showError = false, allowSpecialChars = true) => {
|
||||
const newName = name.trim();
|
||||
let errorMsg = '';
|
||||
if (!newName) {
|
||||
if (emptyCheck && !newName) {
|
||||
errorMsg = `${nameType} can't be empty`;
|
||||
showError &&
|
||||
toast.error(errorMsg, {
|
||||
|
|
|
|||
Loading…
Reference in a new issue