Files
discord-decomp/modules/hub/native/components/HubEmailConnectionPinVerify.tsx
T
2026-11-01 12:12:55 +02:00

174 lines
5.4 KiB
TypeScript

// Metro module 11840 (f11841).
import { useEffect, useState } from "react";
import { Image as Image2, View } from "react-native";
import GuildStore from "../../../../stores/GuildStore";
import { createStyles } from "../../../../design/components/Styles/native/createStyles";
import ToastActionCreators from "../../../toast/native/ToastActionCreators";
import Module11841 from "../../../../_bundle/Module11841";
import HubJoinManager from "../../HubJoinManager";
import navigateToLastChannel from "../../../main_tabs_v2/native/navigateToLastChannel";
import Module12 from "../../../../_bundle/Module12";
import HubActionCreators from "../../../../actions/HubActionCreators";
import { intl, t } from "../../../../intl/index.native";
import { APIError } from "../../../../errors/index";
import { transitionToGuild } from "../../../routing/transitionToGuild.native";
import { HubEmailConnectionScreen } from "./HubEmailConnectionModal";
import Module11843 from "../../../../_bundle/Module11843";
import { Text } from "../../../../design/components/Text/native/Text";
import { CodeBlocks, CodeType } from "../../../phone/native/CodeField";
let useStyles;
const presentResendToast = function presentResendToast(anyErrorMessage) {
ToastActionCreators.open({
key: "HUB_EMAIL_RESET",
content: anyErrorMessage,
icon: Module11841
});
};
useStyles = createStyles({
container: {
alignItems: "center"
},
title: {
marginBottom: 8,
textAlign: "center"
},
description: {
textAlign: "center",
marginBottom: 24
},
label: {
textAlign: "center",
marginBottom: 12
},
error: {
alignSelf: "center",
marginVertical: 8
}
});
export default function HubEmailConnectionPinVerify(props) {
let setState;
const { email, guildId, onClose } = props;
setState = void 0;
let _handleCodeEntered2 = function _handleCodeEntered() {
const r9 = async (c30466_0) => {
let c30466_3;
let c30466_4 = 0;
let c31646_0, c31646_1;
L12: {
try {
c31646_0 = void 0;
c30466_4 = 1;
await HubActionCreators.verifyCode(c30466_0, guildId, email);
c31646_0 = GuildStore.getGuild(guildId);
if (c31646_0 != null) {
(0, onClose)(true);
transitionToGuild(c31646_0.id);
}
c30466_4 = 0;
} catch ($e) {
const r29 = $e;
let r7 = r29;
c30466_3 = r29;
if (c30466_4 !== 0) {
while (true) {
try {
const r84 = c30466_3;
c30466_4 = 0;
c31646_1 = r84;
setState(new APIError(c31646_1));
break L12;
} catch (r80) {
r7 = r80;
c30466_3 = r80;
if (c30466_4 === 0) {
break;
}
}
}
}
throw r7;
}
}
};
_handleCodeEntered2 = r9;
return r9.apply(this, arguments);
};
const styles = useStyles();
useEffect(() => {
HubJoinManager.initialize(() => {
onClose(true);
navigateToLastChannel();
});
return () => {
HubJoinManager.terminate();
};
}, [onClose]);
const onClick = Module12.throttle(async () => {
let anyErrorMessage, c27192_3;
let c27192_4 = 0;
let c30467_0, c30467_1;
L10: {
try {
c30467_0 = void 0;
c27192_4 = 1;
await HubActionCreators.sendVerificationEmail(email, true, guildId);
(0, presentResendToast)(intl.string(t["2bO4dz"]));
c27192_4 = 0;
} catch ($e) {
const r29 = $e;
let r7 = r29;
c27192_3 = r29;
if (c27192_4 !== 0) {
while (true) {
try {
const r79 = c27192_3;
c27192_4 = 0;
c30467_1 = r79;
c30467_0 = new APIError(c30467_1);
const r91 = c30467_0;
anyErrorMessage = r91 == null ? void 0 : r91.getAnyErrorMessage();
if (anyErrorMessage == null) {
anyErrorMessage = intl.string(t.FPzC5z);
}
presentResendToast(anyErrorMessage);
break L10;
} catch (r75) {
r7 = r75;
c27192_3 = r75;
if (c27192_4 === 0) {
break;
}
}
}
}
throw r7;
}
}
}, 1000);
let state;
[state, setState] = useState(null);
return <HubEmailConnectionScreen>
<View style={styles.container}>
<Image2 source={Module11843} />
<Text style={styles.title} accessibilityRole="header" variant="heading-xl/extrabold" color="mobile-text-heading-primary">
{intl.string(t.SJ3Lxc)}
</Text>
<Text style={styles.description} variant="text-sm/medium" color="text-default">
{intl.format(t["b+W0oq"], {
onClick,
email
})}
</Text>
<Text style={styles.label} variant="text-sm/semibold" color="text-muted">
{intl.string(t.rpWT1s)}
</Text>
<CodeBlocks hasError={false} count={8} onCodeEntered={function handleCodeEntered(event) {
return _handleCodeEntered2.apply(this, arguments);
}} codeType={CodeType.ALPHANUMERIC} />
{state != null && <Text variant="text-sm/medium" color="text-feedback-critical" style={styles.error}>
{state.getAnyErrorMessage()}
</Text>}
</View>
</HubEmailConnectionScreen>;
};