-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(job): create job with github api
- Loading branch information
Showing
7 changed files
with
224 additions
and
50 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
27 changes: 26 additions & 1 deletion
27
src/app/presentation/job/create-job-dialog/create-job-dialog.component.scss
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,7 +1,32 @@ | ||
@import '../../../../styles/color'; | ||
|
||
.full-width { | ||
width: 100%; | ||
} | ||
|
||
.half-width { | ||
width: 50%; | ||
width: 48%; | ||
} | ||
|
||
.margin-left { | ||
margin-left: 15px; | ||
} | ||
|
||
.operate { | ||
float: right; | ||
} | ||
|
||
.error { | ||
color: $error-color; | ||
} | ||
|
||
form { | ||
position: relative; | ||
} | ||
|
||
.close { | ||
position: absolute; | ||
right: -10px; | ||
top: -10px; | ||
cursor: pointer; | ||
} |
74 changes: 67 additions & 7 deletions
74
src/app/presentation/job/create-job-dialog/create-job-dialog.component.ts
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,23 +1,83 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Component, Inject, OnInit } from '@angular/core'; | ||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | ||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; | ||
import { JobData } from './JobData'; | ||
import { formToIssue, GITHUB_TOKEN, JobData } from './JobData'; | ||
|
||
@Component({ | ||
selector: 'create-job-dialog', | ||
templateUrl: './create-job-dialog.component.html', | ||
styleUrls: ['./create-job-dialog.component.scss'], | ||
}) | ||
export class CreateJobDialogComponent implements OnInit { | ||
jobForm: FormGroup; | ||
errorMessage: string; | ||
constructor( | ||
public dialogRef: MatDialogRef<CreateJobDialogComponent>, | ||
@Inject(MAT_DIALOG_DATA) public data: JobData | ||
) {} | ||
@Inject(MAT_DIALOG_DATA) public data: JobData, | ||
private fb: FormBuilder, | ||
private http: HttpClient | ||
) { | ||
this.jobForm = this.fb.group({ | ||
jobTitle: ['', Validators.required], | ||
companyName: ['', Validators.required], | ||
companyDescription: ['', Validators.required], | ||
jobDescription: ['', Validators.required], | ||
yearRequire: ['', Validators.required], | ||
workAddress: ['', Validators.required], | ||
salary: ['', Validators.required], | ||
contact: ['', Validators.required], | ||
}); | ||
} | ||
|
||
ngOnInit(): void {} | ||
|
||
close(flag = false): void { | ||
this.dialogRef.close(flag); | ||
} | ||
|
||
ngOnInit(): void { | ||
console.log(this.data); | ||
onSubmit() { | ||
this.errorMessage = ''; | ||
for (const key of Object.keys(this.jobForm.controls)) { | ||
this.jobForm.controls[key].markAsDirty(); | ||
this.jobForm.controls[key].updateValueAndValidity(); | ||
} | ||
if (this.jobForm.status === 'INVALID') { | ||
return; | ||
} | ||
|
||
this.commentOnGithubIssue(this.jobForm.value); | ||
} | ||
|
||
onReset() { | ||
this.errorMessage = ''; | ||
this.jobForm.reset(); | ||
} | ||
|
||
onNoClick(): void { | ||
this.dialogRef.close(); | ||
commentOnGithubIssue(formValue) { | ||
const body = formToIssue(formValue); | ||
|
||
this.http | ||
.post( | ||
'https://api.github.com/repos/phodal/ledge/issues/140/comments', | ||
{ body }, | ||
{ | ||
headers: { | ||
Authorization: `token ${GITHUB_TOKEN}`, | ||
}, | ||
} | ||
) | ||
.subscribe( | ||
(res: any) => { | ||
if (res.id) { | ||
this.close(true); | ||
} else { | ||
this.errorMessage = res.message; | ||
} | ||
}, | ||
(err) => { | ||
this.errorMessage = err.message; | ||
} | ||
); | ||
} | ||
} |
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