forked from doubtfire-lms/doubtfire-web
-
Notifications
You must be signed in to change notification settings - Fork 137
Feature: Grant Extension Form #285
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
20b07c0
feat: add Grant Extension form component
JoeMacl 7c338a6
feat: updated grant extension form with validation and styling
JoeMacl 570433a
feat: update progress on grant extension form
JoeMacl b3b5f97
style: improve modal responsiveness and log form submission
JoeMacl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/app/admin/modals/grant-extension-form/grant-extension-form.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <div class="mx-auto max-w-3xl p-8 bg-white rounded-md shadow-md"> | ||
| <h2 class="text-3xl font-bold text-gray-900 mb-10">Grant Extension</h2> | ||
|
|
||
| <form [formGroup]="grantExtensionForm" (ngSubmit)="onSubmit()" class="space-y-8"> | ||
|
|
||
| <!-- Student --> | ||
| <div> | ||
| <label class="block text-lg font-semibold text-gray-800 mb-2" for="student">Student</label> | ||
| <select | ||
| id="student" | ||
| formControlName="student" | ||
| class="w-full border border-gray-300 rounded-md px-4 py-3 text-base focus:ring-2 focus:ring-blue-500 focus:outline-none" | ||
| required | ||
| > | ||
| <option value="" disabled>Select a student</option> | ||
| <option *ngFor="let student of students" [value]="student.id"> | ||
| {{ student.name }} | ||
| </option> | ||
| </select> | ||
| <!-- Error if not selected --> | ||
| <div *ngIf="grantExtensionForm.get('student')?.touched && grantExtensionForm.get('student')?.invalid" class="text-red-600 text-sm mt-2"> | ||
| Please select a student. | ||
| </div> | ||
|
|
||
| <!-- Extension --> | ||
| <div> | ||
| <label for="extension" class="block text-lg font-semibold text-gray-800 mb-2"> | ||
| Extension Duration: | ||
| <span class="font-bold">{{ grantExtensionForm.get('extension')?.value }}</span> day(s) | ||
| </label> | ||
| <input id="extension" type="range" formControlName="extension" min="1" max="30" class="w-full" /> | ||
| </div> | ||
|
|
||
| <!-- Reason --> | ||
| <div> | ||
| <label for="reason" class="block text-lg font-semibold text-gray-800 mb-2">Reason</label> | ||
| <textarea | ||
| id="reason" | ||
| formControlName="reason" | ||
| rows="4" | ||
| class="w-full border border-gray-300 rounded-md px-4 py-3 text-base focus:ring-2 focus:ring-blue-500 focus:outline-none" | ||
| required | ||
| ></textarea> | ||
| <!-- Error if empty --> | ||
| <div *ngIf="grantExtensionForm.get('reason')?.touched && grantExtensionForm.get('reason')?.invalid" class="text-red-600 text-sm mt-2"> | ||
| Please provide a reason for the extension. | ||
| </div> | ||
|
|
||
| <!-- Notes --> | ||
| <div> | ||
| <label for="notes" class="block text-lg font-semibold text-gray-800 mb-2">Additional Notes (optional)</label> | ||
| <textarea | ||
| id="notes" | ||
| formControlName="notes" | ||
| rows="3" | ||
| class="w-full border border-gray-300 rounded-md px-4 py-3 text-base focus:ring-2 focus:ring-blue-500 focus:outline-none" | ||
| ></textarea> | ||
| </div> | ||
|
|
||
| <!-- Submit --> | ||
| <div class="pt-4 text-right"> | ||
| <button | ||
JoeMacl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| type="submit" | ||
| [disabled]="isSubmitting" | ||
| [ngClass]="{ | ||
| 'bg-blue-700 cursor-not-allowed opacity-70': isSubmitting, | ||
| 'bg-blue-600 hover:bg-blue-700': !isSubmitting | ||
| }" | ||
| class="inline-flex items-center text-white text-lg font-medium px-6 py-3 rounded-md transition" | ||
| > | ||
| Grant Extension | ||
| </button> | ||
| </div> | ||
Empty file.
22 changes: 22 additions & 0 deletions
22
src/app/admin/modals/grant-extension-form/grant-extension-form.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
| import { GrantExtensionFormComponent } from './grant-extension-form.component'; | ||
|
|
||
| describe('GrantExtensionFormComponent', () => { | ||
| let component: GrantExtensionFormComponent; | ||
| let fixture: ComponentFixture<GrantExtensionFormComponent>; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| imports: [GrantExtensionFormComponent] | ||
| }) | ||
| .compileComponents(); | ||
|
|
||
| fixture = TestBed.createComponent(GrantExtensionFormComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
JoeMacl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
| }); | ||
59 changes: 59 additions & 0 deletions
59
src/app/admin/modals/grant-extension-form/grant-extension-form.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import {Component, OnInit} from '@angular/core'; | ||
| import {FormGroup, FormBuilder, Validators, ReactiveFormsModule} from '@angular/forms'; | ||
| import {CommonModule} from '@angular/common'; | ||
|
|
||
JoeMacl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Component({ | ||
| selector: 'f-grant-extension-form', | ||
| standalone: true, | ||
| imports: [ReactiveFormsModule, CommonModule], | ||
| templateUrl: './grant-extension-form.component.html', | ||
| styleUrls: ['./grant-extension-form.component.scss'] | ||
| }) | ||
| export class GrantExtensionFormComponent implements OnInit { | ||
| grantExtensionForm!: FormGroup; | ||
| // Tracks if the form is currently submitting | ||
| isSubmitting = false; | ||
| // Test list of students (to be replaced by API data) | ||
| students = [ | ||
| { id: 1, name: 'Joe M' }, | ||
| { id: 2, name: 'Sahiru W' }, | ||
| { id: 3, name: 'Samindi M' } | ||
| ]; | ||
|
|
||
| constructor(private fb: FormBuilder) {} | ||
|
|
||
| ngOnInit(): void { | ||
| // Initialize the form and apply validators to required fields | ||
| this.grantExtensionForm = this.fb.group({ | ||
| student: ['', Validators.required], // Student must be selected | ||
| extension: [1, [Validators.required, Validators.min(1)]], // Minimum value of 1 | ||
| reason: ['', Validators.required], // Must provide reason | ||
| notes: [''], | ||
| }); | ||
| } | ||
|
|
||
| onSubmit(): void { | ||
| // If form is invalid. Validation errors are shown | ||
| if (this.grantExtensionForm.invalid) { | ||
| this.grantExtensionForm.markAllAsTouched(); // Triggers validation messages | ||
| return; | ||
| } | ||
|
|
||
| this.isSubmitting = true; // Disables the button for loading state | ||
|
|
||
| // Submission delay test | ||
| setTimeout(() => { | ||
| console.log('Form submitted:', this.grantExtensionForm.value); | ||
|
|
||
| // Resets form values | ||
| this.grantExtensionForm.reset({ | ||
| student: '', | ||
| extension: 1, | ||
| reason: '', | ||
| notes: '' | ||
| }); | ||
| // Reset the submit button | ||
| this.isSubmitting = false; | ||
| }, 1000); // Delay for submission | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.