Skip to content

Commit

Permalink
Linting/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dhochbaum-dcp authored and TylerMatteo committed Dec 2, 2024
1 parent 0752171 commit b08b233
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
21 changes: 12 additions & 9 deletions client/app/components/subscription-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ export default class SubscriptionFormComponent extends Component {
isSubmitting = false;

showSubscriptionUpdateConfirmationModal = false;
updateStatus = "none";

updateStatus = 'none';

previousSubscriptions = {};

previousIsCommunityDistrict = false;

constructor(...args) {
Expand All @@ -31,7 +33,7 @@ export default class SubscriptionFormComponent extends Component {
this.previousIsCommunityDistrict = true;
}
// Copy subscriptions to compare for changes
this.previousSubscriptions = {...this.args.subscriptions}
this.previousSubscriptions = { ...this.args.subscriptions };
}
}

Expand All @@ -44,7 +46,7 @@ export default class SubscriptionFormComponent extends Component {
@computed('isCommunityDistrict', 'args.subscriptions', 'args.email')
get canBeSubmitted() {
// If it's an update, subscriptions must be different, or they must have unchecked CD Updates
if(this.args.isUpdate) {
if (this.args.isUpdate) {
if (this.previousIsCommunityDistrict && !this.isCommunityDistrict) return true;
if (!(Object.entries(this.args.subscriptions).find(([key, value]) => (this.previousSubscriptions[key] !== value)))) return false;
}
Expand Down Expand Up @@ -118,6 +120,7 @@ export default class SubscriptionFormComponent extends Component {
}

if (this.args.isUpdate) {
// eslint-disable-next-line no-restricted-syntax
for (const [key, value] of Object.entries(this.previousSubscriptions)) {
if (value !== this.args.subscriptions[key]) {
requestBody.subscriptions[key] = value ? 0 : 1;
Expand All @@ -126,14 +129,15 @@ export default class SubscriptionFormComponent extends Component {
}
// If it's an update, unsubscribe from all CDs if they unchecked the box
if (this.args.isUpdate && !this.isCommunityDistrict) {
// eslint-disable-next-line no-restricted-syntax
for (const [key, value] of Object.entries(this.previousSubscriptions)) {
if ((key !== "CW") && value) {
if ((key !== 'CW') && value) {
requestBody.subscriptions[key] = 0;
}
}
}

const response = await fetch(`${ENV.host}/subscribers${this.args.isUpdate ? (`/`+ this.args.id) : ''}`, {
const response = await fetch(`${ENV.host}/subscribers${this.args.isUpdate ? (`/${this.args.id}`) : ''}`, {
method: this.args.isUpdate ? 'PATCH' : 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -145,18 +149,17 @@ export default class SubscriptionFormComponent extends Component {

if (!response.ok) {
set(this, 'showSubscriptionUpdateConfirmationModal', true);
set(this, 'updateStatus', "error");
set(this, 'updateStatus', 'error');
throw await response.json();
}

if (!this.args.isUpdate) window.location.pathname = '/subscribed';

set(this, 'isSubmitting', false);

if(this.args.isUpdate) {
if (this.args.isUpdate) {
set(this, 'showSubscriptionUpdateConfirmationModal', true);
set(this, 'updateStatus', "success");
set(this, 'updateStatus', 'success');
}

}
}
7 changes: 4 additions & 3 deletions client/app/routes/subscription-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ export default Route.extend({
const body = await response.json();
if (!response.ok) throw await response.json();

var subscriptions = { CW: (body.subscriptions["CW"] === 1) };
const subscriptions = { CW: (body.subscriptions.CW === 1) };
const districts = lookupCommunityDistrict();
// eslint-disable-next-line no-restricted-syntax
for (const district of districts) {
if(body.subscriptions[district.code] && (body.subscriptions[district.code] === 1)) {
subscriptions[district.code] = true;
if (body.subscriptions[district.code] && (body.subscriptions[district.code] === 1)) {
subscriptions[district.code] = true;
} else {
subscriptions[district.code] = false;
}
Expand Down
1 change: 0 additions & 1 deletion client/app/styles/modules/_m-subscription-form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,4 @@ input[type=checkbox] {
display: flex;
width: 100%;
justify-content: center;
// padding-top: 200px;
}

0 comments on commit b08b233

Please sign in to comment.