-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2218 from geeksforsocialchange/ik-2128-removing-p…
…artner-addresses Removing partner addresses
- Loading branch information
Showing
13 changed files
with
269 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
|
||
export default class extends Controller { | ||
static values = { | ||
partnerId: String, | ||
warnOfDelisting: String, // "true" or "false" | ||
}; | ||
|
||
static targets = ["addressInfoArea"]; | ||
|
||
static addressFieldIds = [ | ||
"partner_address_attributes_street_address", | ||
"partner_address_attributes_street_address2", | ||
"partner_address_attributes_street_address3", | ||
"partner_address_attributes_city", | ||
"partner_address_attributes_postcode", | ||
]; | ||
|
||
connect() {} | ||
|
||
disconnect() {} | ||
|
||
do_clear_address(event) { | ||
event.preventDefault(); | ||
|
||
let warning_text = "Please confirm you want to clear this partners address"; | ||
if (this.warnOfDelistingValue === "true") { | ||
warning_text = `This address links to you to this partner and by clearing this address you will no longer be able to access this partner,\n\n${warning_text}`; | ||
} | ||
|
||
if (!confirm(warning_text)) { | ||
return; | ||
} | ||
|
||
const csrfToken = document | ||
.querySelector('meta[name="csrf-token"]') | ||
.getAttribute("content"); | ||
|
||
const url = `/partners/${this.partnerIdValue}/clear_address`; | ||
|
||
const payload = { | ||
method: "DELETE", | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json", | ||
"X-CSRF-Token": csrfToken, | ||
}, | ||
body: "", | ||
}; | ||
|
||
fetch(url, payload) | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
this.constructor.addressFieldIds.forEach((id) => { | ||
let node = document.getElementById(id); | ||
node.value = ""; | ||
node.classList.remove("is-valid"); | ||
}); | ||
|
||
this.addressInfoAreaTarget.innerHTML = | ||
"<p>Address has been cleared</p>"; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<%= form.fields_for :address, @partner.address || Address.new do |address_form| %> | ||
<div class='nested-fields' | ||
data-controller="partner-address" | ||
data-partner-address-partner-id-value="<%= partner.id %>" | ||
data-partner-address-warn-of-delisting-value="<%= partner.warn_user_clear_address?(current_user) ? 'true' : 'false' %>"> | ||
|
||
<%# this view is augmented by the /app/javascript/controllers/parter_address_controller.js %> | ||
|
||
<%= address_form.input :street_address, | ||
class: "form-control address_1 address_field", | ||
label: 'Street address' %> | ||
|
||
<%= address_form.input :street_address2, | ||
class: "form-control address_2 address_field", | ||
label: 'Street address 2' %> | ||
|
||
<%= address_form.input :street_address3, | ||
class: "form-control address_3 address_field", | ||
label: 'Street address 3' %> | ||
|
||
<%= address_form.input :city, | ||
class: "form-control city address_field" %> | ||
|
||
<%= address_form.input :postcode, | ||
class: "form-control postcode address_field" %> | ||
|
||
<% if partner.can_clear_address?(current_user) %> | ||
<div data-partner-address-target="addressInfoArea"> | ||
<% if partner.address.neighbourhood.present? %> | ||
<p>Address in neighbourhood <%= link_to_neighbourhood(partner.address.neighbourhood) %>.</p> | ||
<% end %> | ||
<p> | ||
<%= link_to 'Clear Address', | ||
'#', | ||
class: "btn btn-secondary btn-sm", | ||
data: { action: "click->partner-address#do_clear_address" } %> | ||
</p> | ||
</div> | ||
<% end %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters