-
Notifications
You must be signed in to change notification settings - Fork 44
Offer join form #982 #1034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Offer join form #982 #1034
Changes from all commits
9463870
7ea2f41
a20fb14
2cf9d22
335f110
3fadfbc
ae38fa4
abed5df
ff16e0f
2175008
07bcc62
03dad83
059a338
2eaae9b
1a3f1cf
dcf8f2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| """ | ||
| .. module:: test_join | ||
| """ | ||
|
|
||
| from rest_framework import status | ||
| from rest_framework.test import APITestCase | ||
|
|
||
| from apps.volontulo.tests.views.offers.commons import TestOffersCommons | ||
|
|
||
|
|
||
| class TestAuthenticatedUserJoinOffer(TestOffersCommons, APITestCase): | ||
|
|
||
| """Tests for REST API's join offer view for authenticated user.""" | ||
|
|
||
| def setUp(self): | ||
| """Set up each test.""" | ||
| super(TestAuthenticatedUserJoinOffer, self).setUp() | ||
| self.client.login(username='admin@example.com', password='123admin') | ||
|
|
||
| def test_user_join_offer_authenticated(self): | ||
| """Test offer's created status for admin user.""" | ||
| response = self.client.post('/api/offers/1/join/') | ||
|
|
||
| self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
|
|
||
| def test_user_join_not_existing_offer(self): | ||
| """Test offer's 404 status for non existing offer.""" | ||
| response = self.client.post('/api/offers/1999999999999/join/') | ||
|
|
||
| self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) | ||
|
|
||
|
|
||
| class TestNotAuthenticatedUserJoinOffer(TestOffersCommons, APITestCase): | ||
|
|
||
| """Tests for REST API's join offer view for not authenitcated user""" | ||
|
|
||
| def test_user_join_offer_not_authenticated(self): | ||
| """Test offer's forbidden status for not logged in user.""" | ||
| response = self.client.post('/api/offers/1/join/') | ||
|
|
||
| self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <div class="container"> | ||
| <form [formGroup]="joinForm" (ngSubmit)="onSubmit()"> | ||
| <div class="form-group row"> | ||
| <label class="col-form-label" for="{{ email }}">Email:</label> | ||
| <div class="col-md-5"> | ||
| <input disabled class="form-control" formControlName="applicant_email" id="{{ email }}"/> | ||
| </div> | ||
| <label class="col-form-label" for="{{ fullname }}">Imię i nazwisko:</label> | ||
| <div class="col-md-5"> | ||
| <input disabled class="form-control" formControlName="applicant_name" id="{{ fullname }}"/> | ||
| </div> | ||
| </div> | ||
| <div class="form-group row"> | ||
| <label class="col-form-label" for="{{ phone }}">Telefon:</label> | ||
| <div class="col-md-5"> | ||
| <input disabled class="form-control" formControlName="phone_no"/> | ||
| </div> | ||
| </div> | ||
| <div class="form-group-row"> | ||
| <label class="col-md-3 col-form-label" for="{{ message }}">Możliwe uwagi:</label> | ||
| <div class="col-md-9"> | ||
| <textarea class="form-control" rows="3" formControlName="message"></textarea> | ||
| <volontulo-form-error [fc]="joinForm.controls.message" [minLength]="10" [maxLength]="2000"></volontulo-form-error> | ||
| </div> | ||
| </div> | ||
| <div class="form-group row"> | ||
| <div> | ||
| <button type="submit" class="btn-primary"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Wyślij | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </form> | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| 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 joinForm: FormGroup = this.fb.group({ | ||
| applicant_email: [''], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO camelCase will be better for TypeScript. |
||
| applicant_name: [''], | ||
| message: ['', [Validators.minLength(10), Validators.maxLength(2000)]], | ||
| phone_no: [''], | ||
| }); | ||
|
|
||
| public submitEnabled = false; | ||
| public success: null | boolean = null; | ||
| public offerId: number; | ||
| public error; | ||
|
|
||
| constructor( | ||
| private activatedRoute: ActivatedRoute, | ||
| private fb: FormBuilder, | ||
| private authService: AuthService, | ||
| private userService: UserService, | ||
| private httpClient: HttpClient, | ||
| private offersService: OffersService, | ||
| private location: Location , | ||
| ) { | ||
| } | ||
|
|
||
| ngOnInit() { | ||
| this.authService.user$ | ||
| .subscribe( | ||
| (user: User) => { | ||
| this.joinForm.controls.applicant_email.setValue(user.email); | ||
| this.joinForm.controls.applicant_name.setValue(this.userService.getFullName(user)); | ||
| this.joinForm.controls.phone_no.setValue(user.phoneNo); | ||
| } | ||
| ); | ||
|
|
||
| this.activatedRoute.params | ||
| .switchMap(params => this.offerId = params.offerId) | ||
| .subscribe() | ||
| } | ||
|
|
||
| onSubmit() { | ||
| if (this.joinForm.valid) { | ||
| this.submitEnabled = true; | ||
|
|
||
| this.offersService.joinOffer(this.offerId, this.joinForm.value.message).subscribe( | ||
| response => { | ||
| if (response.status === 201) { | ||
| this.location.back()}} | ||
| ) | ||
| } | ||
| } | ||
| } | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You use {{ }} to bind to
emailvariable, that is not defined in the component, so as a result, you get empty for attributes in HTML (same problem for all other labels). Define them just using strings, and if you defineforattribute in alabeldon't forget to defineid' ininput`, so focus can be set after clicking on label.