Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -167,6 +168,11 @@ const appRoutes: Routes = [
component: UserProfileComponent,
canActivate: [LoggedInGuard],
},
{
path: 'offers/:offerSlug/:offerId/join',
component: OfferJoinFormComponent,
canActivate: [LoggedInGuard],
},
{
path: '**',
component: RedirectComponent
Expand Down Expand Up @@ -213,7 +219,8 @@ registerLocaleData(localePl);
ContactComponent,
FormErrorComponent,
OrganizationsListComponent,
UserProfileComponent
UserProfileComponent,
OfferJoinFormComponent,
],
imports: [
BrowserModule.withServerTransition({ appId: 'volontulo' }),
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/homepage-offer/offers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h2>Pomagasz już w tej inicjatywie</h2>
<div class="alert alert-danger">
<h2>Możesz pomóc?</h2>
<p>Twoja pomoc jest ważna. Potrzebujemy Ciebie!</p>
<a class="btn btn-light" href="{{ getJoinViewUrl(offer) }}"
<a [routerLink]="['/offers', offer.slug, offer.id,'join']" class="btn btn-light"
>Zgłoś się na ten wolontariat</a>
</div>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div class="container">
<form [formGroup]="joinForm" (ngSubmit)="onSubmit()">
<div class="form-group row">
<label class="col-sm-4 col-md-3 col-lg-2 col-form-label" for="fullname">Imię i nazwisko:</label>
<div class="col-sm-8 col-md-9 col-lg-10">
<input class="form-control" formControlName="applicantName" id="fullname"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-md-3 col-lg-2 col-form-label" for="email">Email:</label>
<div class="col-sm-8 col-md-9 col-lg-10">
<input class="form-control" formControlName="applicantEmail" id="email"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-md-3 col-lg-2 col-form-label" for="phone">Telefon:</label>
<div class="col-sm-8 col-md-9 col-lg-10">
<input class="form-control" formControlName="phoneNo" id="phone" [imask]="{mask: '+48 000-000-000'}"/>
</div>
</div>
<div>
<label for="message">Możliwe uwagi:</label>
<textarea type="text" class="form-control" rows="3" id="message" placeholder="{{ communicate }}" formControlName="message"></textarea>
<volontulo-form-error [fc]="joinForm.controls.message" [minLength]="10" [maxLength]="2000"></volontulo-form-error>
</div>
<div class="form-group row d-none">
<label class="col-sm-4 col-md-3 col-lg-2 col-form-label">Bot trap</label>
<div class="col-sm-8 col-md-9 col-lg-10">
<input type="text" class="form-control" formControlName="honeyValue" />
</div>
</div>
<div class="d-flex justify-content-center p-3">
<button type="submit" name="submit" class="btn btn-primary" [disabled]="joinForm.invalid && submitEnabled">
Zgłaszam się do pomocy
</button>
</div>
</form>
</div>

Original file line number Diff line number Diff line change
@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that the type of this variable is HttpRequestError or smth like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. I haven't put it there. IDE did it itself when I used this expresson
err => this.error = err.error.nonFieldErrors

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
)
}
}
}