feat(abonnement): message 'changement à la prochaine échéance' sous les cards (#109)
Ajoute la fonction _change_hint et étend le callback _select_plan pour afficher un hint "changement à la prochaine échéance" quand l'utilisateur sélectionne un plan différent du plan courant. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -85,18 +85,39 @@ def _selection_state(selected):
|
||||
)
|
||||
|
||||
|
||||
def _change_hint(selected: str, sub_info: dict | None) -> tuple[str, str]:
|
||||
sub_info = sub_info or {}
|
||||
current = sub_info.get("current_plan")
|
||||
if (
|
||||
not current
|
||||
or sub_info.get("status") not in ("active", "trial")
|
||||
or selected == current
|
||||
):
|
||||
return "d-none", ""
|
||||
echeance = sub_info.get("echeance")
|
||||
return (
|
||||
"text-muted mt-2",
|
||||
f"Le changement d'abonnement sera appliqué à la prochaine échéance : {echeance}.",
|
||||
)
|
||||
|
||||
|
||||
@callback(
|
||||
Output("inf-plan-hidden", "value"),
|
||||
Output("plan-card-simple", "className"),
|
||||
Output("plan-card-soutien", "className"),
|
||||
Output("inf-plan-invite", "className"),
|
||||
Output("inf-change-hint", "className"),
|
||||
Output("inf-change-hint", "children"),
|
||||
Input("plan-card-simple", "n_clicks"),
|
||||
Input("plan-card-soutien", "n_clicks"),
|
||||
State("inf-sub-info", "data"),
|
||||
prevent_initial_call=True,
|
||||
)
|
||||
def _select_plan(_n_simple, _n_soutien):
|
||||
def _select_plan(_n_simple, _n_soutien, sub_info):
|
||||
selected = "simple" if ctx.triggered_id == "plan-card-simple" else "soutien"
|
||||
return _selection_state(selected)
|
||||
value, cls_simple, cls_soutien, cls_invite = _selection_state(selected)
|
||||
hint_cls, hint_txt = _change_hint(selected, sub_info)
|
||||
return value, cls_simple, cls_soutien, cls_invite, hint_cls, hint_txt
|
||||
|
||||
|
||||
def _legal_note():
|
||||
|
||||
@@ -77,3 +77,42 @@ def test_selectable_cards_preselects_current_plan():
|
||||
text = str(m._selectable_cards(trial_for=lambda key: None, selected="soutien"))
|
||||
# la card soutien est marquée sélectionnée, pas la card simple
|
||||
assert "plan-selectable selected" in text
|
||||
|
||||
|
||||
def test_change_hint_shown_when_plan_differs():
|
||||
from src.pages.compte import abonnement_mes_infos as m
|
||||
|
||||
cls, txt = m._change_hint(
|
||||
"soutien",
|
||||
{"current_plan": "simple", "status": "active", "echeance": "1er janvier"},
|
||||
)
|
||||
assert cls != "d-none"
|
||||
assert "prochaine échéance : 1er janvier" in txt
|
||||
|
||||
|
||||
def test_change_hint_hidden_when_same_plan():
|
||||
from src.pages.compte import abonnement_mes_infos as m
|
||||
|
||||
cls, txt = m._change_hint(
|
||||
"simple",
|
||||
{"current_plan": "simple", "status": "active", "echeance": "1er janvier"},
|
||||
)
|
||||
assert cls == "d-none"
|
||||
assert txt == ""
|
||||
|
||||
|
||||
def test_change_hint_hidden_for_pending():
|
||||
from src.pages.compte import abonnement_mes_infos as m
|
||||
|
||||
cls, _ = m._change_hint(
|
||||
"soutien",
|
||||
{"current_plan": "simple", "status": "pending", "echeance": None},
|
||||
)
|
||||
assert cls == "d-none"
|
||||
|
||||
|
||||
def test_change_hint_hidden_in_subscribe_mode():
|
||||
from src.pages.compte import abonnement_mes_infos as m
|
||||
|
||||
cls, _ = m._change_hint("soutien", {})
|
||||
assert cls == "d-none"
|
||||
|
||||
Reference in New Issue
Block a user