From 4f168bb47db68ddb9e1f02dbcdda8ce47c7d5ccd Mon Sep 17 00:00:00 2001 From: tsh22 Date: Wed, 27 Apr 2022 17:09:47 +0800 Subject: [PATCH] Implement time restriction on returns and fix errors --- screens/return-screens/TempReturnSelection.js | 159 ++++++++++-------- 1 file changed, 89 insertions(+), 70 deletions(-) diff --git a/screens/return-screens/TempReturnSelection.js b/screens/return-screens/TempReturnSelection.js index 77569b6..6cbdcc4 100644 --- a/screens/return-screens/TempReturnSelection.js +++ b/screens/return-screens/TempReturnSelection.js @@ -21,22 +21,30 @@ import { backActionHandler } from "../BasicApi"; import RNPickerSelect from "react-native-picker-select"; import { useFocusEffect } from "@react-navigation/native"; -function ReturnClaim() { +export default function TempReturnSelection() { + // Prevent back button action on Android + useBackHandler(backActionHandler); + const [numCups, setCupNum] = useState(0); const [numContainers, setContainerNum] = useState(0); const [borrowedCup, setBorrowedCup] = useState(0); const [borrowedContainer, setBorrowedContainer] = useState(0); const [location, setLocation] = useState(""); + const [isPressed, setPress] = useState(false); + + const currTime = moment(); + // const currTime = moment("00:00", "HH:mm"); + + // Time that people are allowed to return in moment format for comparison + const legalStartTime = moment("08:00", "HH:mm"); + const legalEndTime = moment("18:30", "HH:mm"); + const weekday = ["Mon", "Tue", "Wed", "Thu", "Fri"]; + const currDay = moment().format("ddd"); const userData = useContext(UserContext); const uid = userData.id; const navigation = useNavigation(); - // useEffect(() => { - // getBorrowedNum(uid, setBorrowedCup, setBorrowedContainer); - // console.log("Setting up current user's borrowed items number"); - // }, []); - useFocusEffect( React.useCallback(() => { getBorrowedNum(uid, setBorrowedCup, setBorrowedContainer); @@ -45,8 +53,6 @@ function ReturnClaim() { ); function renderNextButton() { - const [isPressed, setPress] = useState(false); - function changeState() { setPress(true); } @@ -120,71 +126,84 @@ function ReturnClaim() { } } - return ( - - - Step 1: Select number of reusables to return. - - - Step 2: Drop all of them into the bin. - - - Step 3: Click on the orange button below to confirm. - - - - - Location: - - { - setLocation(location); - // console.log("Location: ", location); - }} - value={location} - items={locations} - placeholder={{ - label: "Select location", - value: "", - }} - useNativeAndroidPickerStyle={false} - style={{ - ...pickerSelectStyles, - placeholder: styles.dropdownPlaceholder, - }} - /> - - - - {renderNextButton(location)} - - ); -} + // Returning within legal time limits and only on weekdays + if ( + currTime.isBetween(legalStartTime, legalEndTime) && + weekday.includes(currDay) + ) { + return ( + + + + + + Step 1: Select number of reusables to return. + + + Step 2: Drop all of them into the bin. + + + Step 3: Click on the orange button below to confirm. + + -export default function ReturnErrorScreen({ navigation, route }) { - // Prevent back button action on Android - useBackHandler(backActionHandler); + + Location: + + { + setLocation(location); + // console.log("Location: ", location); + }} + value={location} + items={locations} + placeholder={{ + label: "Select location", + value: "", + }} + useNativeAndroidPickerStyle={false} + style={{ + ...pickerSelectStyles, + placeholder: styles.dropdownPlaceholder, + }} + /> + + - return ( - - - - + {renderNextButton(location)} + + + + ); + } else { + // Returning out of legal time limits + return ( + + + + + To help our cleaners, please return only on weekdays between 8am to + 6.30pm. Thank you! + + - - ); + ); + } } const locations = [