function RequestAccessComponent()

in src/Components/RequestAccessComponent.js [27:65]


function RequestAccessComponent({dbName, tableName, successHandler}) {
    const [targetAccount, setTargetAccount] = useState();
    const [error, setError] = useState();

    const submitRequestAccess = async() => {
        if (targetAccount && targetAccount.length > 0 && !isNaN(targetAccount)) {
            const credentials = await Auth.currentCredentials();
            const sfnClient = new SFNClient({region: config.aws_project_region, credentials: Auth.essentialCredentials(credentials)});
            try {
                const smExecutionParams = {
                    source: {
                        database: dbName,
                        table: tableName
                    },
                    target: {
                        account_id: targetAccount
                    }
                };

                const resp = await sfnClient.send(new StartExecutionCommand({
                    input: JSON.stringify(smExecutionParams),
                    stateMachineArn: SM_ARN
                }));

                setTargetAccount(null);

                if (successHandler) {
                    successHandler(resp.executionArn);
                }
            } catch (e) {
                setError("An unexpected error has occurred: "+e);
            }
        } else {
            setError("Target Account ID is a required field.");
        }
    }

    return (
        <Form actions={<Button variant="primary" onClick={submitRequestAccess}>Submit</Button>} errorText={error}>