API Calls only for non-TeamLeads (#697)
This commit is contained in:
@@ -8,10 +8,11 @@ interface FloatingBannerCtaProps {
|
||||
onPressHandler: () => void;
|
||||
icon?: JSX.Element;
|
||||
containerStyle?: StyleProp<ViewStyle>;
|
||||
textStyle?: StyleProp<ViewStyle>;
|
||||
}
|
||||
|
||||
const FloatingBannerCta = (props: FloatingBannerCtaProps) => {
|
||||
const { icon, title, onPressHandler, containerStyle } = props;
|
||||
const { icon, title, onPressHandler, containerStyle, textStyle } = props;
|
||||
return (
|
||||
<TouchableOpacity
|
||||
activeOpacity={0.8}
|
||||
@@ -19,7 +20,7 @@ const FloatingBannerCta = (props: FloatingBannerCtaProps) => {
|
||||
onPress={onPressHandler}
|
||||
>
|
||||
{icon ? icon : null}
|
||||
<Text style={GenericStyles.pl6}>{title}</Text>
|
||||
<Text style={[GenericStyles.pl6, textStyle ]}>{title}</Text>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { useAppDispatch, useAppSelector } from '@hooks';
|
||||
import CasesList from './CasesList';
|
||||
import Text from '../../../RN-UI-LIB/src/components/Text';
|
||||
import { RootState } from '@store';
|
||||
import { initCrashlytics } from '@utils/firebaseUtils';
|
||||
import Layout from '../layout/Layout';
|
||||
@@ -25,13 +24,13 @@ import FullScreenLoaderWrapper from '@common/FullScreenLoaderWrapper';
|
||||
import DashboardIcon from '../../assets/icons/DashboardIcon';
|
||||
import DashBoardScreens from '../Dashboard/DashBoardScreens';
|
||||
import { isAgentDashboardVisible } from '@screens/Dashboard/utils';
|
||||
import { View, StyleSheet, TouchableOpacity } from 'react-native';
|
||||
import { StyleSheet} from 'react-native';
|
||||
import { COLORS } from '@rn-ui-lib/colors';
|
||||
import { GenericStyles } from '@rn-ui-lib/styles';
|
||||
import DailyCommitmentIcon from '@rn-ui-lib/icons/DailyCommitmentIcon';
|
||||
import AddCommitment from '../dailyCommitment/DailyCommitmentBottomSheet';
|
||||
import DailyCommitmentBottomSheet from '../dailyCommitment/DailyCommitmentBottomSheet';
|
||||
import { getVisibilityStatus } from '@screens/dailyCommitment/actions';
|
||||
import { logError } from '@components/utlis/errorUtils';
|
||||
import FloatingBannerCta from '@common/FloatingBannerCta';
|
||||
|
||||
const AllCasesMain = () => {
|
||||
const { pendingList, pinnedList, completedList, loading } = useAppSelector(
|
||||
@@ -49,15 +48,18 @@ const AllCasesMain = () => {
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
getVisibilityStatus()
|
||||
.then((response) => {
|
||||
setIsCommitmentSubmitted(response?.isCommitmentFilled);
|
||||
setIsCommitmentFormVisible(response?.isCommitmentBannerVisible);
|
||||
})
|
||||
.catch((err) => {
|
||||
logError(err);
|
||||
});
|
||||
}, [isCommitmentSubmitted,isCommitmentFormVisible]);
|
||||
if (isTeamLead) {
|
||||
return;
|
||||
}
|
||||
getVisibilityStatus()
|
||||
.then((response) => {
|
||||
setIsCommitmentSubmitted(response?.isCommitmentFilled);
|
||||
setIsCommitmentFormVisible(response?.isCommitmentBannerVisible);
|
||||
})
|
||||
.catch((err) => {
|
||||
logError(err);
|
||||
});
|
||||
}, [isCommitmentSubmitted, isCommitmentFormVisible]);
|
||||
|
||||
const shouldShowBanner = useMemo(() => {
|
||||
return !isTeamLead && !isCommitmentSubmitted && isCommitmentFormVisible;
|
||||
@@ -67,22 +69,8 @@ const AllCasesMain = () => {
|
||||
const openCommitmentScreen = () => {
|
||||
setOpenBottomSheet(true);
|
||||
};
|
||||
const CommitmentComponent = () => {
|
||||
return (
|
||||
<>
|
||||
<TouchableOpacity
|
||||
activeOpacity={0.8}
|
||||
style={[GenericStyles.centerAlignedRow, styles.container]}
|
||||
onPress={openCommitmentScreen}
|
||||
>
|
||||
<DailyCommitmentIcon />
|
||||
<Text bold dark style={[GenericStyles.ml8, GenericStyles.mr8, styles.updateText]}>
|
||||
Update your daily commitment
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
const HOME_SCREENS: ITabScreen[] = useMemo(() => {
|
||||
const bottomSheetScreens = [
|
||||
{
|
||||
@@ -90,7 +78,13 @@ const AllCasesMain = () => {
|
||||
component: () => (
|
||||
<>
|
||||
<CasesList casesList={[...pendingList, ...pinnedList, ...completedList]} allCasesView />
|
||||
{shouldShowBanner ? <CommitmentComponent /> : null}
|
||||
{shouldShowBanner ? <FloatingBannerCta
|
||||
title={"Update your daily commitment"}
|
||||
onPressHandler={openCommitmentScreen}
|
||||
containerStyle={styles.container}
|
||||
icon={<DailyCommitmentIcon />}
|
||||
textStyle={styles.titleText}
|
||||
/> : null}
|
||||
</>
|
||||
),
|
||||
icon: CasesIcon,
|
||||
@@ -102,7 +96,13 @@ const AllCasesMain = () => {
|
||||
component: () => (
|
||||
<>
|
||||
<CasesList casesList={pinnedList} isVisitPlan />
|
||||
{shouldShowBanner ? <CommitmentComponent /> : null}
|
||||
{shouldShowBanner ? <FloatingBannerCta
|
||||
title={"Update your daily commitment"}
|
||||
onPressHandler={openCommitmentScreen}
|
||||
containerStyle={styles.container}
|
||||
icon={<DailyCommitmentIcon />}
|
||||
textStyle={styles.titleText}
|
||||
/> : null}
|
||||
</>
|
||||
),
|
||||
icon: VisitPlanIcon,
|
||||
@@ -115,7 +115,13 @@ const AllCasesMain = () => {
|
||||
component: () => (
|
||||
<>
|
||||
<DashBoardScreens />
|
||||
{shouldShowBanner ? <CommitmentComponent /> : null}
|
||||
{shouldShowBanner ? <FloatingBannerCta
|
||||
title={"Update your daily commitment"}
|
||||
onPressHandler={openCommitmentScreen}
|
||||
containerStyle={styles.container}
|
||||
icon={<DailyCommitmentIcon />}
|
||||
textStyle={styles.titleText}
|
||||
/> : null}
|
||||
</>
|
||||
),
|
||||
icon: DashboardIcon,
|
||||
@@ -127,7 +133,13 @@ const AllCasesMain = () => {
|
||||
component: () => (
|
||||
<>
|
||||
<Profile />
|
||||
{shouldShowBanner ? <CommitmentComponent /> : null}
|
||||
{shouldShowBanner ? <FloatingBannerCta
|
||||
title={"Update your daily commitment"}
|
||||
onPressHandler={openCommitmentScreen}
|
||||
containerStyle={styles.container}
|
||||
icon={<DailyCommitmentIcon />}
|
||||
textStyle={styles.titleText}
|
||||
/> : null}
|
||||
</>
|
||||
),
|
||||
icon: ProfileIcon,
|
||||
@@ -168,7 +180,10 @@ const AllCasesMain = () => {
|
||||
onTabPress={(e) => onTabPressHandler(e)}
|
||||
/>
|
||||
<CasesActionButtons />
|
||||
<AddCommitment openBottomSheet={openBottomSheet} setOpenBottomSheet={setOpenBottomSheet} />
|
||||
{!isTeamLead && <DailyCommitmentBottomSheet
|
||||
openBottomSheet={openBottomSheet}
|
||||
setOpenBottomSheet={setOpenBottomSheet}
|
||||
/>}
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
@@ -177,8 +192,11 @@ const styles = StyleSheet.create({
|
||||
backgroundColor: COLORS.BACKGROUND.TEAL,
|
||||
height: 40,
|
||||
},
|
||||
updateText: {
|
||||
titleText: {
|
||||
color: COLORS.TEXT.TEAL,
|
||||
marginLeft: 2,
|
||||
marginRight: 8,
|
||||
fontFamily: 'Inter-Bold',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -7,10 +7,7 @@ import { GenericStyles } from '../../../RN-UI-LIB/src/styles';
|
||||
import { Controller, FieldErrors, useForm } from 'react-hook-form';
|
||||
import { isValidAmountEntered } from '../../components/utlis/commonFunctions';
|
||||
import { addCommitmentApi, getTodaysPtpAmount} from './actions';
|
||||
import Heading from '@rn-ui-lib/components/Heading';
|
||||
import DailyCommitmentIcon from '@rn-ui-lib/icons/DailyCommitmentIcon';
|
||||
import BottomSheetWrapper from '@common/BottomSheetWrapper';
|
||||
import CloseIcon from '@rn-ui-lib/icons/CloseIcon';
|
||||
import { COLORS } from '@rn-ui-lib/colors';
|
||||
import { EXAMPLE_VALUES } from './constants';
|
||||
import { useAppDispatch} from '@hooks';
|
||||
@@ -20,7 +17,7 @@ import { IAddCommitment, IAddCommitmentProps } from '@interfaces/commitmentTrack
|
||||
import HeaderComponent from './headerComponent';
|
||||
import { logError } from '@components/utlis/errorUtils';
|
||||
|
||||
const AddCommitment: React.FC<IAddCommitmentProps> = ({ openBottomSheet, setOpenBottomSheet }) => {
|
||||
const DailyCommitmentBottomSheet: React.FC<IAddCommitmentProps> = ({ openBottomSheet, setOpenBottomSheet }) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const {
|
||||
control,
|
||||
@@ -32,7 +29,7 @@ const AddCommitment: React.FC<IAddCommitmentProps> = ({ openBottomSheet, setOpen
|
||||
mode: 'onChange',
|
||||
});
|
||||
const [submitErrors, setSubmitErrors] = useState<FieldErrors<IAddCommitment>>({});
|
||||
const [todaysPtpAmount, setTodaysPtpAmount] = useState(1000);
|
||||
const [todaysPtpAmount, setTodaysPtpAmount] = useState(0);
|
||||
useEffect(() => {
|
||||
getTodaysPtpAmount()
|
||||
.then((response) => {
|
||||
@@ -218,4 +215,4 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
});
|
||||
|
||||
export default AddCommitment;
|
||||
export default DailyCommitmentBottomSheet;
|
||||
|
||||
@@ -11,18 +11,17 @@ import { addClickstreamEvent } from '@services/clickstreamEventService';
|
||||
import { CLICKSTREAM_EVENT_NAMES } from '@common/Constants';
|
||||
import { AppDispatch } from '@store';
|
||||
import { IAddCommitment } from '@interfaces/commitmentTracker.types';
|
||||
import { getSyncTime } from '@hooks/capturingApi';
|
||||
import { logError } from '@components/utlis/errorUtils';
|
||||
|
||||
export const getTodaysPtpAmount = async () => {
|
||||
try {
|
||||
const url = getApiUrl(ApiKeys.GET_PTP_AMOUNT);
|
||||
const response = await axiosInstance.get(url);
|
||||
return response?.data;
|
||||
} catch (err) {
|
||||
logError(err as Error, 'Error fetching today\'s PTP amount:');
|
||||
return COMMITMENT_TYPE.EMPTY_PTP_AMOUNT;
|
||||
}
|
||||
try {
|
||||
const url = getApiUrl(ApiKeys.GET_PTP_AMOUNT);
|
||||
const response = await axiosInstance.get(url);
|
||||
return response?.data;
|
||||
} catch (err) {
|
||||
logError(err as Error, 'Error fetching today\'s PTP amount:');
|
||||
return COMMITMENT_TYPE.EMPTY_PTP_AMOUNT;
|
||||
}
|
||||
};
|
||||
|
||||
export const getVisibilityStatus = async () => {
|
||||
@@ -39,7 +38,6 @@ export const addCommitmentApi =
|
||||
(data: IAddCommitment, afterApiCallback?: GenericFunctionArgs) => async (dispatch: AppDispatch) => {
|
||||
const { cashCommitted, visitsCommitted } = data;
|
||||
const url = getApiUrl(ApiKeys.DAILY_COMMITMENT);
|
||||
const timestamp = await getSyncTime();
|
||||
const payload = data;
|
||||
axiosInstance
|
||||
.post(url, payload)
|
||||
|
||||
Reference in New Issue
Block a user