diff --git a/src/app/shell/personal-cabinet/provider/create-competition/create-required-form/create-required-form.component.ts b/src/app/shell/personal-cabinet/provider/create-competition/create-required-form/create-required-form.component.ts
index 26526020c..094b29404 100644
--- a/src/app/shell/personal-cabinet/provider/create-competition/create-required-form/create-required-form.component.ts
+++ b/src/app/shell/personal-cabinet/provider/create-competition/create-required-form/create-required-form.component.ts
@@ -19,6 +19,7 @@ import { Subject } from 'rxjs';
})
export class CreateRequiredFormComponent implements OnInit, OnDestroy {
@Input() public competition: Competition;
+ @Input() public parentCompetition: string;
@Input() public provider: Provider;
@Input() public isImagesFeature: boolean;
@Output() public PassRequiredFormGroup = new EventEmitter();
@@ -29,8 +30,8 @@ export class CreateRequiredFormComponent implements OnInit, OnDestroy {
public readonly TypeOfCompetitionEnum = TypeOfCompetitionEnum;
public readonly mailFormPlaceholder = Constants.MAIL_FORMAT_PLACEHOLDER;
- protected startDate: Date = new Date();
- protected endDate: Date = new Date(new Date().setFullYear(new Date().getFullYear() + 1));
+ protected minDate: Date = new Date(new Date().setMonth(new Date().getMonth() - 1));
+ protected maxDate: Date = new Date(new Date().setFullYear(new Date().getFullYear() + 1));
protected readonly TypeOfCompetition = TypeOfCompetition;
protected readonly InfoMenuType = InfoMenuType;
protected readonly ownershipType = OwnershipTypes;
@@ -49,6 +50,7 @@ export class CreateRequiredFormComponent implements OnInit, OnDestroy {
public isShowHintAboutCompetitionAutoClosing: boolean = false;
public availableSeatsRadioBtnControl: FormControl = new FormControl(true);
public useProviderInfoCtrl: FormControl = new FormControl(false);
+ public filteredTypeOfCompetition: { key: string; value: string }[] = [];
private destroy$: Subject = new Subject();
private minimumSeats: number = 1;
@@ -63,10 +65,6 @@ export class CreateRequiredFormComponent implements OnInit, OnDestroy {
return this.RequiredFormGroup.get('typeOfCompetition') as FormControl;
}
- public get parentCompetitionControl(): FormControl {
- return this.RequiredFormGroup.get('parentCompetitionControl') as FormControl;
- }
-
public get minSeats(): number {
if (this.competition?.takenSeats === 0 || !this.competition) {
return this.minimumSeats;
@@ -80,9 +78,26 @@ export class CreateRequiredFormComponent implements OnInit, OnDestroy {
: this.competition?.availableSeats;
}
+ private filterTypeOfCompetition(stage?: boolean): void {
+ this.filteredTypeOfCompetition = Object.entries(TypeOfCompetition)
+ .filter(([key]) => stage || key !== 'CompetitionStage')
+ .map(([key, value]) => ({ key, value }));
+ }
+
public ngOnInit(): void {
this.initForm();
this.PassRequiredFormGroup.emit(this.RequiredFormGroup);
+
+ this.filterTypeOfCompetition(Boolean(this.parentCompetition));
+
+ if (this.competition) {
+ this.activateEditMode();
+ }
+ if (this.parentCompetition) {
+ this.typeOfCompetitionControl.setValue(TypeOfCompetition.CompetitionStage);
+ this.typeOfCompetitionControl.disable();
+ }
+
this.initListeners();
}
@@ -104,6 +119,43 @@ export class CreateRequiredFormComponent implements OnInit, OnDestroy {
return 0;
}
+ /**
+ * This method fills inputs with information of edited workshop
+ */
+ public activateEditMode(): void {
+ this.RequiredFormGroup.patchValue(this.competition, { emitEvent: false });
+ if (this.competition.startDate) {
+ this.minDate = new Date(new Date(this.competition.startDate).setMonth(new Date(this.competition.startDate).getMonth() - 1));
+ }
+
+ if (this.competition.startDate && this.competition.endDate) {
+ this.RequiredFormGroup.get('competitionDateRangeGroup')?.patchValue({
+ start: this.competition.startDate,
+ end: this.competition.endDate
+ });
+
+ this.RequiredFormGroup.get('competitionDateRangeGroup')?.get('start')?.markAsTouched();
+ this.RequiredFormGroup.get('competitionDateRangeGroup')?.get('end')?.markAsTouched();
+ }
+
+ if (this.competition.regStartDate && this.competition.regEndDate) {
+ this.RequiredFormGroup.get('registrationDateRangeGroup')?.patchValue({
+ start: this.competition.regStartDate,
+ end: this.competition.regEndDate
+ });
+
+ this.RequiredFormGroup.get('registrationDateRangeGroup')?.get('start')?.markAsTouched();
+ this.RequiredFormGroup.get('registrationDateRangeGroup')?.get('end')?.markAsTouched();
+ }
+
+ if (this.competition.availableSeats === this.UNLIMITED_SEATS) {
+ this.setAvailableSeatsControlValue(null, 'disable', false);
+ } else {
+ this.setAvailableSeatsControlValue(this.availableSeats, 'enable', false);
+ this.availableSeatsRadioBtnControl.setValue(false);
+ }
+ }
+
private initForm(): void {
this.RequiredFormGroup = this.formBuilder.group({
image: new FormControl(''),
diff --git a/src/app/shell/shell-routing.module.ts b/src/app/shell/shell-routing.module.ts
index 4d9ab735d..09990323f 100644
--- a/src/app/shell/shell-routing.module.ts
+++ b/src/app/shell/shell-routing.module.ts
@@ -177,6 +177,13 @@ const routes: Routes = [
canLoad: [ProviderGuard],
canDeactivate: [CreateGuard]
},
+ {
+ path: 'create-competition/:id/:param',
+ component: CreateCompetitionComponent,
+ loadChildren: () => import('./personal-cabinet/provider/provider.module').then((m) => m.ProviderModule),
+ canLoad: [ProviderGuard],
+ canDeactivate: [CreateGuard]
+ },
{ path: '**', component: ErrorPageComponent }
];