refactor: login

This commit is contained in:
Tristan Yang
2022-07-31 22:57:37 +08:00
parent 3b35e18150
commit b83d687e1e
4 changed files with 20 additions and 13 deletions
@@ -68,7 +68,6 @@ const LogoutConfirmModal: FC<Props> = ({ closeModal }) => {
</Button>
</>
}
// className="animate__animated animate__fadeInDown animate__faster"
>
<div className="clear">
<label htmlFor="clear_cb" className="txt">
+6 -3
View File
@@ -5,6 +5,8 @@ import Label from "../../../common/component/styled/Label";
import Toggle from "../../../common/component/styled/Toggle";
import SaveTip from "../../../common/component/SaveTip";
import useConfig from "../../../common/hook/useConfig";
import { ChangeEvent } from "react";
import { AgoraConfig } from "../../../types/server";
export default function ConfigAgora() {
const { changed, reset, values, setValues, toggleEnable, updateConfig } = useConfig("agora");
@@ -13,10 +15,11 @@ export default function ConfigAgora() {
updateConfig(values);
};
const handleChange = (evt) => {
const handleChange = (evt: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
const newValue = evt.target.value;
const { type } = evt.target.dataset;
const { type = "" } = evt.target.dataset;
setValues((prev) => {
if (!prev) return prev;
return { ...prev, [type]: newValue };
});
};
@@ -29,7 +32,7 @@ export default function ConfigAgora() {
rtm_key,
rtm_secret,
enabled = false
} = values ?? {};
} = values as AgoraConfig;
return (
<StyledContainer>
+2 -1
View File
@@ -16,8 +16,9 @@ export default function ConfigFirebase() {
};
const handleChange = (evt: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
const newValue = evt.target.value;
const { type } = evt.target.dataset;
const { type = "" } = evt.target.dataset;
setValues((prev) => {
if (!prev) return prev;
return { ...prev, [type]: newValue };
});
};
+12 -8
View File
@@ -1,3 +1,4 @@
import { ChangeEvent } from "react";
import toast from "react-hot-toast";
import StyledContainer from "./StyledContainer";
import Toggle from "../../../common/component/styled/Toggle";
@@ -45,22 +46,25 @@ export default function Logins() {
}
}
};
const handleGoogleClientIdChange = (evt) => {
const handleGoogleClientIdChange = (evt: ChangeEvent<HTMLInputElement>) => {
updateClientId(evt.target.value);
};
const handleGithubAuthChange = (evt) => {
const handleGithubAuthChange = (evt: ChangeEvent<HTMLInputElement>) => {
const { key } = evt.target.dataset;
if (key) {
updateGithubAuthConfig({ [key]: evt.target.value });
}
};
const handleToggle = (val) => {
const handleToggle = (
val: Partial<Pick<LoginConfig, "github" | "google" | "password" | "magic_link" | "metamask">>
) => {
setValues((prev) => {
if (!prev) return prev;
return { ...prev, ...val };
});
};
if (!values) return null;
const { google, magic_link, github, metamask, password, oidc = [] } = values ?? {};
const { google, magic_link, github, metamask, password, oidc = [] } = values as LoginConfig;
const valuesChanged = clientIdChanged || changed || githubChanged;
return (
@@ -177,10 +181,10 @@ export default function Logins() {
<IssuerList
issuers={oidc}
onChange={(newOidc) => {
setValues((prev) => ({
...prev,
oidc: newOidc
}));
setValues((prev) => {
if (!prev) return prev;
return { ...prev, oidc: newOidc };
});
}}
/>
</div>