mirror of
https://github.com/wassname/talk.git
synced 2026-07-08 07:46:34 +08:00
SignOff Mutation
This commit is contained in:
@@ -2,13 +2,23 @@ import { Environment } from "relay-runtime";
|
||||
|
||||
import { TalkContext } from "talk-framework/lib/bootstrap";
|
||||
import { createMutationContainer } from "talk-framework/lib/relay";
|
||||
import { signOff } from "talk-framework/rest";
|
||||
import { signOff, SignOffInput } from "talk-framework/rest";
|
||||
|
||||
export type SignOffMutation = (input: SignOffInput) => Promise<void>;
|
||||
|
||||
export async function commit(
|
||||
environment: Environment,
|
||||
input: SignOffInput,
|
||||
{ rest, postMessage }: TalkContext
|
||||
) {
|
||||
signOff(rest);
|
||||
try {
|
||||
await signOff(rest, input);
|
||||
console.log("signing off");
|
||||
// postMessage.send("setAuthToken", result.token, window.opener);
|
||||
// window.close();
|
||||
} catch (err) {
|
||||
// postMessage.send("authError", err.toString(), window.opener);
|
||||
}
|
||||
}
|
||||
|
||||
export const withSignOffMutation = createMutationContainer("signOff", commit);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { withSetViewMutation, SetViewMutation } from "./SetViewMutation";
|
||||
export { withSignInMutation, SignInMutation } from "./SignInMutation";
|
||||
export { withSignUpMutation, SignUpMutation } from "./SignUpMutation";
|
||||
export { withSignOffMutation } from "./SignOffMutation";
|
||||
export { withSignOffMutation, SignOffMutation } from "./SignOffMutation";
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export { default as signIn, SignInInput } from "./signIn";
|
||||
export { default as signUp, SignUpInput } from "./signUp";
|
||||
export { default as signOff } from "./signOff";
|
||||
export { default as signOff, SignOffInput } from "./signOff";
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { RestClient } from "../lib/rest";
|
||||
|
||||
export default function signOff(rest: RestClient) {
|
||||
return rest.fetch("/tenant/auth/local", {
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
export interface SignOffInput {}
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
export interface SignOffResponse {}
|
||||
|
||||
export default function signOff(rest: RestClient, input: SignOffInput) {
|
||||
return rest.fetch<SignOffResponse>("/tenant/auth/local", {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ import MatchMedia from "talk-ui/components/MatchMedia";
|
||||
import { User } from "../containers/UserBoxContainer";
|
||||
import * as styles from "./UserBoxAuthenticated.css";
|
||||
|
||||
export interface UserBoxUnauthenticatedProps {
|
||||
onSignOut: () => void;
|
||||
export interface UserBoxAuthenticatedProps {
|
||||
onSignOff: () => void;
|
||||
user: User;
|
||||
}
|
||||
|
||||
const UserBoxAuthenticated: StatelessComponent<
|
||||
UserBoxUnauthenticatedProps
|
||||
UserBoxAuthenticatedProps
|
||||
> = props => {
|
||||
return (
|
||||
<Flex itemGutter="half">
|
||||
@@ -40,7 +40,7 @@ const UserBoxAuthenticated: StatelessComponent<
|
||||
color="primary"
|
||||
size="small"
|
||||
variant="underlined"
|
||||
onClick={props.onSignOut}
|
||||
onClick={props.onSignOff}
|
||||
>
|
||||
Sign Out
|
||||
</Button>
|
||||
|
||||
@@ -9,7 +9,6 @@ import * as styles from "./UserBoxUnauthenticated.css";
|
||||
export interface UserBoxUnauthenticatedProps {
|
||||
onSignIn: () => void;
|
||||
onRegister: () => void;
|
||||
onSignOff: () => void;
|
||||
}
|
||||
|
||||
const UserBoxUnauthenticated: StatelessComponent<
|
||||
|
||||
@@ -1,29 +1,25 @@
|
||||
import React, { Component } from "react";
|
||||
import UserBoxUnauthenticated from "talk-stream/components/UserBoxUnauthenticated";
|
||||
import { withSignOffMutation } from "../../auth/mutations";
|
||||
import UserBoxAuthenticated from "talk-stream/components/UserBoxAuthenticated";
|
||||
import { SignOffMutation, withSignOffMutation } from "../../auth/mutations";
|
||||
import { User } from "../containers/UserBoxContainer";
|
||||
|
||||
interface SignInContainerProps {
|
||||
onSignIn: () => void;
|
||||
onRegister: () => void;
|
||||
signOff: () => void;
|
||||
interface UserBoxAuthenticatedProps {
|
||||
signOff: SignOffMutation;
|
||||
user: User;
|
||||
}
|
||||
|
||||
export type View = "SIGN_UP" | "FORGOT_PASSWORD";
|
||||
|
||||
class UserBoxUnauthenticatedContainer extends Component<SignInContainerProps> {
|
||||
private signOff = () => {
|
||||
this.props.signOff();
|
||||
class UserBoxAuthenticatedContainer extends Component<
|
||||
UserBoxAuthenticatedProps
|
||||
> {
|
||||
private onSignOff = () => {
|
||||
this.props.signOff({});
|
||||
};
|
||||
public render() {
|
||||
return (
|
||||
<UserBoxUnauthenticated
|
||||
onSignOff={this.signOff}
|
||||
onRegister={this.props.onRegister}
|
||||
onSignIn={this.props.onSignIn}
|
||||
/>
|
||||
<UserBoxAuthenticated onSignOff={this.onSignOff} user={this.props.user} />
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const enhanced = withSignOffMutation(UserBoxUnauthenticatedContainer);
|
||||
const enhanced = withSignOffMutation(UserBoxAuthenticatedContainer);
|
||||
export default enhanced;
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from "talk-stream/mutations";
|
||||
import { Popup } from "talk-ui/components";
|
||||
|
||||
import UserBoxAuthenticated from "../components/UserBoxAuthenticated";
|
||||
import UserBoxUnauthenticated from "talk-stream/components/UserBoxUnauthenticated";
|
||||
import UserBoxAuthenticatedContainer from "../containers/UserBoxAuthenticatedContainer";
|
||||
|
||||
export type USER_ROLE =
|
||||
@@ -50,9 +50,7 @@ export class UserBoxContainer extends Component<InnerProps> {
|
||||
} = this.props;
|
||||
|
||||
if (user) {
|
||||
return (
|
||||
<UserBoxAuthenticated onSignOut={this.handleRegister} user={user} />
|
||||
);
|
||||
return <UserBoxAuthenticatedContainer user={user} />;
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -67,7 +65,7 @@ export class UserBoxContainer extends Component<InnerProps> {
|
||||
onBlur={this.handleBlur}
|
||||
onClose={this.handleClose}
|
||||
/>
|
||||
<UserBoxAuthenticatedContainer
|
||||
<UserBoxUnauthenticated
|
||||
onSignIn={this.handleSignIn}
|
||||
onRegister={this.handleRegister}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user