Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions app/(auth)/(tabs)/info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import LogoutLink from "@/components/custom/LogoutLink";
import LegalLinks from "@/components/custom/LegalLinks";
import RefreshControl from "@/components/custom/RefreshControl";
import { VStack } from "@/components/ui/vstack";
import { useMemo } from "react";
import { useEffect, useMemo, useState } from "react";
import usePauseDialog, { SetPause } from "@/components/custom/info/PauseDialog";
import { IsPausedHow, SetPauseRequestBody } from "@/utils/user";
import dayjs from "dayjs";
Expand All @@ -35,6 +35,7 @@ import { userUpdate } from "@/api/user";
import { useBottomTabBarHeight } from "@react-navigation/bottom-tabs";
import ReadOnlySwitch from "@/components/custom/ReadOnlySwitch";
import ThemeBackground from "@/components/custom/ThemeBackground";
import { bagGetAllByChain } from "@/api/bag";

export default function Info() {
const { t } = useTranslation();
Expand All @@ -43,6 +44,19 @@ export default function Info() {
const { authUser, currentChain } = useStore(authStore);
const authUserRoles = useStore(authStoreAuthUserRoles);
const queryClient = useQueryClient();
const [isUserHoldingBag, setIsUserHoldingBag] = useState(false);

useEffect(() => {
if (!currentChain || !authUser) {
setIsUserHoldingBag(false);
return;
}
(async () => {
const userBags = (await bagGetAllByChain(currentChain.uid, authUser.uid))
.data;
setIsUserHoldingBag(userBags.length > 0);
})();
}, [authUser, currentChain?.uid]);

const pauseState = useMemo(() => {
let pausedFromNow = "";
Expand Down Expand Up @@ -70,7 +84,7 @@ export default function Info() {
}
}
}
return { pausedFromNow, isUserPausedHow, isUserPaused };
return { pausedFromNow, isUserPausedHow, isUserPaused, isUserHoldingBag };
}, [authUser, currentChain?.uid, t]);

const mutationPause = useMutation({
Expand Down Expand Up @@ -118,7 +132,7 @@ export default function Info() {
) : null}

<Pressable
onPress={() => handleOpenPause(pauseState.isUserPausedHow)}
onPress={() => handleOpenPause(pauseState.isUserPausedHow, isUserHoldingBag)}
>
<HStack className="items-center gap-3 px-4 py-2">
<VStack className="shrink flex-grow items-start">
Expand Down
3 changes: 3 additions & 0 deletions assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
"untilITurnItBackOn": "Until I turn it back on",
"selectPauseDuration": "Select pause duration",
"setTimerForACoupleOfWeeks": "Select how many weeks you want to pause your participation",
"youAreHoldingABag": "You are holding a bag, are you sure you want to pause?",
"yesPause": "Yes, pause",
"noGoToBags": "No, go to bags",
"enableNotifications": "Enable notifications",
"updateHeader": "Edit this page's header",
"updateHeaderDesc": "This change will be visible to all loop members.",
Expand Down
69 changes: 50 additions & 19 deletions components/custom/info/PauseDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { IsPausedHowResult } from "@/utils/user";
import { Alert } from "react-native";
import { useActionSheet } from "@expo/react-native-action-sheet";
import dayjs from "dayjs";
import { router } from "expo-router";

export interface SetPause {
isPausedOrUntil: boolean | Date;
Expand All @@ -28,7 +29,10 @@ const minDate = dayjs().add(1, "day").toDate();
export default function usePauseDialog(props: {
onSubmit: (o: SetPause) => Promise<void>;
}): {
handleOpenPause: (isPauseHow: IsPausedHowResult) => void;
handleOpenPause: (
isPauseHow: IsPausedHowResult,
isUserHoldingBag: boolean,
) => void;
PauseDateDialog: FC;
} {
const [openPauseDuration, setOpenPauseDuration] = useState(false);
Expand Down Expand Up @@ -80,7 +84,10 @@ export default function usePauseDialog(props: {
const { t } = useTranslation();
const defaultStyles = useDefaultStyles();

function handleOpenPause(isPausedHow: IsPausedHowResult) {
function handleOpenPause(
isPausedHow: IsPausedHowResult,
isUserHoldingBag: boolean,
) {
if (isPausedHow.sum) {
Alert.alert(t("unPause"), t("areYouSureUnPause"), [
{
Expand All @@ -95,38 +102,62 @@ export default function usePauseDialog(props: {
style: "cancel",
},
]);
} else {
} else if (isUserHoldingBag) {
showActionSheetWithOptions(
{
title: t("pauseUntil"),
options: [
t("selectPauseDuration"),
t("pauseOnlyLoop"),
t("untilITurnItBackOn"),
t("cancel"),
],
cancelButtonIndex: 3,
title: t("youAreHoldingABag"),
options: [t("yesPause"), t("noGoToBags"), t("cancel")],
cancelButtonIndex: 2,
},
(selectedIndex) => {
switch (selectedIndex) {
case 0:
// selectPauseDuration
setOpenPauseDuration((s) => !s);
// go to bags
HandleShowPauseDurations();
break;
case 1:
// pauseOnlyLoop
form.handleSubmit("on_loop");
break;
case 2:
// untilITurnItBackOn
form.handleSubmit("on_user");
// go to pause options
router.push(`/(auth)/(tabs)/bags`);
break;
}
},
);
} else {
HandleShowPauseDurations();
}
}

function HandleShowPauseDurations() {
showActionSheetWithOptions(
{
title: t("pauseUntil"),
options: [
t("selectPauseDuration"),
t("pauseOnlyLoop"),
t("untilITurnItBackOn"),
t("cancel"),
],
cancelButtonIndex: 3,
},
(selectedIndex) => {
switch (selectedIndex) {
case 0:
// selectPauseDuration
setOpenPauseDuration((s) => !s);
break;
case 1:
// pauseOnlyLoop
form.handleSubmit("on_loop");
break;
case 2:
// untilITurnItBackOn
form.handleSubmit("on_user");
break;
}
},
);
}

const PauseDateDialog = useCallback(
() => (
<AlertDialog
Expand Down