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

1157 as a shop owner when saving plans i see oops something is mi #1158

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bffe154
wip Fix #1157 improve edit plan error messages showing field and expl…
chrisjsimpson May 19, 2023
415cff2
#1157 trip() whitespace when storing note_to_buyer_message/customer note
chrisjsimpson May 19, 2023
60ea356
#1157 always check note_to_seller_required if note_to_buyer_message i…
chrisjsimpson May 19, 2023
e2c74af
#1157 tidy trailing space note_to_buyer_message
chrisjsimpson May 19, 2023
f862b93
#1157 Trim whitespace form note_to_buyer_message when checking if empty
chrisjsimpson May 19, 2023
a38a11e
#1157 black format
chrisjsimpson May 19, 2023
39a7ee3
wip Fix #1157 improve edit plan error messages showing field and expl…
chrisjsimpson May 19, 2023
a4a3068
#1157 trip() whitespace when storing note_to_buyer_message/customer note
chrisjsimpson May 19, 2023
d7a56c7
#1157 always check note_to_seller_required if note_to_buyer_message i…
chrisjsimpson May 19, 2023
d469af8
#1157 tidy trailing space note_to_buyer_message
chrisjsimpson May 19, 2023
bf3c24b
#1157 Trim whitespace form note_to_buyer_message when checking if empty
chrisjsimpson May 19, 2023
e4f4efc
#1157 black format
chrisjsimpson May 19, 2023
db14ff1
Merge branch '1157-as-a-shop-owner-when-saving-plans-i-see-oops-somet…
chrisjsimpson May 20, 2023
a888afc
#1157 improve form error handling visual feedback
chrisjsimpson May 20, 2023
9f96487
Fix #1161 use SUBDOMAIN over github.head_ref for pr-preview
chrisjsimpson May 20, 2023
f013f2e
wip Fix #1157 improve edit plan error messages showing field and expl…
chrisjsimpson May 19, 2023
bc2404d
#1157 trip() whitespace when storing note_to_buyer_message/customer note
chrisjsimpson May 19, 2023
ecb149f
#1157 always check note_to_seller_required if note_to_buyer_message i…
chrisjsimpson May 19, 2023
74a6dc4
#1157 tidy trailing space note_to_buyer_message
chrisjsimpson May 19, 2023
457abcb
#1157 Trim whitespace form note_to_buyer_message when checking if empty
chrisjsimpson May 19, 2023
916dd07
#1157 black format
chrisjsimpson May 19, 2023
fa2667c
#1157 trip() whitespace when storing note_to_buyer_message/customer note
chrisjsimpson May 19, 2023
1e428e0
#1157 black format
chrisjsimpson May 19, 2023
3e5a019
#1157 improve form error handling visual feedback
chrisjsimpson May 20, 2023
20fffe6
Merge branch '1157-as-a-shop-owner-when-saving-plans-i-see-oops-somet…
chrisjsimpson May 20, 2023
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
8 changes: 4 additions & 4 deletions .github/workflows/pr-demo-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ jobs:
echo The PR was raised by: ${{ github.event.pull_request.user.login }}
eval `ssh-agent -s`
ssh-add - <<< "$SSH_PRIVATE_KEY"
echo Creating dokku app ${{ github.head_ref }}
echo Creating dokku app ${{ env.SUBDOMAIN }}.pcpink.co.uk/
ssh dokku@$DOKKU_HOST -C "dokku apps:create ${{ env.SUBDOMAIN }}" | true
echo The url will be ${{ github.head_ref }}.pcpink.co.uk
echo The url will be ${{ env.SUBDOMAIN }}.pcpink.co.uk
ssh dokku@$DOKKU_HOST -C "dokku git:initialize ${{ env.SUBDOMAIN }}"
ssh dokku@$DOKKU_HOST -C "dokku git:set ${{ env.SUBDOMAIN }} deploy-branch ${{ github.head_ref }}"
# set Stripe test keys as env vars dor dokku/docker
Expand All @@ -82,7 +82,7 @@ jobs:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
DOKKU_HOST: ${{ secrets.DOKKU_HOST }}
run: |
echo Visit your pr here: http://${{ github.head_ref }}.pcpink.co.uk
echo Visit your pr here: http://${{ env.SUBDOMAIN }}.pcpink.co.uk
- name: 'Comment PR with web address of application live preview'
uses: actions/github-script@v3
if: github.event_name == 'pull_request'
Expand All @@ -92,7 +92,7 @@ jobs:
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "🙌 Live preview is here: http://${{ github.head_ref }}.pcpink.co.uk"
body: "🙌 Live preview is here: http://${{ env.SUBDOMAIN }}.pcpink.co.uk"
})

- uses: actions/setup-node@v3
Expand Down
26 changes: 24 additions & 2 deletions subscribie/blueprints/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def edit():
plan_requirements.note_to_seller_required = False

plan_requirements.note_to_buyer_message = escape(
str(getPlan(form.note_to_buyer_message, index, default="").data)
str(getPlan(form.note_to_buyer_message, index, default="").data).strip()
)

try:
Expand Down Expand Up @@ -615,7 +615,29 @@ def edit():
database.session.commit() # Save
flash("Plan(s) updated.")
return redirect(url_for("admin.edit"))
return render_template("admin/edit.html", plans=plans, form=form)

# Form has validation errors, parse them
validation_errors = []
plansWithErrors = []
for key, value in form.errors.items():
# Work out index of error for plan index
try:
plansWithErrors = [i for i, x in enumerate(value) if x]
for planIndex in plansWithErrors:
plans[planIndex].has_errors = True
except Exception as e:
log.error(f"Error parsing plan form errors. {e}")
if key == "note_to_buyer_message":
key = "Customer note"
for sublist in value:
for item in sublist:
# Ensure item is a string before checking if it contains the error msg
if isinstance(item, str):
validation_errors.append(f"{key}: {item}")

return render_template(
"admin/edit.html", plans=plans, form=form, validation_errors=validation_errors
)


@admin.route("/add", methods=["GET", "POST"])
Expand Down
15 changes: 9 additions & 6 deletions subscribie/blueprints/admin/templates/admin/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ <h2 class="text-center text-dark mb-3">Edit Plans</h2>
<div class="alert alert-danger col-md-6 mx-auto">
<p><strong class="alert-heading">Oops, something is missing. Please take a look at:</strong></p>
<ul class=errors>
{% for error in form.errors %}
<li>{{ error }}</li>
{% for error in validation_errors %}
<li style="list-style: disc;">{{ error }}</li>
{% endfor %}
</ul>
</div>
Expand Down Expand Up @@ -51,7 +51,7 @@ <h2 class="text-center text-dark mb-3">Edit Plans</h2>
<div class="accordion col-lg-8 mx-auto mb-3" id="accordionExample">
{% for plan in plans %}
<div class="card">
<div class="card-header" id="{{ plan.uuid }}">
<div class="card-header{% if plan.has_errors %} alert-danger {% endif %}" id="{{ plan.uuid }}">
<button class="btn btn-link btn-block text-left" type="button" data-toggle="collapse" data-target="#collapse-{{ plan.uuid }}" aria-expanded="false" aria-controls="collapse-{{ plan.uuid }}">{{ plan.title }}</button>
</div>
<div id="collapse-{{ plan.uuid }}" class="collapse" aria-labelledby="{{ plan.uuid }}">
Expand Down Expand Up @@ -197,8 +197,7 @@ <h2 class="text-center text-dark mb-3">Edit Plans</h2>
<div class="form-group ">
<div class="form-check">
<input type="hidden" class="note_to_seller_required-check" data-id="{{ loop.index0 }}" name="note_to_seller_required-{{ loop.index0 }}" value="no">
<input type="checkbox" value="yes" class="form-check-input toggle" name="note_to_seller_required-{{ loop.index0 }}" id="note_to_seller_required-{{ loop.index0 }}" {% if plan.requirements.note_to_seller_required %} checked
{% endif %}>
<input type="checkbox" value="yes" class="form-check-input toggle" name="note_to_seller_required-{{ loop.index0 }}" id="note_to_seller_required-{{ loop.index0 }}" {% if plan.requirements.note_to_seller_required or plan.requirements.note_to_buyer_message | trim != "" %} checked {% endif %}>
<label class="form-check-label font-weight-bolder" for="note_to_seller_required-{{ loop.index0 }}">Require customer note</label>
</div>
<small class="form-text text-muted">
Expand All @@ -208,7 +207,11 @@ <h2 class="text-center text-dark mb-3">Edit Plans</h2>

<div class="form-group extra_fields" id="message">
<label for="note_to_buyer_message-{{ loop.index0 }}" class="col-form-label font-weight-bolder">Message for the customer</label>
<textarea class="form-control" id="note_to_buyer_message-{{ loop.index0 }}" name="note_to_buyer_message-{{ loop.index0 }}">{{ plan.requirements.note_to_buyer_message }} </textarea>
{% if form.note_to_buyer_message.errors[loop.index0] %}
<br />
<em>{{ form.note_to_buyer_message.errors[loop.index0][0] }}</em>
{% endif %}
<textarea class="form-control" id="note_to_buyer_message-{{ loop.index0 }}" name="note_to_buyer_message-{{ loop.index0 }}" maxlength="500" {% if form.note_to_buyer_message.errors[loop.index0] %} style="border: 3px solid red;" {% endif %}>{{ plan.requirements.note_to_buyer_message }}</textarea>
<small class="form-text text-muted">
This message will be shown during checkout to the customer
</small>
Expand Down