Improve the Progressable Button
This commit is contained in:
		
							parent
							
								
									2889c4ad76
								
							
						
					
					
						commit
						6e50cb6019
					
				
					 5 changed files with 31 additions and 10 deletions
				
			
		|  | @ -26,13 +26,13 @@ class ProgressableButton extends React.Component<ProgressableButtonProps, {}> { | ||||||
|     if (this.props.inProgress){ |     if (this.props.inProgress){ | ||||||
|       ourData.title = this.props.titleOnProgress || this.props.title |       ourData.title = this.props.titleOnProgress || this.props.title | ||||||
|       ourData.disabled = ourData.disabled || this.props.disableOnProgress |       ourData.disabled = ourData.disabled || this.props.disableOnProgress | ||||||
|       ourData.prefix = <i className='fa fa-spin fa-spinner'></i> |       ourData.prefix = <span><i className='fa fa-spin fa-spinner'></i> </span> | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     let props = _.omit(this.props, ['title', 'disableOnProgress', 'titleOnProgress', 'inProgress']) |     let props = _.omit(this.props, ['title', 'disableOnProgress', 'titleOnProgress', 'inProgress']) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     return <button {...props} className="button"  disabled={ourData.disabled}> |     return <button {...props} className="button" disabled={ourData.disabled}> | ||||||
|       <span>{ourData.prefix}{ourData.title}</span></button>; |       <span>{ourData.prefix}{ourData.title}</span></button>; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -6,6 +6,7 @@ import {Field, FieldDefinition} from "../../../../types/mobx-react-form"; | ||||||
| import {BasicField} from "../common/fields"; | import {BasicField} from "../common/fields"; | ||||||
| import {ThreeColumnFields, TwoColumnFields} from "../common/layout"; | import {ThreeColumnFields, TwoColumnFields} from "../common/layout"; | ||||||
| import {Validations} from "../../lib/vjf_rules"; | import {Validations} from "../../lib/vjf_rules"; | ||||||
|  | import ProgressableButton from "../common/ProgressableButton"; | ||||||
| 
 | 
 | ||||||
| export interface NonprofitInfoFormProps | export interface NonprofitInfoFormProps | ||||||
| { | { | ||||||
|  | @ -71,8 +72,7 @@ class NonprofitInfoForm extends React.Component<NonprofitInfoFormProps & Injecte | ||||||
|          <BasicField field={this.props.form.$('state')}/> |          <BasicField field={this.props.form.$('state')}/> | ||||||
|          <BasicField field={this.props.form.$('zip')}/> |          <BasicField field={this.props.form.$('zip')}/> | ||||||
|        </ThreeColumnFields> |        </ThreeColumnFields> | ||||||
|        <button onClick={this.props.form.onSubmit} className="button" disabled={!this.props.form.isValid || this.props.form.submitting}> |        <ProgressableButton onClick={this.props.form.onSubmit} className="button" disabled={!this.props.form.isValid} title={this.props.intl.formatMessage({id: this.props.buttonText})} inProgress={this.props.form.submitting || this.props.form.container().submitting} disableOnProgress={true}/> | ||||||
|          {this.props.intl.formatMessage({id: this.props.buttonText})}</button> |  | ||||||
|      </fieldset> |      </fieldset> | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -6,6 +6,8 @@ import {Validations} from "../../lib/vjf_rules"; | ||||||
| import {Field, FieldDefinition} from "mobx-react-form"; | import {Field, FieldDefinition} from "mobx-react-form"; | ||||||
| import {TwoColumnFields} from "../common/layout"; | import {TwoColumnFields} from "../common/layout"; | ||||||
| import {BasicField} from "../common/fields"; | import {BasicField} from "../common/fields"; | ||||||
|  | import ProgressableButton from "../common/ProgressableButton"; | ||||||
|  | import {areWeOrAnyParentSubmitting} from "../../lib/houdini_form"; | ||||||
| 
 | 
 | ||||||
| export const FieldDefinitions : Array<FieldDefinition> = [ | export const FieldDefinitions : Array<FieldDefinition> = [ | ||||||
|   { |   { | ||||||
|  | @ -53,9 +55,12 @@ class UserInfoForm extends React.Component<UserInfoFormProps & InjectedIntlProps | ||||||
|       <BasicField field={this.props.form.$('password_confirmation')}/> |       <BasicField field={this.props.form.$('password_confirmation')}/> | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|       <button onClick={this.props.form.onSubmit} className="button" disabled={!this.props.form.isValid || this.props.form.submitting}> |       <ProgressableButton onClick={this.props.form.onSubmit} | ||||||
|         {this.props.intl.formatMessage({id: this.props.buttonText})} |                           className="button" | ||||||
|       </button> |                           disabled={!this.props.form.isValid} | ||||||
|  |                           title={this.props.intl.formatMessage({id: this.props.buttonText})} | ||||||
|  |                           inProgress={areWeOrAnyParentSubmitting(this.props.form)} | ||||||
|  |                           disableOnProgress={true}/> | ||||||
|     </fieldset>; |     </fieldset>; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| // License: LGPL-3.0-or-later
 | // License: LGPL-3.0-or-later
 | ||||||
| import {Form} from "mobx-react-form"; | import {Field, Form} from "mobx-react-form"; | ||||||
| import {action, runInAction} from 'mobx' | import {action, runInAction} from 'mobx' | ||||||
| import validator = require("validator") | import validator = require("validator") | ||||||
| import * as _ from 'lodash' | import * as _ from 'lodash' | ||||||
|  | @ -17,6 +17,20 @@ export class HoudiniForm extends Form { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | export function areWeOrAnyParentSubmitting(f:Field|Form ) : boolean | ||||||
|  | { | ||||||
|  |   let currentItem: Field|Form = f | ||||||
|  |   let isSubmitting:boolean = f.submitting | ||||||
|  |   while (!isSubmitting && currentItem && !(currentItem instanceof Form)){ | ||||||
|  |     currentItem = currentItem.container() | ||||||
|  |     isSubmitting = currentItem.submitting | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return isSubmitting | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| interface PathToFormField { | interface PathToFormField { | ||||||
|   [props: string]: string |   [props: string]: string | ||||||
|  | @ -84,4 +98,6 @@ export class StaticFormToErrorAndBackConverter<T> { | ||||||
|       }) |       }) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								types/mobx-react-form/index.d.ts
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								types/mobx-react-form/index.d.ts
									
										
									
									
										vendored
									
									
								
							|  | @ -79,7 +79,7 @@ export declare class Field implements Base, FieldProperties, FieldMethods, Field | ||||||
| 
 | 
 | ||||||
|     clear(); |     clear(); | ||||||
| 
 | 
 | ||||||
|     container(): Form |     container(): Form |Field | ||||||
| 
 | 
 | ||||||
|     del(key: any); |     del(key: any); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Eric Schultz
						Eric Schultz