diff --git a/backend/gestion/db/db_init.go b/backend/gestion/db/db_init.go index ba7661fe..e70a1c55 100644 --- a/backend/gestion/db/db_init.go +++ b/backend/gestion/db/db_init.go @@ -246,6 +246,11 @@ func InitDB() *Database { log.Fatalf("❌ Erreur migration products.coming_soon: %v", err) } + // Migration: prix actif/inactif sur les prix de produits + if _, err = database.Exec(`ALTER TABLE product_prices ADD COLUMN IF NOT EXISTS active_price BOOLEAN NOT NULL DEFAULT TRUE`); err != nil { + log.Fatalf("❌ Erreur migration product_prices.active_price: %v", err) + } + // Migration: table contacts (SAV Telegram) if _, err = database.Exec(`CREATE TABLE IF NOT EXISTS contacts ( id SERIAL PRIMARY KEY, diff --git a/frontend-admin/src/screens/admin/ProductsScreen.tsx b/frontend-admin/src/screens/admin/ProductsScreen.tsx index 533bb8ec..5104cfdd 100644 --- a/frontend-admin/src/screens/admin/ProductsScreen.tsx +++ b/frontend-admin/src/screens/admin/ProductsScreen.tsx @@ -851,7 +851,7 @@ export default function ProductsScreen() { key={i} style={[ styles.info, - !p.active_price && { + p.active_price === false && { textDecorationLine: "line-through", color: colors.textMuted, opacity: 0.5, diff --git a/frontend-prep/src/api/api.ts b/frontend-prep/src/api/api.ts index 9cdc1a8c..e075adf1 100644 --- a/frontend-prep/src/api/api.ts +++ b/frontend-prep/src/api/api.ts @@ -1859,6 +1859,7 @@ export interface PublicSettings { nowpayments_currencies: string[]; shop_name: string; two_fa_enabled: boolean; + contact_telegram: string; } export const getPublicSettings = async (): Promise => { @@ -1875,6 +1876,7 @@ export const getPublicSettings = async (): Promise => { nowpayments_currencies: [], shop_name: "Milieu-Nantais", two_fa_enabled: false, + contact_telegram: "", }; try { const response = await fetch(`${API_URL}/app-settings`); @@ -1898,6 +1900,7 @@ export const getPublicSettings = async (): Promise => { : [], shop_name: data.shop_name || "Milieu-Nantais", two_fa_enabled: data.two_fa_enabled ?? false, + contact_telegram: data.contact_telegram || "", }; } catch { return defaults; diff --git a/frontend-prep/src/pages/User/Checkout.tsx b/frontend-prep/src/pages/User/Checkout.tsx index dada2372..dea2895b 100644 --- a/frontend-prep/src/pages/User/Checkout.tsx +++ b/frontend-prep/src/pages/User/Checkout.tsx @@ -1,7 +1,7 @@ import { useState, useEffect, useRef } from 'react'; import { useNavigate } from 'react-router-dom'; import { useCart } from '../../context/useCart'; -import { createCheckout, clearCart, extractUsernameFromToken, isUserAuthenticated, getReferralBalance, getPublicSettings, getMyProfile, getCryptoPaymentStatus, getProductById, getMediaUrl } from '../../api/api'; +import { createCheckout, clearCart, extractUsernameFromToken, isUserAuthenticated, getReferralBalance, getPublicSettings, getMyProfile, getCryptoPaymentStatus, getProductById, getMediaUrl, getTelegramStatus } from '../../api/api'; import type { CheckoutData, CryptoPaymentStatus } from '../../api/api'; import type { Product } from '../../api/api'; import Navbar from '../../components/Navbar'; @@ -80,6 +80,9 @@ function Checkout() { const [referralEnabled, setReferralEnabled] = useState(false); const [useReferral, setUseReferral] = useState(false); + // Telegram + const [telegramLinked, setTelegramLinked] = useState(false); + // Crypto const [cryptoEnabled, setCryptoEnabled] = useState(false); const [cryptoOnly, setCryptoOnly] = useState(false); @@ -129,6 +132,10 @@ function Checkout() { if (res.client.prenom) setFirstName(res.client.prenom); } }); + + getTelegramStatus().then((res) => { + if (res.linked) setTelegramLinked(true); + }); }, []); // Charger settings publics (parrainage + crypto) @@ -578,16 +585,18 @@ function Checkout() { )} -
- -
- Compte Telegram requis -

- Votre commande ne pourra être validée que si votre compte Telegram est lié. - Rendez-vous dans votre profil pour le lier avant de confirmer. -

+ {!telegramLinked && ( +
+ +
+ Compte Telegram requis +

+ Votre commande ne pourra être validée que si votre compte Telegram est lié. + Rendez-vous dans votre profil pour le lier avant de confirmer. +

+
-
+ )}
); diff --git a/mobile/src/api/api.ts b/mobile/src/api/api.ts index a615ba0a..17f36d0a 100644 --- a/mobile/src/api/api.ts +++ b/mobile/src/api/api.ts @@ -777,6 +777,7 @@ export interface PublicSettings { nowpayments_currencies: string[]; telegram_notifications_enabled: boolean; two_fa_enabled: boolean; + contact_telegram: string; } export const getPublicSettings = async (): Promise => { @@ -792,6 +793,7 @@ export const getPublicSettings = async (): Promise => { nowpayments_currencies: [], telegram_notifications_enabled: false, two_fa_enabled: false, + contact_telegram: "", }; try { const { data } = await apiClient.get(`${V1}/app-settings`); @@ -813,6 +815,7 @@ export const getPublicSettings = async (): Promise => { telegram_notifications_enabled: data.telegram_notifications_enabled ?? false, two_fa_enabled: data.two_fa_enabled ?? false, + contact_telegram: data.contact_telegram || "", }; } catch { return defaults; diff --git a/mobile/src/screens/client/CheckoutScreen.tsx b/mobile/src/screens/client/CheckoutScreen.tsx index 1345b831..bc958276 100644 --- a/mobile/src/screens/client/CheckoutScreen.tsx +++ b/mobile/src/screens/client/CheckoutScreen.tsx @@ -21,6 +21,7 @@ import { getReferralBalance, getPublicSettings, getCryptoPaymentStatus, + getTelegramStatus, } from "../../api/api"; import type { CryptoPaymentStatus } from "../../api/api"; import type { ClientStackParamList } from "../../navigation/types"; @@ -57,6 +58,7 @@ export default function CheckoutScreen() { // Notif telegram const [telegramNotificationEnabled, setTelegramNotificationEnabled] = useState(false); + const [telegramLinked, setTelegramLinked] = useState(false); // Crypto const [cryptoEnabled, setCryptoEnabled] = useState(false); @@ -105,6 +107,10 @@ export default function CheckoutScreen() { if (savedPhone) setTelephone(savedPhone); }); + getTelegramStatus().then((res) => { + if (res.linked) setTelegramLinked(true); + }); + return () => { if (pollRef.current) clearInterval(pollRef.current); }; @@ -1027,7 +1033,7 @@ export default function CheckoutScreen() { )} {/* Note Telegram */} - {telegramNotificationEnabled && ( + {telegramNotificationEnabled && !telegramLinked && ( (0); + const [contactTelegram, setContactTelegram] = useState(""); useEffect(() => { getReferralBalance().then((res) => { if (res.success) setBalance(res.balance); }); + getPublicSettings().then((settings) => { + if (settings.contact_telegram) { + setContactTelegram(settings.contact_telegram); + } + }); }, []); const steps = [ { icon: "chatbubble-ellipses-outline" as const, title: "1. Contacte-nous sur Telegram", - desc: "Envoie un message à @milieu_nantais en indiquant ton username et le username de la personne que tu as parrainée.", + desc: contactTelegram + ? `Envoie un message à @${contactTelegram} en indiquant ton username et le username de la personne que tu as parrainée.` + : "Envoie-nous un message sur Telegram en indiquant ton username et le username de la personne que tu as parrainée.", }, { icon: "checkmark-circle-outline" as const, @@ -152,6 +161,12 @@ export default function ParrainageScreen() { [colors], ); + const handleTelegramPress = () => { + if (contactTelegram) { + Linking.openURL(`https://t.me/${contactTelegram}`); + } + }; + return ( {/* Solde actuel */} @@ -190,18 +205,14 @@ export default function ParrainageScreen() { {/* Bouton Telegram */} - - - Linking.openURL("https://t.me/milieu_nantais")} - > - Contacter @milieu_nantais - - + {contactTelegram ? ( + + + + Contacter @{contactTelegram} + + + ) : null} ); }