import { Help } from "@mui/icons-material"; import { Avatar, Box, Button, DialogActions, DialogContent, DialogTitle, Grid2 as Grid, MenuItem, TextField, Tooltip, Typography } from "@mui/material"; import ResponsiveDialog from "common/ResponsiveDialog"; import { teamScope, User } from "models"; import { pond } from "protobuf-ts/pond"; import { useGlobalState, useSnackbar, useUserAPI } from "providers"; import { useLibraCartProxyAPI } from "providers/pond/libracartProxyAPI"; import React, { useEffect, useState } from "react"; import TeamSearch from "teams/TeamSearch"; export default function LibraCartAccess() { const [openDialog, setOpenDialog] = useState(false); const [teamKey, setTeamKey] = useState(""); const [teamUsers, setTeamUsers] = useState([]); const [primaryUser, setPrimaryUser] = useState(""); const [libracartUsername, setLibraCartUserName] = useState(""); const [libracartCode, setLibraCartCode] = useState(""); const [libracartAuth, setLibraCartAuth] = useState(""); //const [activeStep, setActiveStep] = useState(0); const userAPI = useUserAPI(); const libracartAPI = useLibraCartProxyAPI(); //const [dataOps, setDataOps] = useState([]); const { openSnack } = useSnackbar(); const [{ as }] = useGlobalState(); const submitNewOrganization = () => { if (libracartCode && libracartAuth) { libracartAPI .addAccount(teamKey, primaryUser, libracartCode, libracartAuth, libracartUsername) .then(resp => { openSnack("Added New Libra Cart Account Link"); }) .catch(err => { openSnack("Failed to Add New Libra Cart Account Link"); }); setOpenDialog(false); } }; useEffect(() => { if (teamKey !== "") { userAPI.listObjectUsers(teamScope(teamKey)).then(resp => { setTeamUsers(resp.data.users.map((u: pond.User) => User.any(u))); }); } }, [teamKey, userAPI]); // useEffect(() => { // let code = localStorage.getItem("state"); // if (code) { // setLibraCartCode(code); // setOpenDialog(true); // } // }, [searchParams, libracartCode]); useEffect(() => { let code = new URLSearchParams(window.location.search).get("state"); // this is the account_code let auth = new URLSearchParams(window.location.search).get("authorization_token"); // this is the authorization used to verify where it came from if (code && auth) { setLibraCartCode(code); setLibraCartAuth(auth); setOpenDialog(true); } }, [window.location]); const validate = () => { let invalid = false; if (libracartUsername === "" || teamKey === "" || primaryUser === "" || libracartCode === "") { invalid = true; } return invalid; }; const general = () => { return ( setLibraCartUserName(e.target.value)} /> setPrimaryUser(e.target.value)}> {teamUsers.map(u => ( {u.name()} ))} ); }; const newOrgDialog = () => { return ( { setOpenDialog(false); }}> Enter New Integration Link {general()} ); }; return ( Libra Cart data will sync every 6 hours, if the data is needed immediately you can select the Sync button. It may take up to 15 minutes for the data to appear in our platform. {newOrgDialog()} ); }