Skip to content

Commit

Permalink
refactor: ♻️ use env variable for contact numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
nutfdt committed Oct 7, 2024
1 parent 9471ae1 commit 0713973
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 14 deletions.
4 changes: 4 additions & 0 deletions backend/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,7 @@ def get_base_logs(user_agent, user_id: str) -> dict:
)

OAUTH2_SCHEME = OpenIdConnect(openIdConnectUrl=os.environ["OIDC_CONFIG_URL"])

# Phone numbers
PHONE_NUMBER = os.environ.get("IRCGN_PHONE")
CELLPHONE_NUMBER = os.environ.get("IRCGN_CELLPHONE")
9 changes: 8 additions & 1 deletion backend/src/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from fastapi.responses import PlainTextResponse
from user_agents import parse

from .config import APP_VERSION, S3_PREFIX, TYPOLOGIES_MEASURED, get_base_logs
from .config import APP_VERSION, S3_PREFIX, TYPOLOGIES_MEASURED, get_base_logs, PHONE_NUMBER, CELLPHONE_NUMBER
from .models import EmailData
from .utils import get_current_user, send_mail, upload_image

router = APIRouter(prefix="/api")
Expand All @@ -36,6 +37,12 @@ def home():
def version():
return APP_VERSION

@router.get("/contact-details")
async def phone_number(
current_user: Annotated[dict, Depends(get_current_user)],
):
return PHONE_NUMBER, CELLPHONE_NUMBER


@router.post("/upload")
async def imageupload(
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/api/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IDENTIFICATION_FEEDBACK_ROUTE,
TUTORIAL_FEEDBACK_ROUTE,
UPLOAD_PHOTO_FOR_DETECTION_ROUTE,
GET_IRCGN_NUMBERS_ROUTE,
} from "./api-routes";

export const uploadPhotoForDetection = async (file: File) => {
Expand Down Expand Up @@ -46,3 +47,12 @@ export const sendExpertiseForm = async (data: any, accessToken: string) => {
},
});
};

export const getContactDetails = async (accessToken: string) => {
const { data } = await axios.get(GET_IRCGN_NUMBERS_ROUTE, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
return data;
};
1 change: 1 addition & 0 deletions frontend/src/api/api-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export const TUTORIAL_FEEDBACK_ROUTE = "/tutorial-feedback";
export const IDENTIFICATION_FEEDBACK_ROUTE = "/identification-feedback";
export const IDENTIFICATION_DUMMY_ROUTE = "/identification-dummy";
export const ASK_FOR_OPINION_ROUTE = "/expert-contact";
export const GET_IRCGN_NUMBERS_ROUTE = "/contact-details";
61 changes: 48 additions & 13 deletions frontend/src/views/GuideContactExpert/ExpertSituation.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
<script lang="ts" setup>
import { ref } from "vue";
import { DsfrButton } from "@gouvminint/vue-dsfr";
import { useRouter } from "vue-router";
import { DateTime } from "luxon";
import { mgr } from "@/utils/authentication";
import { getContactDetails } from "@/api/api-client";
const user = ref(Object || null);
mgr.getUser().then((data) => (user.value = data));
const getAccessToken: Ref<string> = ref("");
const authIDP: Ref<string> = ref("");
// Récupération des données de l'utilisateur
const getUserData = async () => {
try {
const user = await mgr.getUser();
getAccessToken.value = user?.access_token;
authIDP.value = user?.profile.auth_idp;
} catch (error) {
console.error(
"Erreur pendant la récupération des données de l'utilisateur :",
error,
);
}
};
const getIRCGNDetails = async () => {
try {
const response = await getContactDetails(getAccessToken.value);
IRCGN.fixe = response[0];
IRCGN.phone = response[1];
console.log("Détails de contact récupérés avec succès :", response);
} catch (error) {
console.error(
"Erreur lors de la récupération des détails de contact :",
error,
);
}
};
onMounted(async () => {
await getUserData();
if (authIDP.value === "proxyma") {
await getIRCGNDetails();
}
});
const priority = ref("");
const IRCGN = {
email: "[email protected]",
fixe: "01 78 47 31 46",
phone: "06 07 98 40 09",
fixe: "",
phone: "",
};
const showIRCGNModal = ref(false);
Expand All @@ -37,15 +72,15 @@ const currentPhone = computed(() => {
<div class="text-center mt-5 p-3">
<h1>
<VIcon name="ri-arrow-right-line" scale="1.7" />
<span v-if="user.profile.idp === 'proxyma'">
Contacter un expert de l'IRCGN
</span>
<span v-else>Contacter un expert en arme</span>
<span v-if="authIDP === 'proxyma'"
>Contacter un expert de l'IRCGN</span
>
<span v-if="authIDP === 'cheops'">Contacter un expert en arme</span>
</h1>
<div v-if="user.profile.idp === 'proxyma'">
<div v-if="authIDP === 'proxyma'">
<p>Sélectionnez votre situation actuelle :</p>
</div>
<div v-else>
<div v-if="authIDP === 'cheops'">
<DsfrAlert type="error" title="Avertissement">
Basegun ne fournit pas de
<span class="font-bold"
Expand All @@ -69,7 +104,7 @@ const currentPhone = computed(() => {
</div>
</div>
</div>
<div v-if="user.profile.idp === 'proxyma'">
<div v-if="authIDP === 'proxyma'">
<div class="fr-grid-row">
<div class="fr-col-12 fr-col-lg-6 mx-auto">
<div class="fr-grid-row">
Expand Down Expand Up @@ -130,7 +165,7 @@ const currentPhone = computed(() => {
</DsfrModal>
</Teleport>
</div>
<div v-if="user.profile.idp === 'proxyma'" class="fr-grid-row">
<div v-if="authIDP === 'proxyma'" class="fr-grid-row">
<div class="fr-col text-center">
<div class="bg-purple p-8 fr-my-8w">
<p>Exemple de cas d'urgences :</p>
Expand Down

0 comments on commit 0713973

Please sign in to comment.