Skip to content

Commit

Permalink
fix: test location
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Jun 27, 2024
1 parent 4507113 commit 27c61fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
14 changes: 12 additions & 2 deletions api/src/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require("express");
const { catchErrors } = require("../middlewares/errors");
const router = express.Router();
const prisma = require("../prisma");
const geoip = require("geoip-lite");

router.put(
"/",
Expand Down Expand Up @@ -36,8 +37,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)
var 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
20 changes: 19 additions & 1 deletion 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 Down Expand Up @@ -38,7 +56,7 @@ const HealthIndex = ({ navigation }) => {
navigation.navigate('CONTACT');
}}>
<AppointmentHeart size={80} className="" />
<Text className="text-center">Prendre un RDV avec Doctolib</Text>
{isWellLocated && <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">
Expand Down

0 comments on commit 27c61fc

Please sign in to comment.