mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 00:24:53 +00:00
- Implemented spending of the saved points
This commit is contained in:
@ -1,18 +1,20 @@
|
||||
import {Button, ButtonSize, Dialog, ProgressBar, Text, TouchableOpacity, View,} from "react-native-ui-lib";
|
||||
import React, {useEffect, useState} from "react";
|
||||
import {StyleSheet} from "react-native";
|
||||
import { Button, ButtonSize, Dialog, ProgressBar, Text, TouchableOpacity, View, } from "react-native-ui-lib";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {Alert, StyleSheet } from "react-native";
|
||||
import UserChart from "./UserChart";
|
||||
import ProgressCard, {transformNumber} from "../ProgressCard";
|
||||
import {AntDesign, Ionicons} from "@expo/vector-icons";
|
||||
import {ScrollView} from "react-native-gesture-handler";
|
||||
import { AntDesign, Ionicons } from "@expo/vector-icons";
|
||||
import { ScrollView } from "react-native-gesture-handler";
|
||||
import FireworksOrangeIcon from "@/assets/svgs/FireworksOrangeIcon";
|
||||
import {useAuthContext} from "@/contexts/AuthContext";
|
||||
import { useAuthContext } from "@/contexts/AuthContext";
|
||||
import { useSpendPoints } from "@/hooks/firebase/useUpdateUserData";
|
||||
|
||||
const PROGRESS_LIMIT = 5000;
|
||||
|
||||
const UserChoresProgress = ({ setPageIndex }: { setPageIndex: (value: number) => void; }) => {
|
||||
const [modalVisible, setModalVisible] = useState<boolean>(false);
|
||||
const { profileData, refreshProfileData } = useAuthContext();
|
||||
const { mutateAsync: spendPoints } = useSpendPoints();
|
||||
|
||||
const allTimePoints = profileData?.allTimePoints ?? 0;
|
||||
let transformedAllTimePoints = transformNumber(allTimePoints, PROGRESS_LIMIT);
|
||||
@ -21,6 +23,15 @@ const UserChoresProgress = ({ setPageIndex }: { setPageIndex: (value: number) =>
|
||||
refreshProfileData();
|
||||
}, [])
|
||||
|
||||
const onClickSpendPoints = (pointsToSpend: number) => {
|
||||
if (allTimePoints < pointsToSpend) {
|
||||
Alert.alert("Not Enough Points", "You do not have enough points to spend.");
|
||||
return;
|
||||
} else {
|
||||
spendPoints(pointsToSpend).then(() => setModalVisible(false)).then(refreshProfileData);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<View marginT-20 paddingB-20>
|
||||
<ScrollView
|
||||
@ -68,7 +79,6 @@ const UserChoresProgress = ({ setPageIndex }: { setPageIndex: (value: number) =>
|
||||
</Text>
|
||||
<Button
|
||||
size={ButtonSize.small}
|
||||
disabled
|
||||
label="Spend my points"
|
||||
color="#50be0c"
|
||||
backgroundColor="#ebf2e4"
|
||||
@ -110,7 +120,7 @@ const UserChoresProgress = ({ setPageIndex }: { setPageIndex: (value: number) =>
|
||||
/>
|
||||
<View row spread>
|
||||
<Text style={{fontSize: 13, color: "#858585"}}>0</Text>
|
||||
<Text style={{fontSize: 13, color: "#858585"}}>5000</Text>
|
||||
<Text style={{fontSize: 13, color: "#858585"}}>{PROGRESS_LIMIT}</Text>
|
||||
</View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
@ -129,6 +139,7 @@ const UserChoresProgress = ({ setPageIndex }: { setPageIndex: (value: number) =>
|
||||
backgroundColor="#05a8b6"
|
||||
size={ButtonSize.large}
|
||||
labelStyle={styles.bigButtonText}
|
||||
onPress={() => onClickSpendPoints(150)}
|
||||
/>
|
||||
<Button
|
||||
label="Extra Screen Time - 100 pts"
|
||||
@ -137,6 +148,7 @@ const UserChoresProgress = ({ setPageIndex }: { setPageIndex: (value: number) =>
|
||||
backgroundColor="#ea156c"
|
||||
size={ButtonSize.large}
|
||||
labelStyle={styles.bigButtonText}
|
||||
onPress={() => onClickSpendPoints(100)}
|
||||
/>
|
||||
<Button
|
||||
label="Movie Night - 50 pts"
|
||||
@ -145,6 +157,7 @@ const UserChoresProgress = ({ setPageIndex }: { setPageIndex: (value: number) =>
|
||||
backgroundColor="#7305d4"
|
||||
size={ButtonSize.large}
|
||||
labelStyle={styles.bigButtonText}
|
||||
onPress={() => onClickSpendPoints(50)}
|
||||
/>
|
||||
<Button
|
||||
label="Ice Cream Treat - 25 pts"
|
||||
@ -153,6 +166,7 @@ const UserChoresProgress = ({ setPageIndex }: { setPageIndex: (value: number) =>
|
||||
backgroundColor="#e28800"
|
||||
size={ButtonSize.large}
|
||||
labelStyle={styles.bigButtonText}
|
||||
onPress={() => onClickSpendPoints(25)}
|
||||
/>
|
||||
<TouchableOpacity onPress={() => setModalVisible(false)}>
|
||||
<Text text70 marginT-20 center color="#999999" style={{fontFamily: 'Manrope_500Medium'}}>
|
||||
|
||||
Reference in New Issue
Block a user