-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #485 from wmde/comment-validation
Add validation and error summary to comment form
- Loading branch information
Showing
6 changed files
with
207 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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,35 @@ | ||
import axios, { AxiosResponse } from 'axios'; | ||
|
||
export interface CommentRequest { | ||
donationId: number; | ||
updateToken: string; | ||
comment: string; | ||
withName: boolean; | ||
isPublic: boolean; | ||
} | ||
|
||
interface CommentResponse { | ||
status: string; | ||
message: string; | ||
} | ||
|
||
export interface CommentResource { | ||
post: ( data: CommentRequest ) => Promise<string>; | ||
} | ||
|
||
export class ApiCommentResource implements CommentResource { | ||
postEndpoint: string; | ||
|
||
constructor( postEndpoint: string ) { | ||
this.postEndpoint = postEndpoint; | ||
} | ||
|
||
post( data: CommentRequest ): Promise<string> { | ||
return axios.post( this.postEndpoint, data ).then( ( validationResult: AxiosResponse<CommentResponse> ) => { | ||
if ( validationResult.data.status !== 'OK' ) { | ||
return Promise.reject( validationResult.data.message ); | ||
} | ||
return validationResult.data.message; | ||
} ); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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,16 @@ | ||
import { CommentResource } from '@src/api/CommentResource'; | ||
|
||
export const successMessage = 'Success'; | ||
export const failureMessage = 'Fail'; | ||
|
||
export class FakeSucceedingCommentResource implements CommentResource { | ||
post(): Promise<string> { | ||
return Promise.resolve( successMessage ); | ||
} | ||
} | ||
|
||
export class FakeFailingCommentResource implements CommentResource { | ||
post(): Promise<string> { | ||
return Promise.reject( failureMessage ); | ||
} | ||
} |
This file contains 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
This file contains 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