Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test location #592

Merged
merged 5 commits into from
Jun 27, 2024
Merged
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
16 changes: 14 additions & 2 deletions api/src/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const express = require("express");
const { catchErrors } = require("../middlewares/errors");
const router = express.Router();
const prisma = require("../prisma");
const geoip = require("geoip-lite");
const { capture } = require("../third-parties/sentry");
const fetch = require("node-fetch");

router.put(
"/",
Expand Down Expand Up @@ -36,8 +39,17 @@ router.put(

router.get(
"/location",
catchErrors(async (_req, res) => {
const isWellLocated = false;
catchErrors(async (req, res) => {
const { matomoId } = req.query || {};
let isWellLocated = false;
if (!matomoId) return res.status(400).json({ ok: false, error: "no matomo id" });
const ip = req.connection.remoteAddress; // private ip when dev mode, should be public ip in prod (https://stackoverflow.com/a/58441273/5225096)
const geo = geoip.lookup(ip);
const response = await fetch(`http://ip-api.com/json/${ip}`);
const data = await response.json();
console.log({ data });
capture("test location", { extra: { geo, data } });
if (geo?.region === "IDF") isWellLocated = true;
return res.status(200).send({ ok: true, isWellLocated });
})
);
Expand Down
2 changes: 1 addition & 1 deletion app/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled true
versionCode 284
versionCode 285
versionName "1.25.4"
}

Expand Down
2 changes: 1 addition & 1 deletion app/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "oz_ensemble",
"displayName": "Oz Ensemble",
"version": {
"buildNumber": 284,
"buildNumber": 285,
"buildName": "1.25.4"

}
Expand Down
4 changes: 2 additions & 2 deletions app/ios/oz_ensemble.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@
CODE_SIGN_ENTITLEMENTS = oz_ensemble/oz_ensemble.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 284;
CURRENT_PROJECT_VERSION = 285;
DEVELOPMENT_TEAM = 76GBKHVK25;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = oz_ensemble/Info.plist;
Expand Down Expand Up @@ -560,7 +560,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 284;
CURRENT_PROJECT_VERSION = 285;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 76GBKHVK25;
INFOPLIST_FILE = oz_ensemble/Info.plist;
Expand Down
14 changes: 14 additions & 0 deletions app/src/reference/mocks/FakeData.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ const FakeData = () => {
return (
<WrapperContainer title="Charger des fausses données">
<Container>
<MenuItem
caption="Apparition du bouton pour prendre RDV"
noAlert
onPress={() => {
API.get({
path: '/user/location',
query: {
matomoId: storage.getString('@UserIdv2'),
},
}).then((response) => {
if (response.ok) Alert.alert('Suis-je bien localisé ?', response.isWellLocated ? 'Oui' : 'Non');
});
}}
/>
<H1Wrapper delete>Effacer des données</H1Wrapper>
<MenuItem caption="Mon NPS" onPress={() => storage.delete('@NPSDone')} />
<MenuItem caption="Ma consommation d'alcool" onPress={() => deleteStorageValues(fakeOnboardingQuizz.good)} />
Expand Down
40 changes: 30 additions & 10 deletions app/src/scenes/Health/HealthIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,26 @@ import NewsPaper from '../../components/illustrations/NewsPaper';
import { View, TouchableOpacity, Text } from 'react-native';
import WrapperContainer from '../../components/WrapperContainer';
import HealthPlan from '../../components/illustrations/HealthPlan';
import React, { useEffect, useState } from 'react';
import { storage } from '../../services/storage';
import API from '../../services/api';
import { useIsFocused } from '@react-navigation/native';

const HealthIndex = ({ navigation }) => {
const [isWellLocated, setIsWellLocated] = useState(false);
const isFocused = useIsFocused();
useEffect(() => {
if (isFocused) {
API.get({
path: '/user/location',
query: {
matomoId: storage.getString('@UserIdv2'),
},
}).then((response) => {
if (response.ok) setIsWellLocated(response.isWellLocated);
});
}
}, [isFocused]);
return (
<WrapperContainer title="Santé">
<View className="h-56 w-full flex flex-row gap-4 justify-between mb-4 pt-2 pr-4 ">
Expand All @@ -31,16 +49,18 @@ const HealthIndex = ({ navigation }) => {
</View>
</View>
<View className="h-56 w-full flex flex-row gap-4 justify-between mb-4 pt-2 pr-4 ">
<View className="border border-[#4030A5] bg-white w-1/2 rounded-md shadow-md">
<TouchableOpacity
className="flex items-center gap-6 p-8"
onPress={() => {
navigation.navigate('CONTACT');
}}>
<AppointmentHeart size={80} className="" />
<Text className="text-center">Prendre un RDV avec Doctolib</Text>
</TouchableOpacity>
</View>
{isWellLocated && (
<View className="border border-[#4030A5] bg-white w-1/2 rounded-md shadow-md">
<TouchableOpacity
className="flex items-center gap-6 p-8"
onPress={() => {
navigation.navigate('CONTACT');
}}>
<AppointmentHeart size={80} className="" />
<Text className="text-center">Prendre un RDV avec Doctolib</Text>
</TouchableOpacity>
</View>
)}
<View className="border border-[#4030A5] bg-white w-1/2 rounded-md shadow-md">
<TouchableOpacity
className="flex items-center gap-6 p-8"
Expand Down
Loading