From b4b85ec238f117ae8d47eee92085b0bfe6322180 Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Tue, 5 Aug 2025 19:10:09 -0700 Subject: [PATCH] Allow new/edit on same page & infer company --- .../main/jobs/editor/jobeditor.component.html | 43 ++++-------- .../main/jobs/editor/jobeditor.component.ts | 66 ++++++++++++++----- 2 files changed, 62 insertions(+), 47 deletions(-) diff --git a/src/Client/src/app/pages/main/jobs/editor/jobeditor.component.html b/src/Client/src/app/pages/main/jobs/editor/jobeditor.component.html index c519c73..e60b47f 100644 --- a/src/Client/src/app/pages/main/jobs/editor/jobeditor.component.html +++ b/src/Client/src/app/pages/main/jobs/editor/jobeditor.component.html @@ -1,33 +1,14 @@

POST A NEW JOB

-
- - -
-
-
- - - -
- -
-
+
- +
@@ -40,7 +21,7 @@
- @@ -50,7 +31,7 @@
- +
@@ -59,28 +40,28 @@
-
+

Job Location

- +
- +
- +
- +
@@ -96,11 +77,11 @@
- +
- +
@@ -113,7 +94,7 @@
- +
diff --git a/src/Client/src/app/pages/main/jobs/editor/jobeditor.component.ts b/src/Client/src/app/pages/main/jobs/editor/jobeditor.component.ts index 63b61bc..b5522dc 100644 --- a/src/Client/src/app/pages/main/jobs/editor/jobeditor.component.ts +++ b/src/Client/src/app/pages/main/jobs/editor/jobeditor.component.ts @@ -15,31 +15,46 @@ import { Company, Employee } from 'app/models/Company'; imports: [ FormsModule, CommonModule, RouterModule ] }) export class JobEditorComponent { + public ErrorMsg: string = ""; @ViewChildren('step') formSteps!: QueryList>; currentStep: number = 0; - public employeeOfList: Employee[] = []; - public selectedCompany: Company = new Company; + public Listing: JobListing = new JobListing(); - public newListing: JobListing = new JobListing(); - public ErrorMsg: string = ""; + public mode: string = ""; + public modeID: number = 0; constructor( private http: HttpClient, private router: Router, private route: ActivatedRoute, private title: Title, public auth: Authentication ) { this.title.setTitle("Jobs - Editor | BoredCareers"); - this.http.get("api/employee").subscribe({ - next: empOf => { - if (empOf.length === 0){ - router.navigate(["company/connect"]); - } - this.employeeOfList = empOf; - }, - error: err => { - this.ErrorMsg = err.error; + this.route.queryParams.subscribe(params => { + const CompanyID = params['CompanyID'] ? +params['CompanyID'] : null; + const JobID = params['JobID'] ? +params['JobID'] : null; + if (CompanyID !== null && JobID !== null){ + this.router.navigate([""]); + }else if (CompanyID !== null ){ + this.mode = "new"; + this.modeID = CompanyID; + }else if(JobID !== null){ + this.mode = "edit"; + this.modeID = JobID; + }else if (CompanyID === null && JobID === null){ + this.router.navigate([""]); + } + + if (this.mode === "edit") { + this.http.get("api/joblisting/" + JobID).subscribe({ + next: data => { + this.Listing = data; + }, + error: err => { + this.ErrorMsg = err.error; + } + }); } }); - }; + } ngAfterViewInit(){ this.formSteps.changes.subscribe(() => { @@ -70,8 +85,8 @@ export class JobEditorComponent { this.updateUI(); } - PostJobListing(jobListing: JobListing){ - jobListing.companyID = this.selectedCompany.id!; + PostNewJob(jobListing: JobListing){ + jobListing.companyID = this.modeID; this.http.post("api/joblisting", jobListing).subscribe({ next: data => { this.router.navigate([""]); @@ -82,4 +97,23 @@ export class JobEditorComponent { }); } + PostEditJob(jobListing: JobListing){ + this.http.post("api/joblisting", jobListing).subscribe({ + next: data => { + this.router.navigate([""]); + }, + error: err => { + this.ErrorMsg = err.error; + } + }); + } + + SubmitForm(job: JobListing){ + if (this.mode === "new"){ + this.PostNewJob(job); + }else if (this.mode === "edit"){ + this.PostEditJob(job); + } + } + } \ No newline at end of file