Skip to content

Commit

Permalink
fix(career): corrige redirecionamento após cadastro de vaga
Browse files Browse the repository at this point in the history
closed #64
  • Loading branch information
guiseek committed Nov 24, 2024
1 parent e5e20ce commit 4d2f78b
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DeleteJobOpeningUseCase,
UpdateJobOpeningUseCase,
} from '@devmx/career-domain/client';
import { take, tap } from 'rxjs';

export class JobOpeningFacade extends EntityFacade<JobOpening> {
constructor(
Expand Down Expand Up @@ -36,11 +37,23 @@ export class JobOpeningFacade extends EntityFacade<JobOpening> {
}

create(data: EditableJobOpening) {
this.onCreate(this.createJobOpeningUseCase.execute(data));
const request$ = this.createJobOpeningUseCase.execute(data);

const onCreate = (selected: JobOpening) => this.setState({ selected });

this.onCreate(request$.pipe(tap(onCreate)));

return request$.pipe(take(1));
}

update(data: EditableJobOpening) {
this.onUpdate(this.updateJobOpeningUseCase.execute(data));
const request$ = this.updateJobOpeningUseCase.execute(data);

const onUpdate = (selected: JobOpening) => this.setState({ selected });

this.onUpdate(request$.pipe(tap(onUpdate)));

return request$.pipe(take(1));
}

delete(id: string) {
Expand Down
82 changes: 82 additions & 0 deletions packages/career/data-source/src/lib/dtos/created-job-opening.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { UserRefDto, RangeDto } from '@devmx/shared-data-source';
import { JobSkillDto } from './job-skill';
import { Exclude, Type } from 'class-transformer';
import {
JobMode,
JobType,
JobOpening,
JobContract,
ExperienceLevel,
} from '@devmx/shared-api-interfaces';

export class CreatedJobOpeningDto implements JobOpening {
@ApiProperty()
id: string;

@ApiProperty()
title: string;

@ApiProperty()
description: string;

@ApiProperty()
requirements: string;

@ApiProperty({
type: 'enum',
enum: ['junior', 'mid', 'senior'],
example: 'senior',
})
experience: ExperienceLevel;

@ApiProperty({
type: 'enum',
enum: ['CLT', 'PJ'],
example: 'CLT',
})
contract: JobContract;

@ApiProperty({
type: 'enum',
enum: ['full-time', 'part-time', 'contract', 'freelance'],
example: 'full-time',
})
type: JobType;

@ApiProperty({
type: 'enum',
enum: ['office', 'remote', 'hybrid'],
example: 'remote',
})
mode: JobMode;

@Type(() => JobSkillDto)
@ApiProperty({ type: () => [JobSkillDto] })
skills: JobSkillDto[];

@ApiPropertyOptional()
benefits?: string;

@Type(() => Array<RangeDto>)
@ApiPropertyOptional({ type: () => RangeDto })
salary?: RangeDto;

@ApiPropertyOptional()
contact?: string;

@ApiPropertyOptional()
company?: string;

@ApiPropertyOptional()
link?: string;

@ApiPropertyOptional()
open: boolean;

@ApiPropertyOptional()
active: boolean;

@Exclude()
owner: UserRefDto;
}
9 changes: 5 additions & 4 deletions packages/career/data-source/src/lib/dtos/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './create-job-opening';
export * from './job-opening';
export * from './job-skill';
export * from './update-job-opening';
export * from './create-job-opening';
export * from './created-job-opening';
export * from './job-opening';
export * from './job-skill';
export * from './update-job-opening';
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export const careerFeatureAdminRoutes: Route[] = [
providers: careerFeatureAdminProviders,
component: CareerFeatureAdminComponent,
children: [
{
path: 'minhas-ofertas/nova',
data: {
breadcrumb: 'Nova',
},
component: JobOpeningContainer,
},
{
path: 'minhas-ofertas/:id',
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ <h3 mat-subheader>Habilidades</h3>
</mat-card-content>

<mat-card-actions class="job-opening-actions" align="end">
<button mat-flat-button [disabled]="form.invalid">Salvar</button>
<button mat-flat-button>Salvar</button>
</mat-card-actions>
</mat-card>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@ import { EditorComponent } from '@devmx/shared-ui-global/editor';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { EditableSkill } from '@devmx/shared-api-interfaces';
import { IconComponent } from '@devmx/shared-ui-global/icon';
import { SkillDialogService } from '@devmx/learn-ui-shared';
import { MatButtonModule } from '@angular/material/button';
import { MatSelectModule } from '@angular/material/select';
import { MatSliderModule } from '@angular/material/slider';
import { MessageService } from '@devmx/shared-ui-global';
import { ActivatedRoute, Router } from '@angular/router';
import { MatInputModule } from '@angular/material/input';
import { SkillFacade } from '@devmx/learn-data-access';
import { MatListModule } from '@angular/material/list';
import { MatCardModule } from '@angular/material/card';
import { ReactiveFormsModule } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { JobOpeningForm } from '../../forms';
import { Subject } from 'rxjs';
import { Subject, take } from 'rxjs';
import {
inject,
Component,
ChangeDetectorRef,
ChangeDetectionStrategy,
} from '@angular/core';
import { MessageService } from '@devmx/shared-ui-global';
import { SkillDialogService } from '@devmx/learn-ui-shared';
import { SkillFacade } from '@devmx/learn-data-access';
import { EntityFacade } from '@devmx/shared-data-access';

@Component({
selector: 'devmx-career-admin-job-opening',
Expand All @@ -46,6 +45,8 @@ import { EntityFacade } from '@devmx/shared-data-access';
export class JobOpeningContainer {
route = inject(ActivatedRoute);

router = inject(Router);

cdr = inject(ChangeDetectorRef);

skillFacade = inject(SkillFacade);
Expand Down Expand Up @@ -98,17 +99,29 @@ export class JobOpeningContainer {
}

onSubmit() {
this.form.logErrors();

if (this.form.valid) {
const value = this.form.getRawValue();
if (value.id) this.jobFacade.update(value);
else this.jobFacade.create(value);
if (value.id) {
const update$ = this.jobFacade.update(value);
update$.pipe(take(1)).subscribe(() => {
const path = ['/', 'carreiras', 'administracao', 'minhas-ofertas'];
this.router.navigate(path);
});
} else {
const redirect$ = this.jobFacade.create(value);
redirect$.pipe(take(1)).subscribe(({ id }) => {
this.router.navigate(this.#getPath(id));
});
}

const message = `Armazenando informações`;
return this.messageService.open({ message });
}

return this.form.markAllAsTouched();
}

#getPath(id: string) {
return ['/', 'carreiras', 'administracao', 'minhas-ofertas', id];
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<a class="add-button tertiary-fab" mat-fab routerLink="nova">
<a class="tertiary-fab top right" mat-fab routerLink="nova">
<devmx-icon name="plus" />
</a>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
// justify-content: space-between;

.job-openings-container {
gap: 1em;
padding: 1em;
display: flex;
flex-flow: row wrap;
justify-content: flex-start;
grid-template-columns: repeat(2, 1fr);
display: grid;
grid-auto-flow: dense;

grid-template-columns: repeat(4, 1fr);

@media (max-width: 1918px) {
grid-template-columns: repeat(3, 1fr);
}

> * {
flex: 1;
max-width: 50%;
@media (max-width: 1278px) {
grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 767px) {
grid-template-columns: repeat(1, 1fr);
}

p {
Expand Down Expand Up @@ -52,32 +59,4 @@
display: flex;
justify-content: flex-end;
}

@media (min-width: 1920px) {
.job-openings-container {
grid-template-columns: repeat(3, 1fr);
> * {
flex: 1;
max-width: 33%;
}
}
}

@media (max-width: 767px) {
.job-openings-container {
align-content: flex-start;
grid-template-columns: 1fr;

> * {
display: inline-flex;
min-width: 100%;
}
}
}

.add-button {
position: fixed;
right: 4em;
top: 2em;
}
}
6 changes: 0 additions & 6 deletions packages/career/feature-admin/src/lib/forms/job-opening.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,4 @@ export class JobOpeningForm extends FormGroup<TypedForm<JobOpening>> {
}
}
}

logErrors() {
console.log(this.errors);
console.log(this.skills.errors);
console.log(this.skills.childrenErrors());
}
}
4 changes: 1 addition & 3 deletions packages/career/feature-admin/src/lib/forms/job-skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export class JobSkillForm extends FormGroup<TypedForm<JobSkill>> {

export class SkillsForm extends FormArray<JobSkillForm> {
constructor() {
super([], {
validators: [Validators.required],
});
super([]);
}

add(value?: EditableJobSkill) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<mat-card-title>{{ jobOpening.title }}</mat-card-title>
</mat-card-header>

<mat-list>
<mat-list class="job-opening-list">
@if (jobOpening.company) {
<mat-list-item>
<devmx-icon matListItemIcon name="building/building" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
@use '@angular/material' as mat;

:host {
display: flex;
flex-direction: column;
// max-width: calc(100vw - 2em);
width: 100%;
flex: 1;

.job-opening-card {
flex: 1;
display: flex;
flex-direction: column;

@include mat.elevation-transition();
@include mat.elevation(2);

&:active,
&:hover {
@include mat.elevation(6);
}

&-actions {
&:empty {
display: none;
}
.job-opening-list {
flex: 1;
}
}
}

0 comments on commit 4d2f78b

Please sign in to comment.