-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sign up to event #104
Merged
Merged
Sign up to event #104
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
451c9bd
Add sign-up functionality for event
kristofferlarberg 6c32cd1
Refactor fetch functions, change name for DELETE function
kristofferlarberg 786eaf8
Remove undefined from prop types and move non-null assertion to org p…
kristofferlarberg b19d8df
Remove eslint-disable from EventList
kristofferlarberg 82da026
Update cache when response PUT/DELETE and conditionally render signup…
kristofferlarberg 2a336c8
Refactor functionality and general structure for conditional sign-up …
kristofferlarberg c85776c
Add login procedure in button test
kristofferlarberg c83f3fe
Remove unnecessary spies
kristofferlarberg db23b2c
Refactor useMutation functionality to reusable hook
kristofferlarberg f75a42e
Make small changes in integration and component tests for events page…
kristofferlarberg cdd458a
Include eventResponses in useOnEventResponse
kristofferlarberg 3dea616
Add TODO
kristofferlarberg 7d82701
Apply useEventResponses on event page
kristofferlarberg 748c496
Add space before block
kristofferlarberg 2f21830
Merge branch 'main' into issue-93/sign-up-to-event
kristofferlarberg 6e5a17d
Make integration-tests for events/event pages less flaky
kristofferlarberg 2ee9245
Merge branch 'issue-93/sign-up-to-event' of https://github.com/zetkin…
kristofferlarberg 01a5889
Add user attribute to context
kristofferlarberg 0949317
Refactor events/event page related fetch functions and conditionally …
kristofferlarberg 8970016
Adjust integration tests for sign-up button
kristofferlarberg 3e94a79
Move user attribute to after reqWithSession, remove else stement for …
kristofferlarberg 876a5b1
Make defaultFetch shared module, remove fetch injection in put- and d…
kristofferlarberg 79a4b05
Extract user data object as ctx.user and reuse with augmentProps
kristofferlarberg 6423f59
Refactor back putEventResponse and deleteEventResponse to not returni…
kristofferlarberg 8f02e54
Add type assertion to user object, remove augmentProps function
kristofferlarberg File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,17 +1,29 @@ | ||
import apiUrl from '../utils/apiUrl'; | ||
|
||
import { ZetkinEventSignup, ZetkinMembership } from '../types/zetkin'; | ||
import { ZetkinMembership } from '../types/zetkin'; | ||
|
||
export default async function deleteEventResponse({ eventId, orgId } : ZetkinEventSignup) : Promise<void> { | ||
const mUrl = apiUrl('/users/me/memberships'); | ||
const mRes = await fetch(mUrl); | ||
const mData = await mRes.json(); | ||
const orgMembership = mData.data.find((m : ZetkinMembership) => m.organization.id === orgId); | ||
function defaultFetch(path : string, init? : RequestInit) { | ||
const url = apiUrl(path); | ||
return fetch(url, init); | ||
} | ||
|
||
if (orgMembership) { | ||
const url = apiUrl(`/orgs/${orgId}/actions/${eventId}/responses/${orgMembership.profile.id}`); | ||
await fetch(url, { | ||
method: 'DELETE', | ||
}); | ||
} | ||
interface MutationVariables { | ||
eventId: number; | ||
orgId: number; | ||
} | ||
|
||
export default function deleteEventResponse(fetch = defaultFetch) { | ||
return async ({ eventId, orgId } : MutationVariables) : Promise<void> => { | ||
const mRes = await fetch('/users/me/memberships'); | ||
const mData = await mRes.json(); | ||
//TODO: Memberships should be cached. | ||
const orgMembership = mData.data.find((m : ZetkinMembership ) => m.organization.id === orgId); | ||
|
||
if (orgMembership) { | ||
await fetch(`/orgs/${orgId}/actions/${eventId}/responses/${orgMembership.profile.id}`, { | ||
method: 'DELETE', | ||
}); | ||
} | ||
}; | ||
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reoccurs in many locations, and should probably moved to a shared module and reused. Perhaps in
src/fetching/index.ts
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree!