200 lines
8.1 KiB
TypeScript
200 lines
8.1 KiB
TypeScript
// Metro module 16718 (f16719).
|
|
import { useState, useCallback } from "react";
|
|
import { View } from "react-native";
|
|
import FamilyCenterStore from "../../../parent_tools/FamilyCenterStore";
|
|
import UserStore from "../../../../stores/UserStore";
|
|
import { CONNECT_GUARDIAN_BOTTOM_SHEET_KEY } from "../../../parent_tools/FamilyCenterConstants";
|
|
import { createStyles } from "../../../../design/components/Styles/native/createStyles";
|
|
import Module712 from "../../../../_bundle/Module712";
|
|
import { useOnTaskComplete } from "../SafetyFlowsUtils";
|
|
import { useSafetyFlowTask } from "../../SafetyFlowsTaskContext";
|
|
import { useFamilyCenterActions } from "../../../parent_tools/hooks/useFamilyCenterActions";
|
|
import useMountEffect from "../../../../hooks/useMountEffect";
|
|
import { clearWarning } from "../../../parent_tools/ParentalConsentWarningActionCreators";
|
|
import useOnNewPendingRequest from "../../../parent_tools/hooks/useOnNewPendingRequest";
|
|
import { usePendingRequestCount, useHasActiveParentLinks } from "../../../parent_tools/hooks/useUserLinks";
|
|
import { useStateFromStores } from "../../../../_bundle/Module589";
|
|
import { shareGuardianConnectLink } from "../../../parent_tools/native/shareGuardianConnectLink";
|
|
import { useDerivedPendingRequests } from "../../usePendingParentRequests";
|
|
import { TaskInputType } from "../../types";
|
|
import ToastActionCreators from "../../../toast/native/ToastActionCreators";
|
|
import { intl } from "../../../../intl/index.native";
|
|
import SafetyFlows_messages from "../../SafetyFlows.messages";
|
|
import ActionSheetActionCreators from "../../../action_sheet/native/ActionSheetActionCreators";
|
|
import SafetyFlowTaskScreen from "../SafetyFlowTaskScreen";
|
|
import { ModalFooter } from "../../../../design/components/Modal/native/ModalFooter.native";
|
|
import { Stack } from "../../../../design/components/Stack/native/Stack.native";
|
|
import AgeUpdateFooter from "../../../parental_consent/native/AgeUpdateFooter";
|
|
import { ModalActionButton } from "../../../../design/components/Modal/native/ModalActionButton.native";
|
|
import PendingRequestList from "./PendingRequestList";
|
|
import { Text } from "../../../../design/components/Text/native/Text";
|
|
import FamilyCenter_messages from "../../../parent_tools/FamilyCenter.messages";
|
|
import { ConnectGuardianCard } from "../../../parent_tools/native/ConnectGuardianCard";
|
|
const link = "https://support.discord.com/hc/articles/14155060633623";
|
|
const useStyles = createStyles({
|
|
body: {
|
|
marginTop: Module712.space.PX_24
|
|
},
|
|
cardSection: {
|
|
alignItems: "center"
|
|
},
|
|
cardTitle: {
|
|
marginTop: Module712.space.PX_12,
|
|
marginBottom: Module712.space.PX_24,
|
|
textAlign: "center"
|
|
}
|
|
});
|
|
export default function ParentalConsentConnectionScreen() {
|
|
let link_code, expiresAt, stateFromStores;
|
|
const styles = useStyles();
|
|
const onTaskComplete = useOnTaskComplete();
|
|
const task = useSafetyFlowTask().task;
|
|
const getLinkCode = useFamilyCenterActions().getLinkCode;
|
|
useMountEffect(() => {
|
|
clearWarning();
|
|
});
|
|
useOnNewPendingRequest(getLinkCode);
|
|
let component = task.ui_component.component;
|
|
if (component == null) {
|
|
component = {};
|
|
}
|
|
const link_code2 = component.link_code;
|
|
let r13 = "";
|
|
const r15 = typeof link_code2 === "string" ? component.link_code : "";
|
|
if (typeof component.link_code_expires_at === "string") {
|
|
r13 = component.link_code_expires_at;
|
|
}
|
|
const r17 = Array.isArray(component.pending_requests) ? component.pending_requests : [];
|
|
const pendingRequestCount = usePendingRequestCount();
|
|
const hasActiveParentLinks = useHasActiveParentLinks();
|
|
const stateFromStores2 = useStateFromStores([FamilyCenterStore], () => FamilyCenterStore.getLinkedUsers());
|
|
const stateFromStores3 = useStateFromStores([FamilyCenterStore], () => FamilyCenterStore.getAreLinkedUsersProcessed());
|
|
let r76 = stateFromStores3 ? Object.values(stateFromStores2).some((item) => item != null) : r17.length > 0;
|
|
const pendingCount = stateFromStores3 ? pendingRequestCount : r17.length;
|
|
const [state, setState2] = useState(r76);
|
|
if (r76) {
|
|
r76 = !state;
|
|
}
|
|
if (r76) {
|
|
setState2(true);
|
|
}
|
|
const stateFromStores4 = useStateFromStores([FamilyCenterStore], () => FamilyCenterStore.getLinkCode());
|
|
const stateFromStores5 = useStateFromStores([FamilyCenterStore], () => FamilyCenterStore.getLinkCodeExpiresAt());
|
|
let r101 = stateFromStores4;
|
|
if (r101 == null) {
|
|
r101 = r15;
|
|
}
|
|
link_code = r101;
|
|
let r102 = stateFromStores5;
|
|
if (r102 == null) {
|
|
r102 = Date.parse(r13);
|
|
}
|
|
expiresAt = r102;
|
|
stateFromStores = useStateFromStores([UserStore], () => UserStore.getCurrentUser());
|
|
const callback2 = useCallback(() => {
|
|
if (stateFromStores != null && link_code !== "") {
|
|
shareGuardianConnectLink(stateFromStores, link_code);
|
|
}
|
|
}, [stateFromStores, link_code]);
|
|
const derivedPendingRequests = useDerivedPendingRequests(r17, stateFromStores3);
|
|
const [submitting, setState] = useState(false);
|
|
const callback = useCallback(async () => {
|
|
let c28505_2;
|
|
let c28505_3 = 0;
|
|
L10: {
|
|
try {
|
|
setState(true);
|
|
c28505_3 = 2;
|
|
await onTaskComplete({
|
|
type: TaskInputType.Empty
|
|
});
|
|
c28505_3 = 1;
|
|
c28505_3 = 0;
|
|
(0, setState)(false);
|
|
} catch ($e) {
|
|
const r28 = $e;
|
|
let r7 = r28;
|
|
c28505_2 = r28;
|
|
let r29 = c28505_3;
|
|
if (r29 !== 0) {
|
|
while (true) {
|
|
if (r29 === 1) {
|
|
try {
|
|
const r90 = c28505_2;
|
|
c28505_3 = 0;
|
|
(0, setState)(false);
|
|
throw r90;
|
|
} catch (r88) {
|
|
r7 = r88;
|
|
c28505_2 = r88;
|
|
r29 = c28505_3;
|
|
if (r29 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
try {
|
|
c28505_3 = 1;
|
|
ToastActionCreators.open({
|
|
key: "SAFETY_FLOWS_PARENTAL_CONSENT_CONNECTION_ERROR",
|
|
content: intl.string(SafetyFlows_messages["+QRSxc"])
|
|
});
|
|
c28505_3 = 0;
|
|
(0, setState)(false);
|
|
break L10;
|
|
} catch (r63) {
|
|
r7 = r63;
|
|
c28505_2 = r63;
|
|
r29 = c28505_3;
|
|
if (r29 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r7;
|
|
}
|
|
}
|
|
}, [onTaskComplete]);
|
|
const callback3 = useCallback(() => {
|
|
ActionSheetActionCreators.openLazy(import("../../../parent_tools/native/ConnectGuardianBottomSheet"), CONNECT_GUARDIAN_BOTTOM_SHEET_KEY, {
|
|
linkCode: link_code,
|
|
expiresAt,
|
|
onRefresh: getLinkCode,
|
|
title: intl.string(SafetyFlows_messages.dMMSA0),
|
|
body: intl.format(SafetyFlows_messages["6GaRTu"], {
|
|
link
|
|
})
|
|
});
|
|
}, [link_code, expiresAt, getLinkCode]);
|
|
const props = {
|
|
title: intl.string(SafetyFlows_messages.dMMSA0),
|
|
subtitle: state ? intl.format(SafetyFlows_messages["Ke+kz5"], {
|
|
pendingCount,
|
|
link
|
|
}) : intl.format(SafetyFlows_messages["6GaRTu"], {
|
|
link
|
|
}),
|
|
subtitleColor: "text-muted",
|
|
submitting,
|
|
footer: null,
|
|
children: null
|
|
};
|
|
props.footer = <ModalFooter>
|
|
<Stack spacing={Module712.space.PX_16}>
|
|
<AgeUpdateFooter />
|
|
{state && <ModalActionButton variant="primary" text={intl.string(SafetyFlows_messages.OaHZUf)} disabled={hasActiveParentLinks ? submitting : !hasActiveParentLinks} loading={submitting} onPress={callback} />}
|
|
</Stack>
|
|
</ModalFooter>;
|
|
props.children = <Stack spacing={Module712.space.PX_16} style={styles.body}>
|
|
{state ? <PendingRequestList pendingRequests={derivedPendingRequests} linkedUsersProcessed={stateFromStores3} expiresAt={expiresAt} onRefreshLinkCode={getLinkCode} onShare={callback2} onInviteAnotherGuardian={callback3} /> : <View style={styles.cardSection}>
|
|
<Text style={styles.cardTitle} variant="text-md/semibold" color="mobile-text-heading-primary">
|
|
{intl.string(FamilyCenter_messages.pojgfk)}
|
|
</Text>
|
|
<ConnectGuardianCard shareActions="full" linkCode={link_code} expiresAt={expiresAt} onRefresh={getLinkCode} />
|
|
</View>}
|
|
</Stack>;
|
|
return <SafetyFlowTaskScreen {...props} />;
|
|
};
|