Files
discord-decomp/modules/oauth2/native/SuccessResult.tsx
T
2026-11-01 12:12:55 +02:00

141 lines
5.7 KiB
TypeScript

// Metro module 11002 (f11003).
import { useMemo, useCallback, useEffect } from "react";
import { Image as Image2, ScrollView, View } from "react-native";
import ChannelStore from "../../../stores/ChannelStore";
import PermissionStore from "../../../stores/PermissionStore";
import SelectedChannelStore from "../../../stores/SelectedChannelStore";
import { AnalyticEvents, Permissions } from "../../../Constants";
import { AppLauncherRouteName } from "../../app_launcher/native/AppLauncherNativeConstants";
import { createStyles } from "../../../design/components/Styles/native/createStyles";
import Module712 from "../../../_bundle/Module712";
import { useStore, OrientationType } from "../../device/native/DeviceOrientation";
import { intl, t } from "../../../intl/index.native";
import ModalActionCreators from "../../../actions/ModalActionCreators";
import { transitionToGuild } from "../../routing/transitionToGuild.native";
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
import { useStateFromStores } from "../../../_bundle/Module589";
import ActionSheetActionCreators from "../../action_sheet/native/ActionSheetActionCreators";
import { getBestActiveInput } from "../../../utils/native/ChatInputUtils";
import { KeyboardTypes } from "../../keyboard/native/KeyboardTypes";
import { SafeAreaPaddingView } from "../../../components_native/common/SafeAreaView";
import Module11003 from "../../../_bundle/Module11003";
import { Text } from "../../../design/components/Text/native/Text";
import { Button } from "../../../design/components/Button/native/Button.native";
const useStyles = createStyles({
container: {
flex: 1,
backgroundColor: Module712.colors.BACKGROUND_BASE_LOWER
},
scrollView: {
flex: 1
},
scrollViewContentContainer: {
height: "100%",
backgroundColor: Module712.colors.BACKGROUND_BASE_LOW,
alignItems: "center",
justifyContent: "center"
},
inner: {
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
paddingHorizontal: 16
},
text: {
marginTop: 24,
paddingHorizontal: 40,
textAlign: "center"
},
footer: {
flexDirection: "column",
justifyContent: "space-between",
padding: 16,
gap: 16
},
footerLandscape: {
flexDirection: "row-reverse",
padding: 16
},
footerPortrait: {
flexDirection: "column",
padding: 16
}
});
export default function SuccessResultModal(props) {
let stateFromStores, stateFromStores2;
const { guild, application } = props;
stateFromStores = void 0;
stateFromStores2 = void 0;
const styles = useStyles();
const orientation = useStore().orientation;
const memo = useMemo(() => application != null ? guild != null ? intl.format(t.IlF6IY, {
installedApplicationName: application?.name,
guildName: guild?.name
}) : intl.format(t.vTVC5T, {
installedApplicationName: application?.name
}) : intl.string(t["Dp+rgP"]), [application, guild]);
const callback3 = useCallback(() => {
if (guild?.id != null) {
ModalActionCreators.pop();
transitionToGuild(guild?.id);
AnalyticsUtils.track(AnalyticEvents.OAUTH2_AUTHORIZE_SUCCESS_GO_TO_GUILD_CLICKED, {
application_id: application?.id,
guild_id: guild?.id
});
}
}, [guild, application?.id]);
stateFromStores = useStateFromStores([SelectedChannelStore], () => SelectedChannelStore.getChannelId());
stateFromStores2 = useStateFromStores([ChannelStore], () => ChannelStore.getChannel(stateFromStores));
const callback2 = useCallback(() => {
ModalActionCreators.pop();
ActionSheetActionCreators.hideActionSheet();
if (stateFromStores != null && application != null) {
AnalyticsUtils.track(AnalyticEvents.OAUTH2_AUTHORIZE_SUCCESS_OPEN_APP_CLICKED, {
application_id: application.id
});
setImmediate(() => {
const bestActiveInput = getBestActiveInput();
if (bestActiveInput != null) {
bestActiveInput.openCustomKeyboard({
type: KeyboardTypes.APP_LAUNCHER,
context: {
initialRouteName: AppLauncherRouteName.APPLICATION_VIEW,
application
}
});
}
});
}
}, [application, stateFromStores]);
const callback = useCallback(() => {
ModalActionCreators.pop();
AnalyticsUtils.track(AnalyticEvents.OAUTH2_AUTHORIZE_SUCCESS_CLOSE_CLICKED, {
application_id: application?.id
});
}, [application?.id]);
useEffect(() => {
AnalyticsUtils.track(AnalyticEvents.OAUTH2_AUTHORIZE_SUCCESS_VIEWED, {
application_id: application?.id
});
}, [application?.id]);
const stateFromStores3 = useStateFromStores([PermissionStore], () => PermissionStore.can(Permissions.SEND_MESSAGES, stateFromStores2));
const r109 = [<ScrollView style={styles.scrollView} contentContainerStyle={styles.scrollViewContentContainer}>
<View style={styles.inner}>
<Image2 source={Module11003} />
<Text style={styles.text} variant="text-lg/medium">
{intl.string(t.se5gLj)}
</Text>
{memo != null ? <Text style={styles.text} variant="text-sm/normal">{memo}</Text> : null}
</View>
</ScrollView>, <View style={[styles.footer, orientation === OrientationType.LANDSCAPE ? styles.footerLandscape : styles.footerPortrait]}>
<>
{guild != null ? <Button size="lg" text={intl.formatToPlainString(t.UdYYP3, {
guildName: guild?.name
})} onPress={callback3} /> : null}
{stateFromStores != null ? stateFromStores3 ? <Button size="lg" text={intl.string(t["0cCDKP"])} onPress={callback2} /> : null : null}
<Button size="lg" variant={guild != null ? "tertiary" : void 0} text={intl.string(t.cpT0Cq)} onPress={callback} />
</>
</View>];
return <SafeAreaPaddingView bottom style={styles.container}>{r109}</SafeAreaPaddingView>;
};