149 lines
6.7 KiB
TypeScript
149 lines
6.7 KiB
TypeScript
// Metro module 13907 (f13908).
|
|
import { useCallback, useEffect } from "react";
|
|
import { View } from "react-native";
|
|
import UserStore from "../../../stores/UserStore";
|
|
import FamilyCenterStore from "../FamilyCenterStore";
|
|
import { CONNECT_GUARDIAN_BOTTOM_SHEET_KEY, FAMILY_CENTER_LINK_REQUEST_REGEX, FamilyCenterAction } from "../FamilyCenterConstants";
|
|
import { AnalyticEvents } from "../../../Constants";
|
|
import { NativePermissionTypes } from "../../native_permissions/NativePermissionConstants";
|
|
import { createStyles } from "../../../design/components/Styles/native/createStyles";
|
|
import Module712 from "../../../_bundle/Module712";
|
|
import { useUserQRLinkUrl, useHasMaxConnections } from "../hooks/useUserLinks";
|
|
import { presentFailedToast } from "../../toast/native/ToastUtils";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
import { useFamilyCenterActions } from "../hooks/useFamilyCenterActions";
|
|
import { useStateFromStores } from "../../../_bundle/defaultAreStatesEqual";
|
|
import useRefreshLinkCodeOnExpiry from "../hooks/useRefreshLinkCodeOnExpiry";
|
|
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
|
|
import { shareGuardianConnectLink } from "./shareGuardianConnectLink";
|
|
import ActionSheetActionCreators from "../../action_sheet/native/ActionSheetActionCreators";
|
|
import { Stack } from "../../../design/components/Stack/native/Stack.native";
|
|
import { Button } from "../../../design/components/Button/native/Button.native";
|
|
import { ShareIcon } from "../../../design/components/Icon/native/redesign/generated/ShareIcon";
|
|
import FamilyCenter_messages from "../FamilyCenter.messages";
|
|
import { QrCodeIcon } from "../../../design/components/Icon/native/redesign/generated/QrCodeIcon";
|
|
import ModalActionCreators from "../../../actions/ModalActionCreators";
|
|
import URLUtils from "../../../utils/URLUtils";
|
|
import { handleFamilyCenterQRCodeScan } from "./FamilyCenterNativeUtils";
|
|
import { isMetaQuest } from "../../device/MetaQuestUtils.android";
|
|
import NativePermissionUtils from "../../native_permissions/NativePermissionUtils";
|
|
let useStyles, useStyles2, FamilyCenterBannerButton;
|
|
const FamilyCenterTeenQRCodeButtonInner = function FamilyCenterTeenQRCodeButtonInner() {
|
|
let getLinkCode, getLinkCode2, stateFromStores, stateFromStores2, stateFromStores3;
|
|
const styles = useStyles();
|
|
const callback = useCallback(() => {
|
|
presentFailedToast(intl.string(t.R0RpRX));
|
|
}, []);
|
|
getLinkCode = useFamilyCenterActions().getLinkCode;
|
|
getLinkCode2 = useFamilyCenterActions({
|
|
onError: callback
|
|
}).getLinkCode;
|
|
stateFromStores = useStateFromStores([UserStore], () => UserStore.getCurrentUser());
|
|
stateFromStores2 = useStateFromStores([FamilyCenterStore], () => FamilyCenterStore.getLinkCode());
|
|
stateFromStores3 = useStateFromStores([FamilyCenterStore], () => FamilyCenterStore.getLinkCodeExpiresAt());
|
|
const userQRLinkUrl = useUserQRLinkUrl();
|
|
useEffect(() => {
|
|
getLinkCode();
|
|
}, []);
|
|
useRefreshLinkCodeOnExpiry(stateFromStores3, getLinkCode);
|
|
const disabled = userQRLinkUrl == null || stateFromStores2 == null || stateFromStores3 == null;
|
|
const callback2 = useCallback(() => {
|
|
if (stateFromStores != null && stateFromStores2 != null) {
|
|
AnalyticsUtils.track(AnalyticEvents.FAMILY_CENTER_ACTION, {
|
|
action: FamilyCenterAction.ShareLink
|
|
});
|
|
shareGuardianConnectLink(stateFromStores, stateFromStores2);
|
|
}
|
|
}, [stateFromStores, stateFromStores2]);
|
|
const callback3 = useCallback(() => {
|
|
if (stateFromStores2 != null && stateFromStores3 != null) {
|
|
AnalyticsUtils.track(AnalyticEvents.FAMILY_CENTER_ACTION, {
|
|
action: FamilyCenterAction.ShowQRCodeModal
|
|
});
|
|
ActionSheetActionCreators.openLazy(import("./ConnectGuardianBottomSheet"), CONNECT_GUARDIAN_BOTTOM_SHEET_KEY, {
|
|
linkCode: stateFromStores2,
|
|
expiresAt: stateFromStores3,
|
|
onRefresh: getLinkCode2
|
|
});
|
|
}
|
|
}, [stateFromStores2, stateFromStores3, getLinkCode2]);
|
|
return <Stack direction="horizontal" spacing={Module712.space.PX_8} style={styles.container}>
|
|
<Button grow shrink size="md" variant="primary" text={intl.string(t.Ej3B3Y)} disabled={disabled} onPress={callback2} icon={<ShareIcon size="sm" color="control-primary-text-default" />} iconPosition="start" />
|
|
<Button grow shrink size="md" variant="secondary" text={intl.string(FamilyCenter_messages.wd4yrz)} disabled={disabled} onPress={callback3} icon={<QrCodeIcon size="sm" color="control-secondary-text-default" />} iconPosition="start" />
|
|
</Stack>;
|
|
};
|
|
FamilyCenterBannerButton = function FamilyCenterBannerButton(props) {
|
|
const { onPress: onPress2, text, loading } = props;
|
|
const styles2 = useStyles2();
|
|
return <View style={styles2.button}>
|
|
<Button grow shrink size="md" variant="primary" text={text} onPress={onPress2} loading={loading} icon={<QrCodeIcon style={styles2.art} size="custom" color="white" />} iconPosition="start" />
|
|
</View>;
|
|
};
|
|
useStyles = createStyles({
|
|
container: {
|
|
marginTop: Module712.space.PX_16
|
|
}
|
|
});
|
|
useStyles2 = createStyles({
|
|
button: {
|
|
height: 50,
|
|
width: "100%",
|
|
marginTop: 16
|
|
},
|
|
art: {
|
|
width: 18,
|
|
height: 18,
|
|
marginRight: 6
|
|
}
|
|
});
|
|
export default FamilyCenterBannerButton;
|
|
export function FamilyCenterTeenQRCodeButton() {
|
|
return useHasMaxConnections() ? null : <FamilyCenterTeenQRCodeButtonInner />;
|
|
}
|
|
export function FamilyCenterParentQRCodeButton() {
|
|
const handleQrCodeScanSucess2 = function handleQrCodeScanSucess(a0) {
|
|
ModalActionCreators.pop();
|
|
let r15 = URLUtils.toURLSafe(a0);
|
|
if (r15 == null) {
|
|
r15 = {};
|
|
}
|
|
const { hostname, pathname } = r15;
|
|
const r1 = hostname != null;
|
|
let r0 = null;
|
|
if (r1) {
|
|
const r18 = pathname != null;
|
|
r0 = null;
|
|
if (r18) {
|
|
const isDiscordHostname = URLUtils.isDiscordHostname(hostname);
|
|
r0 = null;
|
|
if (isDiscordHostname) {
|
|
const r25 = pathname.match(FAMILY_CENTER_LINK_REQUEST_REGEX);
|
|
let r26 = null;
|
|
if (r25 !== null) {
|
|
handleFamilyCenterQRCodeScan(pathname, "FamilyCenterQRCodeScan");
|
|
r26 = void 0;
|
|
}
|
|
r0 = r26;
|
|
}
|
|
}
|
|
}
|
|
return r0;
|
|
};
|
|
if (useHasMaxConnections()) {
|
|
return null;
|
|
}
|
|
return <FamilyCenterBannerButton text={intl.string(FamilyCenter_messages.z4a9HP)} onPress={() => {
|
|
AnalyticsUtils.track(AnalyticEvents.FAMILY_CENTER_ACTION, {
|
|
action: FamilyCenterAction.ScanQRCodeButton
|
|
});
|
|
NativePermissionUtils.requestPermission(isMetaQuest() ? NativePermissionTypes.HEADSET_CAMERA : NativePermissionTypes.CAMERA).then((result) => {
|
|
if (result) {
|
|
ModalActionCreators.pushLazy(import("../../../components_native/QRScannerModal"), {
|
|
showHelp: false,
|
|
onScanSuccess: handleQrCodeScanSucess2
|
|
});
|
|
}
|
|
});
|
|
}} />;
|
|
}
|