import { useDeviceAPI, useMobile, useUserAPI } from "hooks"; import PageContainer from "./PageContainer"; import { useEffect, useState } from "react"; import { Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Divider, Grid2, MenuItem, TextField, Typography } from "@mui/material"; import { useBinAPI, useGlobalState, useTeamAPI } from "providers"; import { CheckCircleOutline } from "@mui/icons-material"; import { green } from "@mui/material/colors"; import Tour, { TourStep } from "common/Tour"; import Emoji from "react-emoji-render"; import { getWhitelabel, getFeatures } from "services/whiteLabel"; import { pond } from "protobuf-ts/pond"; import { User } from "models"; // import { color } from "framer-motion"; // interface Props { // } // export default function SignupCallback (props: Props) { export default function SignupCallback () { const userAPI = useUserAPI(); const teamAPI = useTeamAPI() const deviceAPI = useDeviceAPI(); const binAPI = useBinAPI(); const isMobile = useMobile() const [globalState, dispatch] = useGlobalState(); const whiteLabel = getWhitelabel() const [loading, setLoading] = useState(false) const [signupDialogOpen, setSignupDialogOpen] = useState(true) const [hasTeams, setHasTeams] = useState(false) const [hasDevices, setHasDevices] = useState(false) const [hasBins, setHasBins] = useState(false) const [isTourRunning, setIsTourRunning] = useState(false); const [stepIndex, setStepIndex] = useState(0) const [doneBins, setDoneBins] = useState(false) const [doneTeams, setDoneTeams] = useState(false) const [doneDevices, setDoneDevices] = useState(false) const [user, setUser] = useState(globalState.user); useEffect(() => { setLoading(true) userAPI.completeSignup().then(() => { teamAPI.listTeams(1, 0).then(resp => { setHasTeams(resp.data.teams.length > 0) }).finally(() => setDoneTeams(true)) deviceAPI.list(1, 0).then(resp => { setHasDevices(resp.data.devices.length > 0) }).finally(() => setDoneDevices(true)) binAPI.listBins(1, 0).then(resp => { setHasBins(resp.data.bins.length > 0) }).finally(() => setDoneBins(true)) }).finally(() => setLoading(false)) }, []) const loadingComplete = () => { return loading === false && doneBins && doneTeams && doneDevices } const changePressureUnit = (value: any) => { let updatedUser = User.clone(user) let pressureUnit: pond.PressureUnit; switch (value) { case 1: pressureUnit = pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS; break; case 2: pressureUnit = pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER; break; default: pressureUnit = pond.PressureUnit.PRESSURE_UNIT_UNKNOWN; break; } updatedUser.settings.pressureUnit = pressureUnit; setUser(updatedUser) }; const changeTemperatureUnit = (value: any) => { let updatedUser = User.clone(user); let temperatureUnit: pond.TemperatureUnit; switch (value) { case 1: temperatureUnit = pond.TemperatureUnit.TEMPERATURE_UNIT_CELSIUS; break; case 2: temperatureUnit = pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT; break; default: temperatureUnit = pond.TemperatureUnit.TEMPERATURE_UNIT_UNKNOWN; break; } updatedUser.settings.temperatureUnit = temperatureUnit; setUser(updatedUser); }; const unitPreferences = () => { const { pressureUnit, temperatureUnit, distanceUnit, grainUnit } = user.settings; return ( changePressureUnit(event.target.value)} margin="normal" variant="outlined" InputLabelProps={{ shrink: true }}> Kilopascals (kPa) Inches of Water (iwg) changeTemperatureUnit(event.target.value)} margin="normal" variant="outlined" InputLabelProps={{ shrink: true }}> Celsius (°C) Fahrenheit (°F) changeDistanceUnit(event.target.value)} margin="normal" variant="outlined" InputLabelProps={{ shrink: true }}> Meters (m) Feet (ft) {getFeatures().grainUnit && ( changeGrainUnit(event.target.value)} margin="normal" variant="outlined" InputLabelProps={{ shrink: true }}> Bushels (bu) Tonnes (mT) US Tons (t) )} ); }; const content = () => { return ( { loadingComplete() ? : } {hasTeams && "Teams found!"}
{hasDevices && "Devices found!"}
{hasBins && "Bins found!"}
) } const getTourSteps = (): TourStep[] => { let steps: TourStep[] = [ { title: ( <> Welcome to {whiteLabel.name} ), content: ( <> {"Hello " + user.name()} Thank you for signing up! Let me give you the tour ), target: "body", placement: "center", disableBeacon: true, }, { title: "User Menu", content: ( <> In the user menu, you can make changes to your profile, such as adjusting unit preferences.
If you are part of a team, you can select it here as well.
Set your unit preferences here now, they can be changed later from this menu: {unitPreferences()} ), target: "#tour-user-menu", placement: "bottom", disableBeacon: true, // onNext: () => setDoneFirst(true) }, // { // title: // } ]; if (hasTeams) steps.push({ title: "Teams", content: ( <> Here, you can view your team(s), access their settings, and choose your favourite. ), target: "#tour-teams", placement: "right", // spotlightPadding: 50, }) steps.push({ title: "Devices", content: ( <> You can view your devices and their readings here.
If you are viewing as a team, your team's devices will be displayed here instead. ), target: "#tour-dashboard", placement: "right" }) steps.push({ title: "Tasks", content: ( <> You can view and create tasks here and assign a start and end time for them.
If you are viewing as a team you will see the teams tasks, you can even assign tasks to team members. ), target: "#tour-tasks", placement: "right" }) //tasks step if (getFeatures().visualFarm) { steps.push({ title: "Visual Farm", content: ( <> You can view your Visual Farm here, it will allow tou to draw fields and plot bins an a map.
If you are viewing as a team, your team's fields and bins will be displayed here instead. ), target: "#tour-visual-farm", placement: "right", disableBeacon: true, }) steps.push({ title: "Fields", content: ( <> You can view your fields you have drawn on the map here.
If you are viewing as a team, your team's fields will be displayed here instead. ), target: "#tour-field-list", placement: "right", disableBeacon: true, }) steps.push({ title: "Bins", content: ( <> You can view your bins and their inventory here.
If you are viewing as a team, your team's bins will be displayed here instead. ), target: "#tour-bins", placement: "right", disableBeacon: true, }) steps.push({ title: "Contracts", content: ( <> You can view and track any contracts you have created here.
If you are viewing as a team, your team's contracts will be displayed here instead. ), target: "#tour-contracts", placement: "right", disableBeacon: true, }) } return steps; }; const endTour = () => { setIsTourRunning(false); if (user) { userAPI .updateUser(user.id(), user.protobuf()) .then(() => dispatch({ key: "user", value: user })) .catch((err: any) => console.error(err)); } }; const closeDialog = () => { setSignupDialogOpen(false) setIsTourRunning(true) } useEffect(() => { console.log(stepIndex) }, [stepIndex]) return ( Finishing Signup { content() } {loadingComplete() && } ) }