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 branch 'main' into bb/navbar-auth-status
- Loading branch information
Showing
8 changed files
with
142 additions
and
14 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,35 @@ | ||
import { ChangeEvent, FormEvent } from "react"; | ||
|
||
interface FilterListProps { | ||
searchTerm: string; | ||
setSearchTerm: (term: string) => void; | ||
} | ||
|
||
export function FilterListInput({ | ||
searchTerm, | ||
setSearchTerm, | ||
}: FilterListProps) { | ||
const handleChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setSearchTerm(e.target.value); | ||
}; | ||
|
||
const handleSubmit = (e: FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<label htmlFor="filterList"> | ||
Filter List: | ||
<input | ||
type="search" | ||
onChange={handleChange} | ||
value={searchTerm} | ||
id="filterList" | ||
aria-label="Filter items in the list" | ||
placeholder="Search items..." | ||
/> | ||
</label> | ||
</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,74 @@ | ||
import { ChangeEvent, FormEvent, useState } from "react"; | ||
import { shareList } from "../../api/firebase"; | ||
|
||
import toast from "react-hot-toast"; | ||
|
||
import { useAuth } from "../../api/useAuth"; | ||
|
||
import { User } from "../../api/firebase"; | ||
|
||
interface Props { | ||
listPath: string | null; | ||
} | ||
|
||
const ShareListForm = ({ listPath }: Props) => { | ||
const { user: currentUser } = useAuth(); | ||
|
||
const [emailName, setEmailName] = useState(""); | ||
|
||
const handleEmailNameChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setEmailName(e.target.value); | ||
}; | ||
|
||
const handleInvite = async ( | ||
e: FormEvent<HTMLFormElement>, | ||
listPath: string | null, | ||
) => { | ||
console.log("Button clicked! Inviting user!"); | ||
e.preventDefault(); | ||
|
||
if (!listPath) { | ||
return; | ||
} | ||
|
||
try { | ||
await toast.promise(shareList(listPath, currentUser as User, emailName), { | ||
loading: "sharing list with existing user", | ||
success: () => { | ||
setEmailName(""); | ||
return `Successfully invited ${emailName} to your list!`; | ||
}, | ||
error: () => { | ||
return `Oops! Failed to invite ${emailName} to your list. Please verify correct email!`; | ||
}, | ||
}); | ||
} catch (error) { | ||
console.error("Oops! Failed to invite user:", error); | ||
} | ||
}; | ||
|
||
return ( | ||
<form onSubmit={(e) => handleInvite(e, listPath)}> | ||
<label htmlFor="recipient-email"> | ||
Recipient Email: | ||
<input | ||
id="recipient-email" | ||
type="email" | ||
name="recipient-email" | ||
value={emailName} | ||
placeholder="Enter e-mail address. . ." | ||
onChange={handleEmailNameChange} | ||
required | ||
aria-label="Enter the user email address to share list" | ||
aria-required | ||
/> | ||
</label> | ||
<br /> | ||
<button type="submit" aria-label="submits form to share shopping list"> | ||
Invite User | ||
</button> | ||
</form> | ||
); | ||
}; | ||
|
||
export default ShareListForm; |
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