chore(site): rename userXService to authXService (#924)

* chore(site): rename userXService to authXService

* Rename contents of xService
This commit is contained in:
Presley Pizzo
2022-04-08 11:42:57 -04:00
committed by GitHub
parent 94ab6f3d8e
commit 0bf9dee7e3
6 changed files with 34 additions and 34 deletions

View File

@ -5,9 +5,9 @@ import { NavbarView } from "./NavbarView"
export const Navbar: React.FC = () => { export const Navbar: React.FC = () => {
const xServices = useContext(XServiceContext) const xServices = useContext(XServiceContext)
const [userState, userSend] = useActor(xServices.userXService) const [authState, authSend] = useActor(xServices.authXService)
const { me } = userState.context const { me } = authState.context
const onSignOut = () => userSend("SIGN_OUT") const onSignOut = () => authSend("SIGN_OUT")
return <NavbarView user={me} onSignOut={onSignOut} /> return <NavbarView user={me} onSignOut={onSignOut} />
} }

View File

@ -11,13 +11,13 @@ export interface RequireAuthProps {
export const RequireAuth: React.FC<RequireAuthProps> = ({ children }) => { export const RequireAuth: React.FC<RequireAuthProps> = ({ children }) => {
const xServices = useContext(XServiceContext) const xServices = useContext(XServiceContext)
const [userState] = useActor(xServices.userXService) const [authState] = useActor(xServices.authXService)
const location = useLocation() const location = useLocation()
const redirectTo = embedRedirect(location.pathname) const redirectTo = embedRedirect(location.pathname)
if (userState.matches("signedOut") || !userState.context.me) { if (authState.matches("signedOut") || !authState.context.me) {
return <Navigate to={redirectTo} /> return <Navigate to={redirectTo} />
} else if (userState.hasTag("loading")) { } else if (authState.hasTag("loading")) {
return <FullScreenLoader /> return <FullScreenLoader />
} else { } else {
return children return children

View File

@ -8,8 +8,8 @@ import { XServiceContext } from "../xServices/StateContext"
export const CliAuthenticationPage: React.FC = () => { export const CliAuthenticationPage: React.FC = () => {
const xServices = useContext(XServiceContext) const xServices = useContext(XServiceContext)
const [userState] = useActor(xServices.userXService) const [authState] = useActor(xServices.authXService)
const { me } = userState.context const { me } = authState.context
const styles = useStyles() const styles = useStyles()

View File

@ -24,16 +24,16 @@ export const SignInPage: React.FC = () => {
const styles = useStyles() const styles = useStyles()
const location = useLocation() const location = useLocation()
const xServices = useContext(XServiceContext) const xServices = useContext(XServiceContext)
const [userState, userSend] = useActor(xServices.userXService) const [authState, authSend] = useActor(xServices.authXService)
const isLoading = userState.hasTag("loading") const isLoading = authState.hasTag("loading")
const redirectTo = retrieveRedirect(location.search) const redirectTo = retrieveRedirect(location.search)
const authErrorMessage = userState.context.authError ? (userState.context.authError as Error).message : undefined const authErrorMessage = authState.context.authError ? (authState.context.authError as Error).message : undefined
const onSubmit = async ({ email, password }: { email: string; password: string }) => { const onSubmit = async ({ email, password }: { email: string; password: string }) => {
userSend({ type: "SIGN_IN", email, password }) authSend({ type: "SIGN_IN", email, password })
} }
if (userState.matches("signedIn")) { if (authState.matches("signedIn")) {
return <Navigate to={redirectTo} replace /> return <Navigate to={redirectTo} replace />
} else { } else {
return ( return (

View File

@ -1,12 +1,12 @@
import { useInterpret } from "@xstate/react" import { useInterpret } from "@xstate/react"
import React, { createContext } from "react" import React, { createContext } from "react"
import { ActorRefFrom } from "xstate" import { ActorRefFrom } from "xstate"
import { authMachine } from "./auth/authXService"
import { buildInfoMachine } from "./buildInfo/buildInfoXService" import { buildInfoMachine } from "./buildInfo/buildInfoXService"
import { userMachine } from "./user/userXService"
interface XServiceContextType { interface XServiceContextType {
buildInfoXService: ActorRefFrom<typeof buildInfoMachine> buildInfoXService: ActorRefFrom<typeof buildInfoMachine>
userXService: ActorRefFrom<typeof userMachine> authXService: ActorRefFrom<typeof authMachine>
} }
/** /**
@ -24,7 +24,7 @@ export const XServiceProvider: React.FC = ({ children }) => {
<XServiceContext.Provider <XServiceContext.Provider
value={{ value={{
buildInfoXService: useInterpret(buildInfoMachine), buildInfoXService: useInterpret(buildInfoMachine),
userXService: useInterpret(userMachine), authXService: useInterpret(authMachine),
}} }}
> >
{children} {children}

View File

@ -2,22 +2,22 @@ import { assign, createMachine } from "xstate"
import * as API from "../../api" import * as API from "../../api"
import * as Types from "../../api/types" import * as Types from "../../api/types"
export interface UserContext { export interface AuthContext {
getUserError?: Error | unknown getUserError?: Error | unknown
authError?: Error | unknown authError?: Error | unknown
me?: Types.UserResponse me?: Types.UserResponse
} }
export type UserEvent = { type: "SIGN_OUT" } | { type: "SIGN_IN"; email: string; password: string } export type AuthEvent = { type: "SIGN_OUT" } | { type: "SIGN_IN"; email: string; password: string }
export const userMachine = export const authMachine =
/** @xstate-layout N4IgpgJg5mDOIC5QFdZgE4GUAuBDbYAdLAJZQB2kA8stgMSYCSA4gHID6jrioADgPalsJfuR4gAHogDM0gJyEATAHYAbNIAscxdunKArKo0AaEAE9EG+YX0BGABz3FD6atsbbc5QF9vp1Bg4+ESkFCTkUIzkdBCiROEAbvwA1iFk5FHiAkIiYkiSiHIADITSOvbSRRqq2m7StqYWCIr2+ja2tvVV+vqaRVW+-mhYeATE6eGR0Rjo-OiEvAA2+ABmcwC24xSZ+dkkwqLiUghlyoRF+opayq4X+sqK+o2Il6qEcq5y+hrfjt+qgxAARGwUIMGwwgiAFVhjE4oREikiOCALJgLKCfa5I4yIyEZTFZQaezFK5lPTPBC2IqKUqKC4EjqqKrFOSA4FBMbgyFQGEYOgzOYLZbYNboTao9G7TEHPKgY7SewlTQ3dRyVQ6GpVSmKMqEIz2ZRKjrKIqqJzs4actIUSBRBgsDhUKEAFQxOUO+WOhvshA0ahualsqnu8kpthUhGplVUIa+rUq9ktgVGNvIkxo9FilAR5CSqS25Ez7qxnvliCMGlK1Tk6vN5p+T3ML0Ub2U7iKXmcGg8tmTILGoXTEUzAvQs3mS1WG0LxelHrlBQQIbasc7aiKtnbV3sOpaUZXBjkwd1A0B5H4EDg4g5qcL1FoJdlOIQdlpH2qhmJzJ+DWbCB7WxSmUIl2wJM0CSTPwgStO8h0mHY+BlbEvReICaSMbQflkU0fkpHtfS3MC3C+aR9ENfR+2tMEwAhSY+XQJ8UPLACziVS5TXKAxPDI8MaSjIojSqPQezNRUqLg9I7UXPZn1Q5dqn1CMNEEi4HAecNIyVGoIweVQDH0tloNvUF4JHR951LRdvQcc4PCcAx12-fDOnOeRTU7C4SXsPtjNg4ImLLJddUIdiVBpOQKJ4psmh0ASQOPRUiI8RRfF8IA */ /** @xstate-layout N4IgpgJg5mDOIC5QFdZgE4GUAuBDbYAdLAJZQB2kA8stgMSYCSA4gHID6jrioADgPalsJfuR4gAHogDM0gJyEATAHYAbNIAscxdunKArKo0AaEAE9EG+YX0BGABz3FD6atsbbc5QF9vp1Bg4+ESkFCTkUIzkdBCiROEAbvwA1iFk5FHiAkIiYkiSiHIADITSOvbSRRqq2m7StqYWCIr2+ja2tvVV+vqaRVW+-mhYeATE6eGR0Rjo-OiEvAA2+ABmcwC24xSZ+dkkwqLiUghlyoRF+opayq4X+sqK+o2Il6qEcq5y+hrfjt+qgxAARGwUIMGwwgiAFVhjE4oREikiOCALJgLKCfa5I4yIyEZTFZQaezFK5lPTPBC2IqKUqKC4EjqqKrFOSA4FBMbgyFQGEYOgzOYLZbYNboTao9G7TEHPKgY7SewlTQ3dRyVQ6GpVSmKMqEIz2ZRKjrKIqqJzs4actIUSBRBgsDhUKEAFQxOUO+WOhvshA0ahualsqnu8kpthUhGplVUIa+rUq9ktgVGNvIkxo9FilAR5CSqS25Ez7qxnvliCMGlK1Tk6vN5p+T3ML0Ub2U7iKXmcGg8tmTILGoXTEUzAvQs3mS1WG0LxelHrlBQQIbasc7aiKtnbV3sOpaUZXBjkwd1A0B5H4EDg4g5qcL1FoJdlOIQdlpH2qhmJzJ+DWbCB7WxSmUIl2wJM0CSTPwgStO8h0mHY+BlbEvReICaSMbQflkU0fkpHtfS3MC3C+aR9ENfR+2tMEwAhSY+XQJ8UPLACziVS5TXKAxPDI8MaSjIojSqPQezNRUqLg9I7UXPZn1Q5dqn1CMNEEi4HAecNIyVGoIweVQDH0tloNvUF4JHR951LRdvQcc4PCcAx12-fDOnOeRTU7C4SXsPtjNg4ImLLJddUIdiVBpOQKJ4psmh0ASQOPRUiI8RRfF8IA */
createMachine( createMachine(
{ {
tsTypes: {} as import("./userXService.typegen").Typegen0, tsTypes: {} as import("./authXService.typegen").Typegen0,
schema: { schema: {
context: {} as UserContext, context: {} as AuthContext,
events: {} as UserEvent, events: {} as AuthEvent,
services: {} as { services: {} as {
getMe: { getMe: {
data: Types.UserResponse data: Types.UserResponse
@ -32,13 +32,13 @@ export const userMachine =
getUserError: undefined, getUserError: undefined,
authError: undefined, authError: undefined,
}, },
id: "userState", id: "authState",
initial: "gettingUser", initial: "gettingUser",
states: { states: {
signedOut: { signedOut: {
on: { on: {
SIGN_IN: { SIGN_IN: {
target: "#userState.signingIn", target: "#authState.signingIn",
}, },
}, },
}, },
@ -48,14 +48,14 @@ export const userMachine =
id: "signIn", id: "signIn",
onDone: [ onDone: [
{ {
target: "#userState.gettingUser", target: "#authState.gettingUser",
actions: "clearAuthError", actions: "clearAuthError",
}, },
], ],
onError: [ onError: [
{ {
actions: "assignAuthError", actions: "assignAuthError",
target: "#userState.signedOut", target: "#authState.signedOut",
}, },
], ],
}, },
@ -68,13 +68,13 @@ export const userMachine =
onDone: [ onDone: [
{ {
actions: ["assignMe", "clearGetUserError"], actions: ["assignMe", "clearGetUserError"],
target: "#userState.signedIn", target: "#authState.signedIn",
}, },
], ],
onError: [ onError: [
{ {
actions: "assignGetUserError", actions: "assignGetUserError",
target: "#userState.signedOut", target: "#authState.signedOut",
}, },
], ],
}, },
@ -83,7 +83,7 @@ export const userMachine =
signedIn: { signedIn: {
on: { on: {
SIGN_OUT: { SIGN_OUT: {
target: "#userState.signingOut", target: "#authState.signingOut",
}, },
}, },
}, },
@ -94,13 +94,13 @@ export const userMachine =
onDone: [ onDone: [
{ {
actions: ["unassignMe", "clearAuthError"], actions: ["unassignMe", "clearAuthError"],
target: "#userState.signedOut", target: "#authState.signedOut",
}, },
], ],
onError: [ onError: [
{ {
actions: "assignAuthError", actions: "assignAuthError",
target: "#userState.signedIn", target: "#authState.signedIn",
}, },
], ],
}, },
@ -120,21 +120,21 @@ export const userMachine =
assignMe: assign({ assignMe: assign({
me: (_, event) => event.data, me: (_, event) => event.data,
}), }),
unassignMe: assign((context: UserContext) => ({ unassignMe: assign((context: AuthContext) => ({
...context, ...context,
me: undefined, me: undefined,
})), })),
assignGetUserError: assign({ assignGetUserError: assign({
getUserError: (_, event) => event.data, getUserError: (_, event) => event.data,
}), }),
clearGetUserError: assign((context: UserContext) => ({ clearGetUserError: assign((context: AuthContext) => ({
...context, ...context,
getUserError: undefined, getUserError: undefined,
})), })),
assignAuthError: assign({ assignAuthError: assign({
authError: (_, event) => event.data, authError: (_, event) => event.data,
}), }),
clearAuthError: assign((context: UserContext) => ({ clearAuthError: assign((context: AuthContext) => ({
...context, ...context,
authError: undefined, authError: undefined,
})), })),