Add error handling for closed and draft surveys; update related interfaces
This commit is contained in:
@@ -249,7 +249,7 @@ export class ParticipatePage implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private friendlyError(
|
private friendlyError(
|
||||||
reason: 'invalid_token' | 'already_submitted' | 'survey_not_found'
|
reason: 'invalid_token' | 'already_submitted' | 'survey_not_found' | 'survey_closed' | 'survey_draft'
|
||||||
): string {
|
): string {
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case 'invalid_token':
|
case 'invalid_token':
|
||||||
@@ -258,6 +258,10 @@ export class ParticipatePage implements OnInit, OnDestroy {
|
|||||||
return 'You have already submitted a response for this survey. Each link can only be used once.';
|
return 'You have already submitted a response for this survey. Each link can only be used once.';
|
||||||
case 'survey_not_found':
|
case 'survey_not_found':
|
||||||
return 'The survey could not be found on the host. It may have been deleted.';
|
return 'The survey could not be found on the host. It may have been deleted.';
|
||||||
|
case 'survey_draft':
|
||||||
|
return 'This survey is not yet open for responses. Please try again later.';
|
||||||
|
case 'survey_closed':
|
||||||
|
return 'This survey is closed and no longer accepting responses.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,8 @@
|
|||||||
</ion-item>
|
</ion-item>
|
||||||
|
|
||||||
<div class="ion-margin-top button-row">
|
<div class="ion-margin-top button-row">
|
||||||
<ion-button *ngIf="!isHosting" expand="block" (click)="startHosting()">
|
<ion-button *ngIf="!isHosting" expand="block" (click)="startHosting()"
|
||||||
|
[disabled]="survey.status !== 'active'">
|
||||||
<ion-icon slot="start" name="play-outline"></ion-icon>
|
<ion-icon slot="start" name="play-outline"></ion-icon>
|
||||||
Start Hosting
|
Start Hosting
|
||||||
</ion-button>
|
</ion-button>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { ToastController, AlertController, Platform } from '@ionic/angular';
|
import { ToastController } from '@ionic/angular';
|
||||||
import { DataConnection } from 'peerjs';
|
import { DataConnection } from 'peerjs';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import { SurveyService } from '../../services/survey.service';
|
import { SurveyService } from '../../services/survey.service';
|
||||||
@@ -52,9 +52,7 @@ export class SurveyDetailPage implements OnInit, OnDestroy {
|
|||||||
private surveyService: SurveyService,
|
private surveyService: SurveyService,
|
||||||
private responseService: ResponseService,
|
private responseService: ResponseService,
|
||||||
private peerService: PeerService,
|
private peerService: PeerService,
|
||||||
private toastCtrl: ToastController,
|
private toastCtrl: ToastController
|
||||||
private alertCtrl: AlertController,
|
|
||||||
private platform: Platform
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
async ngOnInit(): Promise<void> {
|
||||||
@@ -228,6 +226,16 @@ export class SurveyDetailPage implements OnInit, OnDestroy {
|
|||||||
if (!this.survey) return;
|
if (!this.survey) return;
|
||||||
|
|
||||||
if (msg.type === 'join') {
|
if (msg.type === 'join') {
|
||||||
|
if (this.survey.status === 'draft') {
|
||||||
|
conn.send({ type: 'error', reason: 'survey_draft' } as P2PMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.survey.status === 'closed') {
|
||||||
|
conn.send({ type: 'error', reason: 'survey_closed' } as P2PMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const participant = await this.surveyService.getParticipant(msg.token);
|
const participant = await this.surveyService.getParticipant(msg.token);
|
||||||
|
|
||||||
if (!participant || participant.surveyId !== this.surveyId) {
|
if (!participant || participant.surveyId !== this.surveyId) {
|
||||||
|
|||||||
@@ -134,4 +134,4 @@ export type P2PMessage =
|
|||||||
/** Host acknowledges a successful submit or update */
|
/** Host acknowledges a successful submit or update */
|
||||||
| { type: 'ack'; status: 'submitted' | 'updated' }
|
| { type: 'ack'; status: 'submitted' | 'updated' }
|
||||||
/** Host signals an error — participant should display the reason */
|
/** Host signals an error — participant should display the reason */
|
||||||
| { type: 'error'; reason: 'invalid_token' | 'already_submitted' | 'survey_not_found' };
|
| { type: 'error'; reason: 'invalid_token' | 'already_submitted' | 'survey_not_found' | 'survey_closed' | 'survey_draft' };
|
||||||
|
|||||||
Reference in New Issue
Block a user