Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

must get the actionIdentifier from the button AND categoryIdentifier OF REQUEST #53

Open
github-actions bot opened this issue Dec 21, 2022 · 0 comments
Labels

Comments

@github-actions
Copy link

actionIdentifier: "approve", // TODO must get the actionIdentifier from the button AND categoryIdentifier OF REQUEST

import React, { useState, useContext } from "react";

import { SafeAreaView, View, useColorScheme } from "react-native";

import {
    Appbar,
    Menu,
    IconButton,
    Colors,
    Button,
    Modal,
    Dialog,
    Portal,
    Paragraph,
} from "react-native-paper";

import * as Notifications from "expo-notifications";
// import { Picker } from "@react-native-picker/picker";

// import { PaperSelect } from "react-native-paper-select";

import DropDown from "react-native-paper-dropdown";

import { Separator } from "../components/Shared";

import { useTheme } from "react-native-paper";

import { AppReducer } from "../const";
import { setPushResponse } from "../reducers/app";

import apiService from "../service/api";
import styles from "../styles";

export default function NotificationPopup() {
    const theme = useTheme();
    const colorScheme = useColorScheme();

    const { state, dispatch } = useContext(AppReducer);

    const [visible, setVisible] = useState(false);
    const [loading, setLoading] = useState(false);

    const [pushContent, setPushContent] = useState(null);

    const themedStyles = styles(colorScheme);

    const lastNotificationResponse = Notifications.useLastNotificationResponse();

    React.useEffect(() => {
        if (!lastNotificationResponse) return;

        console.log("lastNotificationResponse", lastNotificationResponse);
        setPushContent(lastNotificationResponse.notification.request.content);

        // only load for the default type
        if (
            lastNotificationResponse &&
            lastNotificationResponse.actionIdentifier === Notifications.DEFAULT_ACTION_IDENTIFIER
        ) {
            setVisible(true);
        }
    }, [lastNotificationResponse]);

    // TODO build a list of categories and functions to generate action buttons

    return (
        <Portal>
            <Modal
                style={{ backgroundColor: "#000000FF" }}
                visible={visible}
                onDismiss={() => setVisible(false)}
                contentContainerStyle={{
                    backgroundColor: theme.colors.backdrop,
                    margin: 20,
                }}
            >
                <Dialog.Title>Incoming Push</Dialog.Title>
                <Dialog.Content>
                    {lastNotificationResponse && pushContent && (
                        <View>
                            <Paragraph>
                                actionIdentifier: {lastNotificationResponse.actionIdentifier}
                            </Paragraph>
                            <Paragraph>title: {pushContent.title}</Paragraph>
                            <Paragraph>body: {pushContent.body}</Paragraph>
                            <Paragraph>categoryIdentifier: {pushContent.categoryIdentifier}</Paragraph>
                            <Paragraph>pushIdent: {pushContent.data.pushIdent}</Paragraph>
                            <Paragraph>pushId: {pushContent.data.pushId}</Paragraph>
                            <Separator />
                            <Paragraph>{JSON.stringify(lastNotificationResponse)}</Paragraph>
                        </View>
                    )}
                </Dialog.Content>
                <Dialog.Actions>
                    <Button onPress={() => setVisible(false)}>Thanks</Button>
                    <Button
                        onPress={() => {
                            const responseData = {
                                pushIdent: pushContent.data.pushIdent,
                                pushId: pushContent.data.pushId,
                                actionIdentifier: "reject", // TODO must get the actionIdentifier from the button AND categoryIdentifier OF REQUEST
                                categoryIdentifier: pushContent.categoryIdentifier,
                                responseText: null,
                            };
                            dispatch(setPushResponse(responseData));
                            setVisible(false);
                        }}
                        loading={loading}
                    >
                        Reject
                    </Button>
                    <Button
                        onPress={() => {
                            const responseData = {
                                pushIdent: pushContent.data.pushIdent,
                                pushId: pushContent.data.pushId,
                                actionIdentifier: "approve", // TODO must get the actionIdentifier from the button AND categoryIdentifier OF REQUEST
                                categoryIdentifier: pushContent.categoryIdentifier,
                                responseText: null,
                            };
                            dispatch(setPushResponse(responseData));
                            setVisible(false);
                        }}
                        loading={loading}
                    >
                        Approve
                    </Button>
                </Dialog.Actions>
            </Modal>
        </Portal>
    );
}
@github-actions github-actions bot added the todo label Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants