-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New team page * Add team to output jsons * Add save shortcut to all forms * Add save shortcut to all forms
- Loading branch information
1 parent
329ff6f
commit 54868c0
Showing
22 changed files
with
418 additions
and
9 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,16 @@ | ||
import { useHotkeys } from 'react-hotkeys-hook' | ||
import { useRef } from 'react' | ||
|
||
export const SaveShortcut = () => { | ||
const ref = useRef(null) | ||
useHotkeys(['ctrl+s', 'meta+s'], (event) => { | ||
event.preventDefault() | ||
// @ts-ignore | ||
const form = ref.current?.closest('form') | ||
if (form) { | ||
form.dispatchEvent(new Event('submit', { cancelable: true, bubbles: true })) | ||
} | ||
}) | ||
|
||
return <div ref={ref}></div> | ||
} |
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,11 @@ | ||
import { TeamMember } from '../../types' | ||
import { getDocs } from 'firebase/firestore' | ||
import { collections } from '../../services/firebase' | ||
|
||
export const getTeam = async (eventId: string): Promise<TeamMember[]> => { | ||
const snapshots = await getDocs(collections.team(eventId)) | ||
|
||
return snapshots.docs.map((snapshot) => ({ | ||
...snapshot.data(), | ||
})) | ||
} |
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
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,55 @@ | ||
import * as React from 'react' | ||
import { Box, Button, Card, Container, Link, Typography } from '@mui/material' | ||
import { ArrowBack } from '@mui/icons-material' | ||
import { useLocation, useRoute } from 'wouter' | ||
import { doc } from 'firebase/firestore' | ||
import { collections } from '../../../services/firebase' | ||
import { FirestoreQueryLoaderAndErrorDisplay } from '../../../components/FirestoreQueryLoaderAndErrorDisplay' | ||
import { MemberForm } from './components/MemberForm' | ||
import { useFirestoreDocumentMutation } from '../../../services/hooks/firestoreMutationHooks' | ||
import { useTeam } from '../../../services/hooks/useTeam' | ||
import { Event, TeamMember } from '../../../types' | ||
|
||
export type EventMemberProps = { | ||
event: Event | ||
} | ||
export const EventMember = ({ event }: EventMemberProps) => { | ||
const [_, params] = useRoute('/:routeName/:memberId*') | ||
const members = useTeam(event.id) | ||
const [_2, setLocation] = useLocation() | ||
|
||
const memberId = params?.memberId | ||
|
||
const mutation = useFirestoreDocumentMutation(doc(collections.team(event.id), memberId)) | ||
|
||
if (members.isLoading || !members.data) { | ||
return <FirestoreQueryLoaderAndErrorDisplay hookResult={members} /> | ||
} | ||
|
||
const member = members.data.find((s: TeamMember) => s.id === memberId) | ||
|
||
if (!member) { | ||
setLocation('/team') | ||
} | ||
|
||
return ( | ||
<Container maxWidth="lg" sx={{ mt: 4, mb: 4 }} key={memberId}> | ||
<Box display="flex" justifyContent="space-between" mt={2}> | ||
<Button startIcon={<ArrowBack />} component={Link} href="/team"> | ||
All members | ||
</Button> | ||
</Box> | ||
<Card sx={{ paddingX: 2 }}> | ||
<Typography variant="h2">{member.name}</Typography> | ||
|
||
<MemberForm | ||
event={event} | ||
member={member} | ||
onSubmit={async (data) => { | ||
await mutation.mutate(data) | ||
}} | ||
/> | ||
</Card> | ||
</Container> | ||
) | ||
} |
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 { Event, TeamMember } from '../../../types' | ||
import * as React from 'react' | ||
import { FirestoreQueryLoaderAndErrorDisplay } from '../../../components/FirestoreQueryLoaderAndErrorDisplay' | ||
import { Box, Button, Card, Container, Typography } from '@mui/material' | ||
import { useTeam } from '../../../services/hooks/useTeam' | ||
import { Member } from './components/Member' | ||
|
||
export type EventTeamProps = { | ||
event: Event | ||
} | ||
export const EventTeam = ({ event }: EventTeamProps) => { | ||
const team = useTeam(event.id) | ||
|
||
const teamData = team.data || [] | ||
|
||
if (team.isLoading) { | ||
return <FirestoreQueryLoaderAndErrorDisplay hookResult={team} /> | ||
} | ||
|
||
return ( | ||
<Container maxWidth="lg" sx={{ mt: 4, mb: 4 }}> | ||
<Box display="flex" justifyContent="space-between" alignItems="center" marginBottom={1}> | ||
<Typography>{team.data?.length} members</Typography> | ||
<Box marginY={2}> | ||
<Button href={`/team/new`}>Add member</Button> | ||
</Box> | ||
</Box> | ||
<Card sx={{ padding: 2, minHeight: '50vh', display: 'flex', flexDirection: 'column', flexFlow: 'row' }}> | ||
{teamData.map((member: TeamMember) => ( | ||
<Member key={member.id} member={member} event={event} /> | ||
))} | ||
</Card> | ||
<Box marginY={2}> | ||
<Button href={`/team/new`}>Add member</Button> | ||
</Box> | ||
</Container> | ||
) | ||
} |
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,41 @@ | ||
import * as React from 'react' | ||
import { useLocation } from 'wouter' | ||
import { collections } from '../../../services/firebase' | ||
import { Button, Card, Container, Typography } from '@mui/material' | ||
import { ArrowBack } from '@mui/icons-material' | ||
import { Event } from '../../../types' | ||
import { MemberForm } from './components/MemberForm' | ||
import { useFirestoreCollectionMutation } from '../../../services/hooks/firestoreMutationHooks' | ||
import { slugify } from '../../../utils/slugify' | ||
|
||
export type NewMemberProps = { | ||
event: Event | ||
} | ||
export const NewMember = ({ event }: NewMemberProps) => { | ||
const [_, setLocation] = useLocation() | ||
const mutation = useFirestoreCollectionMutation(collections.team(event.id)) | ||
|
||
return ( | ||
<Container maxWidth="lg" sx={{ mt: 4, mb: 4 }}> | ||
<Button href="/team" startIcon={<ArrowBack />}> | ||
Cancel | ||
</Button> | ||
<Card sx={{ paddingX: 2 }}> | ||
<Typography variant="h2">New member</Typography> | ||
|
||
<MemberForm | ||
event={event} | ||
onSubmit={(member) => { | ||
return mutation.mutate(member, slugify(member.name)).then(() => { | ||
setLocation('/team') | ||
}) | ||
}} | ||
/> | ||
|
||
{mutation.isError && ( | ||
<Typography color="error">Error while adding member: {mutation.error?.message}</Typography> | ||
)} | ||
</Card> | ||
</Container> | ||
) | ||
} |
Oops, something went wrong.