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

Split state in two so that clearing and redirecting is separate #647

Merged
merged 1 commit into from
Jul 31, 2023
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: 12 additions & 4 deletions yal/assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ async def state_stop_assessment_reminders_confirm(self):
Choice("start", self._("Start questions")),
],
next={
"skip": "state_stop_assessment_reminders",
"skip": "state_stop_assessment_reminders_clear_fields",
"start": f"state_{assessment_reminder_name}_assessment",
},
error=self._(get_generic_error()),
Expand All @@ -507,13 +507,13 @@ async def state_stop_assessment_reminders_confirm(self):
Choice("start", self._("Start questions")),
],
next={
"skip": "state_stop_assessment_reminders",
"skip": "state_stop_assessment_reminders_clear_fields",
"start": f"state_{assessment_reminder_name}_assessment",
},
error=self._(get_generic_error()),
)

async def state_stop_assessment_reminders(self):
async def state_stop_assessment_reminders_clear_fields(self):
msisdn = utils.normalise_phonenumber(self.inbound.from_addr)
whatsapp_id = msisdn.lstrip(" + ")
assessment_name = None
Expand All @@ -537,7 +537,15 @@ async def state_stop_assessment_reminders(self):
if error:
return await self.go_to_state("state_error")

if assessment_name != "locus_of_control":
self.save_metadata("last_assessment_reminder_cleared_name", assessment_name)
return await self.go_to_state("state_stop_assessment_reminders")

async def state_stop_assessment_reminders(self):
last_assessment_reminder_cleared_name = self.user.metadata.get(
"last_assessment_reminder_cleared_name"
)
self.delete_metadata("last_assessment_reminder_cleared_name")
if last_assessment_reminder_cleared_name != "locus_of_control":
return WhatsAppButtonState(
self,
question=self._(
Expand Down
1 change: 1 addition & 0 deletions yal/tests/states_dictionary.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
| state_sexual_health_literacy_send_risk_message | TRUE | Text | TRUE | Sends the user a message based on their risk score, takes in "yes" and "no" |
| state_handle_assessment_reminder_response | FALSE | | | Handles the response to the assessment reminders |
| state_stop_assessment_reminders_confirm | TRUE | Text | TRUE | Confirms that the user no longer wants assessment reminders |
| state_stop_assessment_reminders_clear_fields | FALSE | Text | FALSE | Clears the users assessment reminders, then send user on to next state to determine where they want to go
| state_stop_assessment_reminders | TRUE | Text | TRUE | Sets the user to no longer get assessment reminders, asks user if they would like to go to menu or aaq |
| state_reschedule_assessment_reminder | | | | Schedules the assessment reminders |
| state_remind_tomorrow | TRUE | Text | TRUE | Lets the user know we will remind them tomorrow, asks the user if they would like to go to the mainmenu |
Expand Down
Loading