-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Subscription feature (#936) * feat: add form to collect subscription data * feat: add form to collect subscription data * WIP: add ember-phone-input * feat: add not loggedin and subscribed screen and integreate API * feat: fixing bug * fix: bug to show form even if user is already subscribed * fix: urls * fix: urls * fix: urls * delete: service subscribe test * fix: resolve comments * Update app/components/header.hbs Co-authored-by: Mehul Kiran Chaudhari <[email protected]> * fix: comments and remove modal * fix: phone number input * fix: content change * fix: remove card * fix: remove comments * fix:subscribe message --------- Co-authored-by: Vinit khandal <[email protected]> Co-authored-by: Mehul Kiran Chaudhari <[email protected]> * subscription feature fixes (#944) * fix: navbar & css & phone validation * fix: PR comments * feat: add error to in valid input * fix: lint --------- Co-authored-by: Vinit khandal <[email protected]> Co-authored-by: Mehul Kiran Chaudhari <[email protected]>
- Loading branch information
1 parent
62f2fa0
commit 945b102
Showing
17 changed files
with
493 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const phoneNumberRegex = | ||
/^[+]{1}(?:[0-9\-\\(\\)\\/.]\s?){6,15}[0-9]{1}$/; |
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,100 @@ | ||
import Controller from '@ember/controller'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
import { RDS_TWITTER, APPS } from '../constants/urls'; | ||
import { TOAST_OPTIONS } from '../constants/toast-options'; | ||
import { phoneNumberRegex } from '../constants/regex'; | ||
|
||
export default class SubscribeController extends Controller { | ||
@service login; | ||
@tracked isFormOpen = false; | ||
@tracked email = ''; | ||
@tracked phone = ''; | ||
@tracked userData = null; | ||
@tracked isLoading = false; | ||
@tracked showSubscribedMessage = false; | ||
@service toast; | ||
@tracked isPhoneValid = true; | ||
|
||
RDS_TWITTER = RDS_TWITTER; | ||
|
||
constructor() { | ||
super(...arguments); | ||
this.userData = this.login.userData; | ||
} | ||
|
||
get isLoggedIn() { | ||
return this.login.isLoggedIn; | ||
} | ||
|
||
get isSubscribed() { | ||
return this.login.userData.isSubscribed; | ||
} | ||
|
||
get isSubmitDisabled() { | ||
const isPhoneValid = !this.phone || phoneNumberRegex.test(this.phone); | ||
return !this.email || !isPhoneValid; | ||
} | ||
|
||
@action | ||
toggleFormModal() { | ||
this.isFormOpen = !this.isFormOpen; | ||
} | ||
|
||
@action | ||
updateEmail(event) { | ||
this.email = event.target.value; | ||
} | ||
|
||
@action | ||
updatePhone(event) { | ||
this.phone = event.target.value; | ||
this.isPhoneValid = !this.phone || phoneNumberRegex.test(this.phone); | ||
} | ||
|
||
@action | ||
async handleSubmit(event) { | ||
event.preventDefault(); | ||
if (!this.isSubmitDisabled) { | ||
this.isLoading = true; | ||
try { | ||
const url = `${APPS.API_BACKEND}/subscription?dev=true`; | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
email: this.email, | ||
phoneNumber: this.phone, | ||
}), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
credentials: 'include', | ||
}); | ||
if (!response.ok) { | ||
this.toast.error( | ||
'Something went wrong. Please try again.', | ||
'', | ||
TOAST_OPTIONS, | ||
); | ||
} else { | ||
this.login.userData.isSubscribed = true; | ||
this.isFormOpen = false; | ||
this.showSubscribedMessage = true; | ||
this.toast.success('🎉 Thankyou for subscribing!', '', TOAST_OPTIONS); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
this.toast.error( | ||
`Something went wrong. ${error.message}`, | ||
'', | ||
TOAST_OPTIONS, | ||
); | ||
} finally { | ||
this.isLoading = false; | ||
} | ||
this.email = ''; | ||
this.phone = ''; | ||
} | ||
} | ||
} |
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,3 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default class SubscribeRoute extends Route {} |
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,23 @@ | ||
.phone-input { | ||
display: flex; | ||
align-items: center; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.country-code-select { | ||
margin-right: 10px; | ||
} | ||
|
||
.phone-number-input { | ||
flex-grow: 1; | ||
} | ||
|
||
.phone-input select, | ||
.phone-input input[type="tel"] { | ||
width: 100%; | ||
padding: 5px; | ||
} | ||
|
||
button { | ||
padding: 5px 10px; | ||
} |
Oops, something went wrong.