Skip to content

Commit

Permalink
Merge pull request #37 from the-collab-lab/ce-ju--dublicate-list-alert
Browse files Browse the repository at this point in the history
Ce ju  dublicate list alert
  • Loading branch information
BikeMouse authored Mar 22, 2024
2 parents d1aee86 + b186b28 commit c1ba6b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/ListForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ import { useState } from 'react';
import { createList } from '../api';
import { useNavigate } from 'react-router-dom';
import { inputHasValue } from '../utils/inputValidation';
import { stringsHaveSameValue } from '../utils/inputValidation';

const ListForm = (props) => {
const { setMessage, setListPath, userId, userEmail } = props;
const { setMessage, setListPath, userId, userEmail, data } = props;
const [newList, setNewList] = useState('');
const navigate = useNavigate();

const checkNameNewList = (newList) => {
if (data.some((item) => stringsHaveSameValue(newList, item.name))) {
return true;
}
};

const handleSubmit = async (event) => {
event.preventDefault();

Expand All @@ -16,6 +23,11 @@ const ListForm = (props) => {
setNewList('');
return;
}
if (checkNameNewList(newList)) {
setMessage('A List with this name already exists');
setNewList('');
return;
}

try {
const response = await createList(userId, userEmail, newList);
Expand Down
1 change: 1 addition & 0 deletions src/views/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function Home({ data, setListPath, userId, userEmail }) {
setListPath={setListPath}
userId={userId}
userEmail={userEmail}
data={data}
/>
{message !== '' && <ErrorMessage errorMessage={message} />}
</div>
Expand Down

0 comments on commit c1ba6b6

Please sign in to comment.