Change add_letter error to a redirect

This commit is contained in:
Sage Vaillancourt 2023-05-03 20:09:12 +00:00
parent cd87e4fa29
commit cca15686bf
2 changed files with 8 additions and 3 deletions

View File

@ -167,7 +167,7 @@ def add_letter() -> Response:
existing_letter_count = len(db.get_user_letters(user.id))
if user.in_free_tier() and existing_letter_count >= FREE_TIER_TEMPLATES:
return render_index(error=f'A maximum of {FREE_TIER_TEMPLATES} templates are available to each user.')
return redirect('/?error=template_limit')
new_letter_name = f'Letter{existing_letter_count + 1}'
default_form_json = jsonify(CLForm().to_cl_data()).get_data(True)
db.add_letter(user.id, new_letter_name, default_form_json)
@ -194,6 +194,9 @@ def index_get() -> Response:
form.letterName.data = 1
selected_letter = request.args.get('letter_name')
error = None
if request.args.get('error') == 'template_limit':
error = f'A maximum of {FREE_TIER_TEMPLATES} templates are available to each user.'
if selected_letter:
for i, letter in enumerate(letters):
@ -216,7 +219,7 @@ def index_get() -> Response:
form.skillTypes.data = data['skillTypes']
form.username.data = data['username']
return render_index(form=form)
return render_index(form=form, error=error)
@writing_blueprint.route('/reset', methods=['POST', 'GET'])

View File

@ -59,7 +59,9 @@
{% else %}
<div class="user logged-out">
<form action="/create_account">
<div class="black-white-button" style="font-family: 'BarlowMedium'; margin-right: 1em; padding: 0.4em 1em;" onclick="showModal(false, 'Create your account')">Create account</div>
<div class="black-white-button" style="font-family: 'BarlowMedium'; margin-right: 1em; padding: 0.4em 1em;" onclick="showModal(false, 'Create your account')">
Create account
</div>
<div class="white-black-button" style="margin: 0; padding: 0.4em 1em;" onclick="showModal(true, 'Login now')">Log in</div>
</form>
</div>