generated from the-collab-lab/smart-shopping-list
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #24 from the-collab-lab/an-sc-issue-6
6. As a user, I want to be able to invite others to an existing shopping list #6
- Loading branch information
Showing
4 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
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,47 @@ | ||
import { useState } from 'react'; | ||
import { shareList } from '../api'; | ||
import { useAuth } from '../api/useAuth.jsx'; | ||
|
||
const InviteForm = ({ listPath, closeModal }) => { | ||
const [input, setInput] = useState(''); | ||
const { user } = useAuth(); | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
try { | ||
const message = await shareList(listPath, user.uid, input); | ||
if (message) { | ||
alert(message); | ||
setInput(''); | ||
closeModal(); | ||
return; | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; | ||
|
||
const handleInputChange = (e) => { | ||
setInput(e.target.value); | ||
}; | ||
return ( | ||
<> | ||
<form onSubmit={handleSubmit}> | ||
<label htmlFor="email"> | ||
Please enter the email of the person you want to invite: | ||
<input | ||
type="email" | ||
name="recipientEmail" | ||
placeholder="[email protected]" | ||
id="email" | ||
value={input} | ||
onChange={handleInputChange} | ||
/> | ||
</label> | ||
<button type="submit">Invite to List</button> | ||
</form> | ||
</> | ||
); | ||
}; | ||
|
||
export default InviteForm; |
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,20 @@ | ||
import React from 'react'; | ||
|
||
const Modal = ({ isOpen, onClose, children }) => { | ||
return ( | ||
<> | ||
{isOpen ? ( | ||
<div className="modal-overlay"> | ||
<div className="modal-content"> | ||
<button className="close-btn" onClick={onClose}> | ||
Close | ||
</button> | ||
{children} | ||
</div> | ||
</div> | ||
) : null} | ||
</> | ||
); | ||
}; | ||
|
||
export default Modal; |
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