|
| 1 | +<form |
| 2 | + id="comment-form" |
| 3 | + class="comment-form" |
| 4 | + (ngSubmit)="onSubmit($event)" |
| 5 | + #commentForm="ngForm" |
| 6 | +> |
| 7 | + <!-- Reply indication --> |
| 8 | + <div *ngIf="replyData" class="reply-to"> |
| 9 | + <div>Replying to <strong>{{ replyData.author }}</strong></div> |
| 10 | + </div> |
| 11 | + |
| 12 | + <!-- Loading state --> |
| 13 | + <div *ngIf="isSubmitting()" class="submitting-overlay"> |
| 14 | + <p>Submitting your comment...</p> |
| 15 | + </div> |
| 16 | + |
| 17 | + <!-- Error message --> |
| 18 | + <div *ngIf="formError()" class="error-message"> |
| 19 | + <p>{{ formError()?.message || "Error submitting comment" }}</p> |
| 20 | + <button type="button" (click)="clearError()" class="close-error">×</button> |
| 21 | + </div> |
| 22 | + |
| 23 | + <!-- Success message --> |
| 24 | + <div *ngIf="showSuccess()" class="success-message"> |
| 25 | + <p>Comment submitted successfully but waiting for approval!</p> |
| 26 | + </div> |
| 27 | + |
| 28 | + <!-- Author name --> |
| 29 | + <div class="form-group"> |
| 30 | + <label for="author">Name *</label> |
| 31 | + <input |
| 32 | + type="text" |
| 33 | + id="author" |
| 34 | + name="author" |
| 35 | + [(ngModel)]="formData.author" |
| 36 | + required |
| 37 | + maxlength="245" |
| 38 | + placeholder="Your name" |
| 39 | + [disabled]="isSubmitting()" |
| 40 | + #authorField="ngModel" |
| 41 | + /> |
| 42 | + <div |
| 43 | + *ngIf="authorField.invalid && commentForm.submitted && !isSubmitting()" |
| 44 | + class="field-error" |
| 45 | + > |
| 46 | + <span *ngIf="authorField.errors?.['required']">Name is required</span> |
| 47 | + <span *ngIf="authorField.errors?.['maxlength']" |
| 48 | + >Name must be less than 245 characters</span |
| 49 | + > |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + |
| 53 | + <!-- Author email --> |
| 54 | + <div class="form-group"> |
| 55 | + <label for="email">Email *</label> |
| 56 | + <input |
| 57 | + type="email" |
| 58 | + id="email" |
| 59 | + name="email" |
| 60 | + [(ngModel)]="formData.email" |
| 61 | + required |
| 62 | + maxlength="100" |
| 63 | + |
| 64 | + [disabled]="isSubmitting()" |
| 65 | + #emailField="ngModel" |
| 66 | + /> |
| 67 | + <div |
| 68 | + *ngIf="emailField.invalid && commentForm.submitted && !isSubmitting()" |
| 69 | + class="field-error" |
| 70 | + > |
| 71 | + <span *ngIf="emailField.errors?.['required']">Email is required</span> |
| 72 | + <span *ngIf="emailField.errors?.['email']" |
| 73 | + >Please enter a valid email</span |
| 74 | + > |
| 75 | + <span *ngIf="emailField.errors?.['maxlength']" |
| 76 | + >Email must be less than 100 characters</span |
| 77 | + > |
| 78 | + </div> |
| 79 | + </div> |
| 80 | + |
| 81 | + <!-- Author website (optional) --> |
| 82 | + <div class="form-group"> |
| 83 | + <label for="url">Website</label> |
| 84 | + <input |
| 85 | + type="url" |
| 86 | + id="url" |
| 87 | + name="url" |
| 88 | + [(ngModel)]="formData.url" |
| 89 | + maxlength="200" |
| 90 | + placeholder="https://yourwebsite.com" |
| 91 | + [disabled]="isSubmitting()" |
| 92 | + #urlField="ngModel" |
| 93 | + /> |
| 94 | + <div |
| 95 | + *ngIf="urlField.invalid && commentForm.submitted && !isSubmitting()" |
| 96 | + class="field-error" |
| 97 | + > |
| 98 | + <span *ngIf="urlField.errors?.['url']">Please enter a valid URL</span> |
| 99 | + <span *ngIf="urlField.errors?.['maxlength']" |
| 100 | + >URL must be less than 200 characters</span |
| 101 | + > |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + |
| 105 | + <!-- Comment content --> |
| 106 | + <div class="form-group"> |
| 107 | + <label for="content">Comment *</label> |
| 108 | + <textarea |
| 109 | + id="content" |
| 110 | + name="content" |
| 111 | + [(ngModel)]="formData.content" |
| 112 | + required |
| 113 | + rows="6" |
| 114 | + placeholder="Write your comment here..." |
| 115 | + [disabled]="isSubmitting()" |
| 116 | + #contentField="ngModel" |
| 117 | + ></textarea> |
| 118 | + <div |
| 119 | + *ngIf="contentField.invalid && commentForm.submitted && !isSubmitting()" |
| 120 | + class="field-error" |
| 121 | + > |
| 122 | + <span *ngIf="contentField.errors?.['required']" |
| 123 | + >Comment content is required</span |
| 124 | + > |
| 125 | + </div> |
| 126 | + </div> |
| 127 | + |
| 128 | + <!-- Submit button --> |
| 129 | + <div class="form-actions text-center"> |
| 130 | + <button |
| 131 | + type="submit" |
| 132 | + [disabled]="commentForm.invalid || isSubmitting()" |
| 133 | + class="button button-primary submit-comment" |
| 134 | + > |
| 135 | + {{ |
| 136 | + isSubmitting() |
| 137 | + ? "Submitting..." |
| 138 | + : replyData |
| 139 | + ? "Post Reply" |
| 140 | + : "Post Comment" |
| 141 | + }} |
| 142 | + </button> |
| 143 | + |
| 144 | + <button |
| 145 | + *ngIf="replyData" |
| 146 | + type="button" |
| 147 | + (click)="onCancel()" |
| 148 | + class="button button-secondary cancel-comment" |
| 149 | + [disabled]="isSubmitting()" |
| 150 | + > |
| 151 | + Cancel Reply |
| 152 | + </button> |
| 153 | + </div> |
| 154 | +</form> |
0 commit comments