-
Notifications
You must be signed in to change notification settings - Fork 136
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
Replace connect
with hooks in 3 components
#7552
Merged
markerikson
merged 2 commits into
replayio:main
from
Andarist:deconnectify-few-components
Aug 24, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import React, { ChangeEvent, useEffect, useState } from "react"; | ||
import { connect, ConnectedProps } from "react-redux"; | ||
import React, { ChangeEvent, useState, useMemo } from "react"; | ||
import * as actions from "ui/actions/app"; | ||
import hooks from "ui/hooks"; | ||
import { useAppSelector, useAppDispatch } from "ui/setup/hooks"; | ||
import * as selectors from "ui/reducers/app"; | ||
import { UIState } from "ui/state"; | ||
import { WorkspaceUser } from "ui/types"; | ||
import { validateEmail } from "ui/utils/helpers"; | ||
import { TextInput } from "../Forms"; | ||
|
@@ -29,9 +28,11 @@ export function WorkspaceMembers({ | |
members: WorkspaceUser[]; | ||
isAdmin: boolean; | ||
}) { | ||
const sortedMembers = members.sort( | ||
(a: WorkspaceUser, b: WorkspaceUser) => Number(b.pending) - Number(a.pending) | ||
); | ||
const sortedMembers = useMemo(() => { | ||
return members | ||
.slice() | ||
.sort((a: WorkspaceUser, b: WorkspaceUser) => Number(b.pending) - Number(a.pending)); | ||
}, [members]); | ||
|
||
const canLeave = members.length > 1; | ||
const canAdminLeave = canLeave && members.filter(a => a.roles?.includes("admin")).length > 1; | ||
|
@@ -62,7 +63,7 @@ type WorkspaceFormProps = { | |
members?: WorkspaceUser[]; | ||
}; | ||
|
||
function WorkspaceForm({ members }: WorkspaceFormProps) { | ||
function WorkspaceForm({ members = [] }: WorkspaceFormProps) { | ||
const workspaceId = useGetTeamIdFromRoute(); | ||
const [inputValue, setInputValue] = useState(""); | ||
const [errorMessage, setErrorMessage] = useState<string | null>(null); | ||
|
@@ -72,7 +73,7 @@ function WorkspaceForm({ members }: WorkspaceFormProps) { | |
setIsLoading(false); | ||
}); | ||
|
||
const memberEmails = (members || []).filter(m => m.email).map(m => m.email!); | ||
const memberEmails = members.filter(m => m.email).map(m => m.email!); | ||
const onChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setInputValue(e.target.value); | ||
}; | ||
|
@@ -130,7 +131,6 @@ const settings: Settings< | |
settings?: any; | ||
isAdmin: boolean; | ||
workspaceId: string; | ||
hideModal: PropsFromRedux["hideModal"]; | ||
} | ||
> = [ | ||
{ | ||
|
@@ -146,13 +146,13 @@ const settings: Settings< | |
{ | ||
title: "Team Members", | ||
icon: "group", | ||
component: function TeamMembers({ isAdmin, workspaceId, settings, ...rest }) { | ||
component: function TeamMembers({ isAdmin, workspaceId }) { | ||
const { members } = hooks.useGetWorkspaceMembers(workspaceId); | ||
|
||
return ( | ||
<div className="flex flex-col flex-grow space-y-3"> | ||
<div className="flex flex-grow flex-col space-y-3"> | ||
<div>{`Manage members here so that everyone who belongs to this team can see each other's replays.`}</div> | ||
<WorkspaceForm {...rest} members={members} /> | ||
<WorkspaceForm members={members} /> | ||
<div className="text-xs font-semibold uppercase">{`Members`}</div> | ||
<div className="flex-grow overflow-y-auto"> | ||
<div className="workspace-members-container flex flex-col space-y-1.5"> | ||
|
@@ -180,7 +180,8 @@ const settings: Settings< | |
{ | ||
title: "Delete Team", | ||
icon: "cancel", | ||
component: function DeleteTeam({ hideModal, workspaceId }) { | ||
component: function DeleteTeam({ workspaceId }) { | ||
const dispatch = useAppDispatch(); | ||
const redirectToTeam = useRedirectToTeam(true); | ||
const updateDefaultWorkspace = hooks.useUpdateDefaultWorkspace(); | ||
const deleteWorkspace = hooks.useDeleteWorkspace(); | ||
|
@@ -196,7 +197,7 @@ const settings: Settings< | |
deleteWorkspace({ | ||
variables: { workspaceId: workspaceId, shouldDeleteRecordings: true }, | ||
}); | ||
hideModal(); | ||
dispatch(actions.hideModal()); | ||
updateDefaultWorkspace({ variables: { workspaceId: null } }); | ||
redirectToTeam("me"); | ||
} | ||
|
@@ -221,24 +222,23 @@ const settings: Settings< | |
}, | ||
]; | ||
|
||
function WorkspaceSettingsModal({ view, ...rest }: PropsFromRedux) { | ||
const tabNameForView = { | ||
billing: "Billing", | ||
members: "Team Members", | ||
api: "API Keys", | ||
} as const; | ||
|
||
export default function WorkspaceSettingsModal() { | ||
const selectedTab = useAppSelector(state => { | ||
const opts = selectors.getModalOptions(state); | ||
const view = opts && "view" in opts ? opts.view : null; | ||
return view && tabNameForView[view as keyof typeof tabNameForView]; | ||
}); | ||
const workspaceId = useGetTeamIdFromRoute(); | ||
const [selectedTab, setTab] = useState<string>(); | ||
const { members } = hooks.useGetWorkspaceMembers(workspaceId); | ||
const { workspace } = hooks.useGetWorkspace(workspaceId); | ||
const { userId: localUserId } = hooks.useGetUserId(); | ||
|
||
useEffect(() => { | ||
if (view) { | ||
const views: Record<string, string> = { | ||
billing: "Billing", | ||
members: "Team Members", | ||
api: "API Keys", | ||
}; | ||
setTab(views[view]); | ||
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 was trying to derive the local state from the selected state - so I've just refactored this to use the actual selected state right from the start |
||
} | ||
}, [view]); | ||
|
||
if (!(workspaceId && workspace)) { | ||
return null; | ||
} | ||
|
@@ -263,7 +263,7 @@ function WorkspaceSettingsModal({ view, ...rest }: PropsFromRedux) { | |
<SettingsModal | ||
hiddenTabs={hiddenTabs} | ||
tab={tab} | ||
panelProps={{ isAdmin, workspaceId, ...rest }} | ||
panelProps={{ isAdmin, workspaceId }} | ||
settings={settings} | ||
size="lg" | ||
title={ | ||
|
@@ -276,17 +276,3 @@ function WorkspaceSettingsModal({ view, ...rest }: PropsFromRedux) { | |
/> | ||
); | ||
} | ||
|
||
const connector = connect( | ||
(state: UIState) => { | ||
const opts = selectors.getModalOptions(state); | ||
const view = opts && "view" in opts ? opts.view : null; | ||
return { view }; | ||
}, | ||
{ | ||
hideModal: actions.hideModal, | ||
} | ||
); | ||
export type PropsFromRedux = ConnectedProps<typeof connector>; | ||
|
||
export default connector(WorkspaceSettingsModal); |
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.
If I read this correctly... only
TeamMembers
were actually usinghideModal
so I've just moved it directly to it and cleaned this up from the parent components