Standardize new vs update

This commit is contained in:
2025-08-19 20:42:30 -07:00
parent 8bb8b4aedf
commit fee10939bb
4 changed files with 19 additions and 13 deletions
@@ -156,7 +156,11 @@
</div> </div>
<div class="content-frame"> <div class="content-frame">
<button type="button" (click)="prevStep()">Back</button> <button type="button" (click)="prevStep()">Back</button>
@if(isNewCompany){
<button type="submit">CREATE COMPANY</button> <button type="submit">CREATE COMPANY</button>
}@else{
<button type="submit">UPDATE COMPANY</button>
}
</div> </div>
<div class="footer-frame"> <div class="footer-frame">
<span>Does everything look good</span><br /> <span>Does everything look good</span><br />
@@ -19,6 +19,7 @@ export class CompanyEditorComponent {
currentStep: number = 0; currentStep: number = 0;
public newListing: Company = new Company(); public newListing: Company = new Company();
public isNewCompany: boolean = true;
public ErrorMsg: string = ""; public ErrorMsg: string = "";
MaxFileMB: number = 3; MaxFileMB: number = 3;
@@ -36,6 +37,7 @@ export class CompanyEditorComponent {
this.http.get<Company>("api/company?CompanyID=" + CompanyID).subscribe({ this.http.get<Company>("api/company?CompanyID=" + CompanyID).subscribe({
next: data => { next: data => {
this.newListing = data; this.newListing = data;
this.isNewCompany = false;
}, },
error: err => { error: err => {
this.ErrorMsg = err.error; this.ErrorMsg = err.error;
@@ -169,9 +171,9 @@ export class CompanyEditorComponent {
return; return;
} }
this.http.post("api/company?newCompany=true", company).subscribe({ this.http.post("api/company", company).subscribe({
next: data => { next: data => {
this.router.navigate([""]); this.router.navigate(["/company"]);
}, },
error: err => { error: err => {
this.ErrorMsg = err.error; this.ErrorMsg = err.error;
@@ -108,7 +108,11 @@
<div class="center"> <div class="center">
<div class="content-frame"> <div class="content-frame">
<button type="button" (click)="prevStep()">Back</button> <button type="button" (click)="prevStep()">Back</button>
<button type="submit">CREATE JOB LISTING</button> @if (isNewListing){
<button type="submit">CREATE LISTING</button>
}@else{
<button type="submit">UPDATE LISTING</button>
}
</div> </div>
</div> </div>
</div> </div>
@@ -20,9 +20,9 @@ export class JobEditorComponent {
currentStep: number = 0; currentStep: number = 0;
public Listing: JobListing = new JobListing(); public Listing: JobListing = new JobListing();
public isNewListing: boolean = true;
public mode: string = ""; public mode: string = "";
public modeID: number = 0;
constructor( private http: HttpClient, private router: Router, private route: ActivatedRoute, private title: Title, public auth: Authentication ) { constructor( private http: HttpClient, private router: Router, private route: ActivatedRoute, private title: Title, public auth: Authentication ) {
this.title.setTitle("Jobs - Editor | BoredCareers"); this.title.setTitle("Jobs - Editor | BoredCareers");
@@ -39,10 +39,11 @@ export class JobEditorComponent {
this.router.navigate([""]); this.router.navigate([""]);
}else if (CompanyID !== null ){ }else if (CompanyID !== null ){
this.mode = "new"; this.mode = "new";
this.modeID = CompanyID; this.Listing.companyID = CompanyID;
}else if(JobID !== null){ }else if(JobID !== null){
this.mode = "edit"; this.mode = "edit";
this.modeID = JobID; this.Listing.id = JobID;
this.isNewListing = false;
}else if (CompanyID === null && JobID === null){ }else if (CompanyID === null && JobID === null){
this.router.navigate([""]); this.router.navigate([""]);
} }
@@ -90,14 +91,9 @@ export class JobEditorComponent {
} }
SubmitForm(jobListing: JobListing){ SubmitForm(jobListing: JobListing){
if (this.mode === "new"){
jobListing.companyID = this.modeID;
} else if (this.mode === "edit"){
jobListing.id = this.modeID;
}
this.http.post("api/joblisting", jobListing).subscribe({ this.http.post("api/joblisting", jobListing).subscribe({
next: data => { next: data => {
this.router.navigate([""]); this.router.navigate(["/company"]);
}, },
error: err => { error: err => {
this.ErrorMsg = err.error; this.ErrorMsg = err.error;