Skip to content

Commit

Permalink
fix: code form in user menu causing dom issues
Browse files Browse the repository at this point in the history
it was a form encapsulated in a form and that is not safe
  • Loading branch information
NikhilNarayana committed Jan 22, 2022
1 parent 281afe9 commit a8269c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/renderer/containers/ActivateOnlineForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import { validateConnectCodeStart } from "@/lib/validate";

const log = electronLog.scope("ActivateOnlineForm");

export const ActivateOnlineForm: React.FC = () => {
export const ActivateOnlineForm: React.FC<{ onSubmit?: () => void }> = ({ onSubmit }) => {
const user = useAccount((store) => store.user);
const refreshActivation = useAccount((store) => store.refreshPlayKey);
return (
<div>
<div>Your connect code is used for players to connect with you directly.</div>
<ConnectCodeSetter displayName={user ? user.displayName : null} onSuccess={refreshActivation} />
<ConnectCodeSetter displayName={user ? user.displayName : null} onSuccess={onSubmit || refreshActivation} />
</div>
);
};
Expand Down
13 changes: 5 additions & 8 deletions src/renderer/containers/Header/ActivateOnlineDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export const ActivateOnlineDialog: React.FC<ActivateOnlineDialogProps> = ({ open
const refreshPlayKey = useAccount((store) => store.refreshPlayKey);
const { addToast } = useToasts();

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const handleSubmit = () => {
refreshPlayKey()
.then(() => {
onClose();
Expand All @@ -37,12 +36,10 @@ export const ActivateOnlineDialog: React.FC<ActivateOnlineDialogProps> = ({ open

return (
<Dialog open={open} onClose={onClose} fullWidth={true} fullScreen={fullScreen} disableBackdropClick={false}>
<form onSubmit={handleSubmit}>
<StyledDialogTitle>Choose a connect code</StyledDialogTitle>
<DialogContent style={{ display: "flex", paddingBottom: 30 }}>
<ActivateOnlineForm />
</DialogContent>
</form>
<StyledDialogTitle>Choose a connect code</StyledDialogTitle>
<DialogContent style={{ display: "flex", paddingBottom: 30 }}>
<ActivateOnlineForm onSubmit={handleSubmit} />
</DialogContent>
</Dialog>
);
};
Expand Down
4 changes: 0 additions & 4 deletions src/renderer/containers/Header/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import EjectIcon from "@material-ui/icons/Eject";
import LanguageIcon from "@material-ui/icons/Language";
import firebase from "firebase";
import React from "react";
import { useToasts } from "react-toast-notifications";

import { ConfirmationModal } from "@/components/ConfirmationModal";
import { IconMenu, IconMenuItem } from "@/components/IconMenu";
Expand All @@ -22,12 +21,10 @@ export const UserMenu: React.FC<{
}> = ({ user, handleError }) => {
const playKey = useAccount((store) => store.playKey);
const displayName = useAccount((store) => store.displayName);
const refreshPlayKey = useAccount((store) => store.refreshPlayKey);
const loading = useAccount((store) => store.loading);
const [openLogoutPrompt, setOpenLogoutPrompt] = React.useState(false);
const [openNameChangePrompt, setOpenNameChangePrompt] = React.useState(false);
const [openActivationDialog, setOpenActivationDialog] = React.useState(false);
const { addToast } = useToasts();
const onLogout = async () => {
try {
await logout();
Expand Down Expand Up @@ -107,7 +104,6 @@ export const UserMenu: React.FC<{
open={openActivationDialog}
onClose={() => setOpenActivationDialog(false)}
onSubmit={() => {
refreshPlayKey().catch((err) => addToast(err.message, { appearance: "error" }));
setOpenActivationDialog(false);
}}
/>
Expand Down

0 comments on commit a8269c6

Please sign in to comment.