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 #22 from the-collab-lab/hm-mm-shareList
- Loading branch information
Showing
5 changed files
with
118 additions
and
70 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
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,57 @@ | ||
import { useState } from 'react'; | ||
import { addItem } from '../../api/firebase'; | ||
|
||
export default function AddItemForm({ listPath }) { | ||
const [formData, setFormData] = useState({ | ||
itemName: '', | ||
daysUntilNextPurchase: '', | ||
}); | ||
|
||
const handleSubmit = async (event) => { | ||
try { | ||
event.preventDefault(); | ||
await addItem(listPath, formData); | ||
alert(`${formData.itemName} was added to the list successfully`); | ||
} catch (error) { | ||
alert(`There was a problem adding ${formData.itemName} to the list`); | ||
} | ||
}; | ||
|
||
const handleChange = (event) => { | ||
let { name, value } = event.target; | ||
setFormData((prevFormData) => ({ ...prevFormData, [name]: value })); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={(event) => handleSubmit(event)}> | ||
<div className="item-name"> | ||
<label htmlFor="itemName">Enter the item name: </label> | ||
<input | ||
type="text" | ||
name="itemName" | ||
id="itemName" | ||
required | ||
value={formData.itemName} | ||
onChange={handleChange} | ||
/> | ||
</div> | ||
<div className="buy-again"> | ||
<label htmlFor="daysUntilNextPurchase"> | ||
When do you think you will need to purchase this item again? | ||
</label> | ||
<select | ||
name="daysUntilNextPurchase" | ||
id="daysUntilNextPurchase" | ||
value={formData.daysUntilNextPurchase} | ||
onChange={handleChange} | ||
> | ||
<option value="">Select Time</option> | ||
<option value="7">Soon (7 days)</option> | ||
<option value="14">Kind of soon (14 days)</option> | ||
<option value="30">Not soon (30 days)</option> | ||
</select> | ||
</div> | ||
<button type="submit">Add Item</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useState } from 'react'; | ||
import { shareList } from '../../api'; | ||
|
||
export default function ShareListForm({ listPath, user }) { | ||
const [recipientEmail, setRecipientEmail] = useState(''); | ||
const currentUserId = user?.uid; | ||
|
||
const handleSubmit = async (event) => { | ||
event.preventDefault(); | ||
await shareList(listPath, currentUserId, recipientEmail); | ||
setRecipientEmail(''); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={(event) => handleSubmit(event)}> | ||
<label htmlFor="email">Invite a user by email: </label> | ||
<input | ||
type="text" | ||
id="email" | ||
required | ||
value={recipientEmail} | ||
onChange={(e) => setRecipientEmail(e.target.value)} | ||
/> | ||
<button type="submit">Invite</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,11 @@ | ||
import { useState } from 'react'; | ||
import { addItem } from '../api/firebase'; | ||
export function ManageList({ listPath }) { | ||
const [formData, setFormData] = useState({ | ||
itemName: '', | ||
daysUntilNextPurchase: '', | ||
}); | ||
|
||
const handleSubmit = async (event) => { | ||
try { | ||
event.preventDefault(); | ||
await addItem(listPath, formData); | ||
alert(`${formData.itemName} was added to the list successfully`); | ||
} catch (error) { | ||
alert(`There was a problem adding ${formData.itemName} to the list`); | ||
} | ||
}; | ||
|
||
const handleChange = (event) => { | ||
let { name, value } = event.target; | ||
setFormData((prevFormData) => ({ ...prevFormData, [name]: value })); | ||
}; | ||
import AddItemForm from '../components/ManageListForms/AddItemForm'; | ||
import ShareListForm from '../components/ManageListForms/ShareListForm'; | ||
|
||
export function ManageList({ listPath, user }) { | ||
return ( | ||
<form onSubmit={(event) => handleSubmit(event)}> | ||
<div className="item-name"> | ||
<label htmlFor="itemName">Enter the item name: </label> | ||
<input | ||
type="text" | ||
name="itemName" | ||
id="itemName" | ||
required | ||
value={formData.itemName} | ||
onChange={handleChange} | ||
/> | ||
</div> | ||
<div className="buy-again"> | ||
<label htmlFor="daysUntilNextPurchase"> | ||
When do you think you will need to purchase this item again? | ||
</label> | ||
<select | ||
name="daysUntilNextPurchase" | ||
id="daysUntilNextPurchase" | ||
value={formData.daysUntilNextPurchase} | ||
onChange={handleChange} | ||
> | ||
<option value="">Select Time</option> | ||
<option value="7">Soon (7 days)</option> | ||
<option value="14">Kind of soon (14 days)</option> | ||
<option value="30">Not soon (30 days)</option> | ||
</select> | ||
</div> | ||
<button type="submit">Add Item</button> | ||
</form> | ||
<div> | ||
<AddItemForm listPath={listPath} /> | ||
<ShareListForm listPath={listPath} user={user} /> | ||
</div> | ||
); | ||
} |