diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 034f3e26..2ca31e1c 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -56,6 +56,7 @@ import { ContactService } from './contact.service'; import { UserProfileComponent } from './user-profile/user-profile.component'; import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; import { IMaskModule } from 'angular-imask'; +import { OfferJoinFormComponent } from './offers/offer-join-form/offer-join-form.component'; Raven.config(environment.sentryDSN).install(); @@ -167,6 +168,11 @@ const appRoutes: Routes = [ component: UserProfileComponent, canActivate: [LoggedInGuard], }, + { + path: 'offers/:offerSlug/:offerId/join', + component: OfferJoinFormComponent, + canActivate: [LoggedInGuard], + }, { path: '**', component: RedirectComponent @@ -213,7 +219,8 @@ registerLocaleData(localePl); ContactComponent, FormErrorComponent, OrganizationsListComponent, - UserProfileComponent + UserProfileComponent, + OfferJoinFormComponent, ], imports: [ BrowserModule.withServerTransition({ appId: 'volontulo' }), diff --git a/frontend/src/app/homepage-offer/offers.service.ts b/frontend/src/app/homepage-offer/offers.service.ts index 5a506a6d..37b9bc04 100644 --- a/frontend/src/app/homepage-offer/offers.service.ts +++ b/frontend/src/app/homepage-offer/offers.service.ts @@ -35,4 +35,8 @@ export class OffersService { return this.http.put(`${environment.apiRoot}/offers/${id}/`, offer); } + joinOffer(id: number, message: string) { + return this.http.post(`${environment.apiRoot}/offers/${id}/join/`, {message}, {observe: 'response'}); + } + } diff --git a/frontend/src/app/offers/offer-detail/offer-detail.component.html b/frontend/src/app/offers/offer-detail/offer-detail.component.html index 51e2d40c..348d424b 100644 --- a/frontend/src/app/offers/offer-detail/offer-detail.component.html +++ b/frontend/src/app/offers/offer-detail/offer-detail.component.html @@ -68,7 +68,7 @@

Pomagasz już w tej inicjatywie

Możesz pomóc?

Twoja pomoc jest ważna. Potrzebujemy Ciebie!

- Zgłoś się na ten wolontariat
diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.html b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html new file mode 100644 index 00000000..6434bb14 --- /dev/null +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html @@ -0,0 +1,39 @@ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ + + +
+
+ +
+ +
+
+
+ +
+
+
+ diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts new file mode 100644 index 00000000..e9b7b7a6 --- /dev/null +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts @@ -0,0 +1,68 @@ +import { Component, OnInit } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { HttpClient } from '@angular/common/http'; +import { Location } from '@angular/common' + +import { ActivatedRoute } from '@angular/router'; +import { AuthService } from '../../auth.service'; +import { OffersService } from 'app/homepage-offer/offers.service'; +import { User } from '../../user'; +import { UserService } from '../../user.service'; + +@Component({ + selector: 'volontulo-offer-join-form', + templateUrl: './offer-join-form.component.html' +}) + +export class OfferJoinFormComponent implements OnInit { + public error; + public communicate = 'Dodatkowe informacje dla organizatora (pole nieobowiązkowe)'; + public joinForm: FormGroup = this.fb.group({ + applicantEmail: [{value: '', disabled: true}], + applicantName: [{value: '', disabled: true}], + message: ['', [Validators.minLength(10), Validators.maxLength(2000)]], + phoneNo: [{value: '', disabled: true}], + honeyValue: [''], + }); + public offerId: number; + public submitEnabled = true; + + constructor( + private activatedRoute: ActivatedRoute, + private authService: AuthService, + private fb: FormBuilder, + private httpClient: HttpClient, + private location: Location, + private offersService: OffersService, + private userService: UserService, + ) { + } + + ngOnInit() { + this.authService.user$ + .subscribe( + (user: User) => { + this.joinForm.controls.applicantEmail.setValue(user.email); + this.joinForm.controls.applicantName.setValue(this.userService.getFullName(user)); + this.joinForm.controls.phoneNo.setValue(user.phoneNo); + } + ); + + this.activatedRoute.params + .switchMap(params => this.offerId = params.offerId) + .subscribe() + } + + onSubmit() { + if (this.joinForm.valid && !this.joinForm.value.honeyValue) { + this.submitEnabled = false; + + this.offersService.joinOffer(this.offerId, this.joinForm.value.message).subscribe( + response => { + if (response.status === 201) { + this.location.back()}}, + err => this.error = err.error.nonFieldErrors + ) + } + } +}