user-feedback / views /intro_screen.py
Ashmi Banerjee
updated with resuming surveys:
0759822
raw
history blame
1.88 kB
import streamlit as st
import os
from dotenv import load_dotenv
from views.continue_survey import continue_survey_screen
from db.crud import read
load_dotenv()
VALIDATION_CODE = os.getenv("VALIDATION_CODE")
def validate_username(username: str) -> bool:
return bool(username.strip())
def validate_code(input_code: str) -> bool:
"""Validate the entered code against the hardcoded validation code"""
return input_code.strip() == VALIDATION_CODE
def welcome_screen():
"""Display the welcome screen and direct users accordingly."""
st.title("Welcome to the Feedback Survey")
username_input = st.text_input("Enter your First name and press TAB:")
validation_code_input = st.text_input("Enter the validation code to proceed and press ENTER:")
next_button = st.button("Next")
if (username_input and validation_code_input) or next_button:
if validate_username(username_input) and validate_code(validation_code_input):
st.session_state.username = username_input
# # Check if user progress exists in Firebase
# saved_state = read(username_input)
#
# if saved_state:
# # Show continue survey screen for returning users
# st.success("Previous progress found.")
# continue_survey_screen()
# else:
# # Start fresh for new users
# st.success("Starting a new survey.")
# st.session_state.current_index = 0
# st.session_state.responses = []
# st.rerun()
else:
if not validate_username(username_input):
st.warning("Invalid Prolific ID. Please check and try again.")
if not validate_code(validation_code_input):
st.warning("Invalid validation code. Please check and try again.")