generated from the-collab-lab/smart-shopping-list
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from the-collab-lab/jo-hm-createList
- Loading branch information
Showing
7 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useState } from 'react'; | ||
import { createList } from '../api/firebase'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import toast from 'react-hot-toast'; | ||
|
||
export default function CreateShoppingList({ user, setListPath }) { | ||
const [listName, setListName] = useState(''); | ||
const userId = user?.uid; | ||
const userEmail = user?.email; | ||
const navigate = useNavigate(); | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
|
||
try { | ||
const listPath = await createList(userId, userEmail, listName); | ||
setListPath(listPath); | ||
toast.success('List created successfully!'); | ||
navigate('/list'); | ||
} catch (error) { | ||
toast.error('List creation failed. Please try again'); | ||
} | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<label htmlFor="shoppingList">Enter Shopping List name:</label> | ||
<input | ||
id="shoppingList" | ||
type="text" | ||
value={listName} | ||
onChange={(e) => setListName(e.target.value)} | ||
required | ||
/> | ||
<button type="submit">Create Shopping List</button> | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters