-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const APPLICATION_STATUS_TYPES = { | ||
accepted: 'accepted', | ||
rejected: 'rejected', | ||
pending: 'pending', | ||
}; |
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 |
---|---|---|
@@ -1,74 +1,60 @@ | ||
import Controller from '@ember/controller'; | ||
import { action } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
import { APPS } from '../constants/urls'; | ||
import { validateApplicationDetails } from '../utils/validate-application-details'; | ||
import { APPLICATION_STATUS_TYPES } from '../constants/application'; | ||
|
||
export default class IntroController extends Controller { | ||
@service login; | ||
@tracked remarks = ''; | ||
statusTypes = APPLICATION_STATUS_TYPES; | ||
|
||
@tracked rejectionNote = localStorage.getItem('rejectionNote') || ''; | ||
@tracked isRejected = localStorage.getItem('isRejected') === 'true'; | ||
@action | ||
updateRemarks(e) { | ||
const value = e.currentTarget.value; | ||
this.remarks = value; | ||
} | ||
|
||
@action | ||
async approveAction() { | ||
const userId = this.model.userId; | ||
async approveRejectAction(status) { | ||
const initialApplicationDetails = this.model?.[0]; | ||
|
||
if (!userId) { | ||
alert('User ID is missing. Unable to generate invite link.'); | ||
const { isValid, data } = validateApplicationDetails( | ||
initialApplicationDetails, | ||
); | ||
|
||
if (!isValid || !data) { | ||
alert('Invalid application details.'); | ||
return; | ||
} | ||
|
||
const applicationId = data.id; | ||
const body = { status, feedback: this.remarks }; | ||
|
||
try { | ||
const response = await fetch( | ||
`https://api.realdevsquad.com/discord/invites?userId=${userId}`, | ||
`${APPS.API_BACKEND}/applications/${applicationId}`, | ||
{ | ||
method: 'POST', | ||
method: 'PATCH', | ||
credentials: 'include', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(body), | ||
}, | ||
); | ||
|
||
if (response.ok) { | ||
const result = await response.json(); | ||
const inviteLink = result.inviteLink; | ||
|
||
this.model.inviteLink = inviteLink; | ||
|
||
alert('User approved and invite link generated.'); | ||
} else if (response.status === 409) { | ||
alert('Invite link is already present for this user.'); | ||
} else if (response.status === 403 || response.status === 404) { | ||
const errorData = await response.json(); | ||
alert(`Failed to generate invite link: ${errorData.message}`); | ||
} else { | ||
const errorData = await response.json(); | ||
alert(`Failed to generate invite link: ${errorData.message}`); | ||
if (!response.ok || response.status >= 400) { | ||
alert('Failed to update application status.'); | ||
return; | ||
} | ||
|
||
alert(`Application ${status.toLowerCase()} successfully.`); | ||
} catch (error) { | ||
console.error('Error generating invite link:', error); | ||
alert('An error occurred. Please try again later.'); | ||
alert('Something went wrong, please try again later.'); | ||
console.error('Error :', error); | ||
} | ||
} | ||
|
||
@action | ||
copyToClipboard(link) { | ||
navigator.clipboard | ||
.writeText(link) | ||
.then(() => { | ||
alert('Invite link copied to clipboard!'); | ||
}) | ||
.catch((err) => { | ||
console.error('Failed to copy the text: ', err); | ||
}); | ||
} | ||
|
||
@action | ||
rejectAction() { | ||
const feedbackNote = document.querySelector('.comment-box').value.trim(); | ||
this.rejectionNote = feedbackNote; | ||
this.isRejected = true; | ||
|
||
// Store in local storage | ||
localStorage.setItem('rejectionNote', feedbackNote); | ||
localStorage.setItem('isRejected', 'true'); | ||
} | ||
} |
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,36 @@ | ||
/** | ||
* Generate application details | ||
* --- | ||
* @param {Object} applicationDetails | ||
* @param {string} applicationDetails.id | ||
* @param {Object} applicationDetails.intro | ||
* @param {string} applicationDetails.intro.funFact | ||
* @param {string} applicationDetails.intro.forFun | ||
* @param {number} applicationDetails.intro.numberOfHours | ||
* @param {string} applicationDetails.intro.whyRds | ||
* @param {string} applicationDetails.intro.introduction | ||
* @param {Object} applicationDetails.biodata | ||
* @param {string} applicationDetails.biodata.firstName | ||
* @param {string} applicationDetails.biodata.lastName | ||
* @param {Object} applicationDetails.location | ||
* @param {string} applicationDetails.location.country | ||
* @param {string} applicationDetails.location.city | ||
* @param {string} applicationDetails.location.state | ||
* @param {string} applicationDetails.foundFrom | ||
* @param {string} applicationDetails.userId | ||
* @param {Object} applicationDetails.professional | ||
* @param {string} applicationDetails.professional.skills | ||
* @param {string} applicationDetails.professional.institution | ||
* @param {string} applicationDetails.status - "accepted" | "rejected" | "pending" | ||
* | ||
* @returns {Object} validateApplicationDetails | ||
* @returns {boolean} validateApplicationDetails.isValid | ||
* @returns {applicationDetails} validateApplicationDetails.data | ||
*/ | ||
export const validateApplicationDetails = (applicationDetails) => { | ||
if (!applicationDetails || !applicationDetails.userId) { | ||
return { isValid: false, data: null }; | ||
} | ||
|
||
return { isValid: true, data: applicationDetails }; | ||
}; |