-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace match.params as props with hooks (#155)
* Install react-router types. * Migrate EventDetailsPage to useParam hook + typescript. * Migrate EventSignInForm to useParam hook + typescript. * Migrate EventRsvpPage to useParam hook + typescript. * Migrate EventEditPage to useParam hook + typescript. * Migrate ProfilePages to hooks + useParams hook. * Add yup typing. * Add @types to dependencies instead of devDep. @types should be in dev dep to prevent build size bloat, but somehow netlify builds fail when @types are not deps. * Modify CardProps to take in className. * Change pages to use new Card component. * Make className optional for cards.
- Loading branch information
1 parent
04abeeb
commit 69b60c3
Showing
25 changed files
with
412 additions
and
571 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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { useParams } from 'react-router'; | ||
|
||
import EventDetailsComponent from './components/EventDetails'; | ||
|
||
import { Loading } from '@SharedComponents'; | ||
import { getEventById } from '@Services/EventService'; | ||
import { EventResponse } from '@Services/api/models'; | ||
|
||
function EventDetailsPage(): JSX.Element { | ||
const { id } = useParams(); | ||
const [eventInfo, setEventInfo] = useState<EventResponse | null>(null); | ||
|
||
useEffect(() => { | ||
const getEvent = async () => { | ||
const eventResponse = await getEventById(id); | ||
setEventInfo(eventResponse); | ||
}; | ||
|
||
getEvent(); | ||
}, [id]); | ||
|
||
return eventInfo == null ? ( | ||
<Loading /> | ||
) : ( | ||
<EventDetailsComponent eventId={id} eventInfo={eventInfo} /> | ||
); | ||
} | ||
|
||
export default EventDetailsPage; |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { useHistory, useParams } from 'react-router'; | ||
|
||
import EventEditForm from './components/EventEditForm'; | ||
|
||
import { Card } from '@SharedComponents'; | ||
import { getEventById, updateEvent } from '@Services/EventService'; | ||
import { EventResponse, EventRequest } from '@Services/api/models'; | ||
|
||
function EventEditPage(): JSX.Element { | ||
const { eventId: id } = useParams(); | ||
const history = useHistory(); | ||
const [event, setEvent] = useState<EventResponse | null>(null); | ||
const [loading, setLoading] = useState<boolean>(true); | ||
|
||
useEffect(() => { | ||
const getEvent = async () => { | ||
const eventResponse = await getEventById(id); | ||
setEvent(eventResponse); | ||
setLoading(false); | ||
}; | ||
getEvent(); | ||
}, [id]); | ||
|
||
const handleCancel = () => { | ||
history.push(`/events/${id}`); | ||
}; | ||
|
||
const handleSubmit = async ( | ||
values: EventRequest, | ||
setSubmitting: (_: boolean) => void | ||
) => { | ||
const eventRequest: EventRequest = { | ||
...values, | ||
hosts: values.hosts.map(host => { | ||
return { | ||
id: host.id, | ||
}; | ||
}), | ||
}; | ||
|
||
await updateEvent(id, eventRequest); | ||
setSubmitting(false); | ||
history.push(`/events/${id}`); | ||
}; | ||
|
||
if (loading) { | ||
return <></>; | ||
} | ||
return ( | ||
<Card> | ||
<EventEditForm | ||
handleSubmit={handleSubmit} | ||
handleCancel={handleCancel} | ||
initialValues={event} | ||
/> | ||
</Card> | ||
); | ||
} | ||
|
||
export default EventEditPage; |
6 changes: 3 additions & 3 deletions
6
src/pages/EventEditPage/index.js → src/pages/EventEditPage/index.ts
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,3 +1,3 @@ | ||
import EventEditPage from './event_edit'; | ||
|
||
export default EventEditPage; | ||
import EventEditPage from './event_edit'; | ||
|
||
export default EventEditPage; |
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
Oops, something went wrong.