Skip to content

Commit

Permalink
common imports for constants
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravsinhaweb committed Oct 28, 2023
1 parent 1057569 commit 4c032b0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
8 changes: 2 additions & 6 deletions src/pages/dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useState } from 'react';
import Button from '@/components/Button';
import InputBox from '@/components/InputBox';
import Layout from '@/components/Layout';
import { randomString } from '@/utils/constants';
import { useState } from 'react';
import AddIcon from '../../../public/assets/icons/add';
import CopyIcon from '../../../public/assets/icons/copy';
import ReloadIcon from '../../../public/assets/icons/reload';
Expand All @@ -10,12 +11,7 @@ const Dashboard = () => {
const [url, getUrl] = useState<string>('');
const [shortUrl, setUrl] = useState<string>('');

function generateRandomString() {
const randomString = Math.random().toString(36).substring(2, 7);
return randomString;
}
const handleUniqueUrl = () => {
const randomString = generateRandomString();
setUrl(`https://rds.li/${randomString}`);
};
return (
Expand Down
3 changes: 2 additions & 1 deletion src/pages/login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Button from '@/components/Button';
import InputBox from '@/components/InputBox';
import Layout from '@/components/Layout';
import { alphanumicUnderscore } from '@/utils/constants';
import { ChangeEvent, SetStateAction, useState } from 'react';

const LoginPage = () => {
Expand All @@ -12,7 +13,7 @@ const LoginPage = () => {

const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
const inputValue = (event.target as HTMLInputElement).value;
const alphanumicUnderscore = /^[a-zA-Z0-9_]+$/;

if (event.target.name === 'username') {
if (alphanumicUnderscore.test(inputValue)) {
setUsernameBorder(' border-2 border-green-500');
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const alphanumicUnderscore = /^[a-zA-Z0-9_]+$/;
export const randomString = Math.random().toString(36).substring(2, 7);

0 comments on commit 4c032b0

Please sign in to comment.