Revamp: Remove duplicate function (#7937)

* revamp

* update
This commit is contained in:
Anantshree Chandola 2023-10-17 23:54:53 +05:30 committed by GitHub
parent 2f6d384621
commit 5e9366bfe4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 22 deletions

View file

@ -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);

View file

@ -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 || '');
}
};

View file

@ -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, {