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
Sign up to event #104
Changes from 2 commits
451c9bd
6c32cd1
786eaf8
b19d8df
82da026
2a336c8
c85776c
c83f3fe
db23b2c
f75a42e
cdd458a
3dea616
7d82701
748c496
2f21830
6e5a17d
2ee9245
01a5889
0949317
8970016
3e94a79
876a5b1
79a4b05
6423f59
8f02e54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import apiUrl from '../utils/apiUrl'; | ||
|
||
export function defaultFetch(path : string, init? : RequestInit) : Promise<Response> { | ||
const url = apiUrl(path); | ||
return fetch(url, init); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { AppSession } from '../types'; | |
import { getMessages } from './locale'; | ||
import stringToBool from './stringToBool'; | ||
import { ZetkinUser } from '../interfaces/ZetkinUser'; | ||
import { ZetkinZ, ZetkinZResult } from '../types/sdk'; | ||
import { ZetkinZ } from '../types/sdk'; | ||
|
||
//TODO: Create module definition and revert to import. | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
|
@@ -26,7 +26,7 @@ export type ScaffoldedProps = RegularProps & { | |
|
||
export type ScaffoldedContext = GetServerSidePropsContext & { | ||
apiFetch: (path : string, init? : RequestInit) => Promise<Response>; | ||
user: ZetkinZResult | null; | ||
user: unknown; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be typed as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I tried that, but get the following:
|
||
z: ZetkinZ; | ||
}; | ||
|
||
|
@@ -76,7 +76,8 @@ export const scaffold = (wrapped : ScaffoldedGetServerSideProps, options? : Scaf | |
} | ||
|
||
try { | ||
ctx.user = await ctx.z.resource('users', 'me').get(); | ||
const user = await ctx.z.resource('users', 'me').get(); | ||
ctx.user = user.data.data; | ||
} | ||
catch (error) { | ||
ctx.user = null; | ||
|
@@ -104,8 +105,7 @@ export const scaffold = (wrapped : ScaffoldedGetServerSideProps, options? : Scaf | |
}; | ||
|
||
try { | ||
const user = await ctx.z.resource('users', 'me').get(); | ||
augmentProps(user.data.data as ZetkinUser); | ||
augmentProps(ctx.user as ZetkinUser); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look right. The The typecast should also not be necessary, as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, sorry I missed this, looking at it now it's obvious. |
||
} | ||
catch (error) { | ||
augmentProps(null); | ||
|
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.
Why return a function in this function? It should not be necessary to wrap the actual operations of this function in an inner function which is then returned. Just run the code in the body of
putEventResponse
and pass aroundputEventResponse
instead of passing around the return value.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 is a side-effect of the refactoring for server side rendering. But since neither the put or delete functions are run server side I'll revert these back to their previous state (same as you describe).