Skip to content

Commit

Permalink
Merge branch 'develop' into 234-NewTutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
sudjoao authored Jul 8, 2023
2 parents b442fe5 + 4e3d712 commit 4b253cb
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { BadgeContext } from '../../../../store/contexts/badgeContext';
import { LoadingContext } from '../../../../store/contexts/loadingContext';
import { UserContext } from '../../../../store/contexts/userContext';
import { Dialog } from '../../../molecules/Dialog';
import { translatedActivities } from '../../../../utils/translatedActivities';

export const UserActivity = ({
activityType,
Expand All @@ -31,6 +32,7 @@ export const UserActivity = ({
useState(false);

const activityIcon = getActivityIcon(activityType);
const activity = translatedActivities[activityType].translation;
const indicatorColor = isRiskGroup
? { icon: colors.danger[300], text: 'text-danger-300' }
: { icon: colors.primary[300], text: 'text-primary-300' };
Expand Down Expand Up @@ -65,15 +67,11 @@ export const UserActivity = ({
if (!response.error) {
alertSuccess(messages[activityType].success);
if (isRequest) {
const badgeResponse = await increaseUserBadge(
user._id,
'offer',
navigation,
);
if (!badgeResponse.recentUpdated) closeModal();
} else closeModal();
await increaseUserBadge(user._id, 'offer', navigation);
}
}
if (isRequest) setIsLoading(false);
closeModal();
};

return (
Expand All @@ -97,7 +95,7 @@ export const UserActivity = ({
<Text
className={`${indicatorColor.text} font-ms-semibold text-2xl ml-2`}
>
Pedido
{activity}
</Text>
</View>
<View className="justify-center">
Expand Down
42 changes: 33 additions & 9 deletions app/src/components/modals/BadgeEarnModal/index.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { BaseModal } from '../BaseModal';
import { CircleBadge } from '../../atoms/CircleBadge';
import { Text, View } from 'react-native';
import Button from '../../UI/button';

export const BadgeEarnModal = ({
badge,
navigation,
badges,
setIsVisible,
onviewBadge,
...modalProps
}) => {
const [index, setIndex] = useState(0);

useEffect(() => {
onviewBadge(badges[index]._id);
}, [index]);

const badge = badges[index].template;

const badgeMessages = {
offer: {
1: 'você está fazendo a diferença, e por conta disso conquistou a conquista',
Expand All @@ -21,23 +29,39 @@ export const BadgeEarnModal = ({
2: 'você realmente é um guerreiro, e por conta disso conquistou a conquista',
3: 'você realmente é um guerreiro, e por conta disso conquistou a conquista',
},
help: {
1: 'você está fazendo a diferença, e por conta disso conquistou a conquista',
2: 'você continua tentando ajudar ao máximo, e por conta disso agora recebeu a conquista',
3: 'você continua tentando ajudar ao máximo, e por conta disso agora recebeu a conquista',
},
};

const handleClose = () => {
setIsVisible(false);
};

const handleContinue = () => {
if (index < badges.length - 1) {
setIndex(index + 1);
return;
}
setIsVisible(false);
if (navigation)
navigation.reset({
index: 0,
routes: [{ name: 'home' }],
});
};

const message = `Parabéns, ${badgeMessages[badge.category][badge.rank]} `;
const title = badge.rank == 1 ? 'Nova Conquista' : 'Novo Nível';

return (
badge && (
<BaseModal onCloseModal={handleContinue} {...modalProps}>
<BaseModal onCloseModal={handleClose} {...modalProps}>
<Text
className={
'absolute top-4 right-2 font-ms-medium text-black'
}
>
{' '}
{index + 1}/{badges.length}{' '}
</Text>
<View className="items-center">
<CircleBadge
badgeIcon={badge?.iconName}
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/molecules/ActivityMarker/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const ActivityMarker = ({
} overflow-hidden `}
numberOfLines={1}
>
{title || `${selectedType.text} ${index}`}
{title || `${selectedType.text} ${index || ''}`}
</Text>
</View>
</Marker>
Expand Down
16 changes: 3 additions & 13 deletions app/src/components/organisms/ActivityCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ActivityBottomSheetContext } from '../../../store/contexts/activityBott
import navigateToMyActivity from '../../../utils/navigateToMyActivity';
import { ActivitiesContext } from '../../../store/contexts/activitiesContext';
import colors from '../../../../colors';
import { translatedActivities } from '../../../utils/translatedActivities';

export const ActivityCard = ({
variant,
Expand All @@ -34,18 +35,7 @@ export const ActivityCard = ({
const isNewActivity = isRecentDate(creationDate);
const isTheSameUser = user._id == ownerId;

const activitiesVariants = {
help: {
translation: 'Pedido',
},
offer: {
translation: 'Oferta',
},
campaign: {
translation: 'Campanha',
},
};
const selectedVariant = activitiesVariants[variant];
const selectedVariant = translatedActivities[variant].translation;
const icon = getActivityIcon(variant);
const color = {
font: isRiskGroup ? 'text-danger' : 'text-primary-400',
Expand Down Expand Up @@ -87,7 +77,7 @@ export const ActivityCard = ({
type={icon.type}
/>
<Text className={`${color.font} font-ms-bold ml-1 text-base`}>
{`${selectedVariant.translation} ${count}`}
{`${selectedVariant} ${count || ''}`}
</Text>
{isNewActivity && <SeedlingIcon className="ml-auto" />}
</View>
Expand Down
2 changes: 1 addition & 1 deletion app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function Root() {
</SocialNetworkProfileContextProvider>
</UserContextProvider>
</LoadingContextProvider>
</DeviceInfoProvider >
</DeviceInfoProvider>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useFocusEffect, useNavigationState } from '@react-navigation/native';
import { Dialog } from '../../../../components/molecules/Dialog';
import { FeedbackContext } from '../../../../store/contexts/feedbackContext';
import { FeedbackModal } from './FeedbackModal';
import { BadgeContext } from '../../../../store/contexts/badgeContext';

export default function HelpDescription({
route,
Expand All @@ -29,6 +30,8 @@ export default function HelpDescription({
const { user } = useContext(UserContext);
const { setIsLoading } = useContext(LoadingContext);
const { createFeedback } = useContext(FeedbackContext);
const { increaseUserBadge } = useContext(BadgeContext);

const [updateData, setUpdateData] = useState(false);
const [showPossibleHelpers, setShowPossibleHelpers] = useState(false);
const [helper, setHelper] = useState(null);
Expand Down Expand Up @@ -146,7 +149,10 @@ export default function HelpDescription({
setIsLoading(true);
const response = await finishHelpByOwner(helpId);
setIsLoading(false);
if (response) setShowSuccesDialog(true);
if (response) {
setShowSuccesDialog(true);
increaseUserBadge(help?.helperId, 'help');
}
};

const handleShowFeedbackBottomSheet = () => {
Expand Down
9 changes: 2 additions & 7 deletions app/src/pages/AuthPages/Location/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,10 @@ export default function Location({ route }) {
setConfirmationModalVisible(false);

if (!response.error) {
let badgeResponse;
if (requestType == 'HelpOffer')
badgeResponse = await increaseUserBadge(
user._id,
'offer',
navigation,
);
await increaseUserBadge(user._id, 'offer', navigation);
alertSuccess(texts[requestType].successText);
if (!badgeResponse?.recentUpdated) navigation.navigate('home');
navigation.navigate('home');
}
setIsLoading(false);
}
Expand Down
21 changes: 15 additions & 6 deletions app/src/pages/Main/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,29 @@ import { ActivitiesContext } from '../../store/contexts/activitiesContext';
import { AnimatedMap } from '../../components/organisms/AnimatedMap';

export default function Main({ navigation }) {
const { user, isEntity, env } = useContext(UserContext);
const { increaseUserBadge } = useContext(BadgeContext);
const [region, setRegion] = useState(null);

const { user, isEntity } = useContext(UserContext);
const { getBadgeList } = useContext(BadgeContext);
const [focusedCardLocation, setFocusedCardLocation] = useState({});
const [visibleItemData, setVisibleItemData] = useState(null);
const { showActivityModal, activityInfo, setShowActivityModal } =
useContext(ActivityBottomSheetContext);
const { activitiesList } = useContext(ActivitiesContext);
const limitedActivitiesList = activitiesList.slice(0, 15);

const handleGetBadges = async () => {
await getBadgeList(user._id);
};


useEffect(() => {
if (!env.production && !isEntity) {
increaseUserBadge(user._id, 'tester');
}
}, []);
setRegion(null);
}, [region]);

useEffect(() => {
if (!showActivityModal) handleGetBadges();
}, [showActivityModal]);

const renderHelpButtons = () => {
return (
Expand Down
12 changes: 10 additions & 2 deletions app/src/pages/TimeLine/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@ export const Timeline = () => {

return (
<View className="bg-new_background flex-1 px-4 py-6">
{hasTimelineItems && <DefaultTimeline data={parsedTimelineItems} useIcon />}
{!hasTimelineItems && <NotFound size='large' title='Possivelmente você é dev' body='Se você está vendo isso é porque criou a conta antes dessa feat e não atualizou seu banco de dados'/>}
{hasTimelineItems && (
<DefaultTimeline data={parsedTimelineItems} useIcon />
)}
{!hasTimelineItems && (
<NotFound
size="large"
title="Possivelmente você é dev"
body="Se você está vendo isso é porque criou a conta antes dessa feat e não atualizou seu banco de dados"
/>
)}
</View>
);
};
9 changes: 9 additions & 0 deletions app/src/services/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class BadgeService {
const response = await api.post('/badges/', { userId, category });
return response.data;
}
async getBadgeList(userId) {
const response = await api.get(`/badges/list?userId=${userId}`);
return response.data;
}

async viewBadge(badgeId) {
const response = await api.put(`/badges/${badgeId}`);
return response.data;
}
}

const badgeService = new BadgeService();
Expand Down
55 changes: 41 additions & 14 deletions app/src/store/contexts/badgeContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,46 @@ export const BadgeContext = createContext();

export default function BadgeContextProvider({ children }) {
const [showModal, setShowModal] = useState(false);
const [badge, setBadge] = useState();
const [navigation, setNavigation] = useState();
const [badges, setBadges] = useState();

const showUpdatedBadges = (updatedBadges) => {
if (updatedBadges.length > 0) {
setBadges(updatedBadges);
setShowModal(true);
}
};
async function getUserBadges(userId) {
return await callService(badgeService, 'getUserBadges', [userId]);
}

async function getBadgeList(userId) {
const badgeList = await callService(badgeService, 'getBadgeList', [
userId,
]);
const updatedBadges = badgeList.filter(
(badge) =>
!badge.visualizedAt || badge.visualizedAt < badge.updatedAt,
);
showUpdatedBadges(updatedBadges);
}

async function getBadgesHistory(userId) {
return await callService(badgeService, 'getBadgesHistory', [userId]);
}
async function increaseUserBadge(userId, category, navigationObject) {

async function increaseUserBadge(userId, category) {
const response = await callService(badgeService, 'increaseUserBadge', [
userId,
category,
]);
if (!response.error) {
setNavigation(navigationObject);
setBadge({
...response.badge,
recentUpdated: response.recentUpdated,
});
setShowModal(response.recentUpdated);
}
return response;
}

async function viewBadge(userId, badgeId) {
const response = await callService(badgeService, 'viewBadge', [
userId,
badgeId,
]);
return response;
}

Expand All @@ -36,18 +54,27 @@ export default function BadgeContextProvider({ children }) {
getUserBadges,
getBadgesHistory,
increaseUserBadge,
getBadgeList,
showUpdatedBadges,
viewBadge,
};
}, [getUserBadges, getBadgesHistory, increaseUserBadge]);
}, [
getUserBadges,
getBadgesHistory,
increaseUserBadge,
getBadgeList,
showUpdatedBadges,
]);

return (
<BadgeContext.Provider value={contextValue}>
{children}
{showModal && (
<BadgeEarnModal
badge={badge.template}
badges={badges}
setIsVisible={setShowModal}
isVisible={showModal}
navigation={navigation}
onviewBadge={viewBadge}
/>
)}
</BadgeContext.Provider>
Expand Down
11 changes: 11 additions & 0 deletions app/src/utils/translatedActivities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const translatedActivities = {
help: {
translation: 'Pedido',
},
offer: {
translation: 'Oferta',
},
campaign: {
translation: 'Campanha',
},
};

0 comments on commit 4b253cb

Please sign in to comment.