-
Notifications
You must be signed in to change notification settings - Fork 355
/
RestrictedContainer.tsx
66 lines (56 loc) · 1.54 KB
/
RestrictedContainer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { RouteProps } from "found";
import React, { Component } from "react";
import { graphql } from "react-relay";
import { SetRedirectPathMutation } from "coral-admin/mutations";
import { waitFor } from "coral-common/helpers";
import {
MutationProp,
withFragmentContainer,
withMutation,
} from "coral-framework/lib/relay";
import {
SignOutMutation,
withSignOutMutation,
} from "coral-framework/mutations";
import { RestrictedContainer_viewer as ViewerData } from "coral-admin/__generated__/RestrictedContainer_viewer.graphql";
import Restricted from "./Restricted";
interface Props {
viewer: ViewerData | null;
error?: Error | null;
signOut: SignOutMutation;
setRedirectPath: MutationProp<typeof SetRedirectPathMutation>;
}
class RestrictedContainer extends Component<Props> {
public static routeConfig: RouteProps;
private handleSignInAs = async () => {
await this.props.signOut();
// Wait for new context to propagate.
await waitFor();
void this.props.setRedirectPath({
path: location.pathname + location.search + location.hash,
});
};
public render() {
if (!this.props.viewer) {
return null;
}
return (
<Restricted
username={this.props.viewer.username}
onSignInAs={this.handleSignInAs}
/>
);
}
}
const enhanced = withFragmentContainer<Props>({
viewer: graphql`
fragment RestrictedContainer_viewer on User {
username
}
`,
})(
withMutation(SetRedirectPathMutation)(
withSignOutMutation(RestrictedContainer)
)
);
export default enhanced;