Setting.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import React from 'react'
  2. const styles = require('../Organization.less')
  3. import { Button, Input, Form, Row, Col, Radio, Modal } from 'antd'
  4. import {FormComponentProps} from 'antd/lib/form'
  5. const FormItem = Form.Item
  6. const RadioButton = Radio.Button
  7. import UploadAvatar from 'components/UploadAvatar'
  8. import { IOrganization } from '../types'
  9. const utilStyles = require('assets/less/util.less')
  10. interface ISettingProps {
  11. form: any
  12. currentOrganization: IOrganization
  13. editOrganization: (oranization: IOrganization) => () => any
  14. deleteOrganization: (id: number) => any
  15. }
  16. export class Setting extends React.PureComponent <ISettingProps> {
  17. public componentWillMount () {
  18. this.initData()
  19. }
  20. private initData = () => {
  21. const { currentOrganization } = this.props
  22. const {
  23. id,
  24. name,
  25. description,
  26. allowCreateProject,
  27. allowDeleteOrTransferProject,
  28. allowChangeVisibility,
  29. memberPermission
  30. } = currentOrganization
  31. this.forceUpdate(() => {
  32. this.props.form.setFieldsValue({
  33. id,
  34. name,
  35. description,
  36. allowCreateProject,
  37. allowDeleteOrTransferProject,
  38. allowChangeVisibility,
  39. memberPermission
  40. })
  41. })
  42. }
  43. private confirmDelete = () => {
  44. const { form, deleteOrganization } = this.props
  45. const { id, name } = form.getFieldsValue()
  46. Modal.confirm({
  47. title: `确定删除组织 “${name}”?`,
  48. onOk: () => {
  49. deleteOrganization(id)
  50. }
  51. })
  52. }
  53. public render () {
  54. const { getFieldDecorator } = this.props.form
  55. const commonFormItemStyle = {
  56. labelCol: { span: 2 },
  57. wrapperCol: { span: 18 }
  58. }
  59. const { name, avatar, id, description, allowCreateProject, memberPermission } = this.props.currentOrganization
  60. const currentValues = this.props.form.getFieldsValue()
  61. let isDisabled = true
  62. if (currentValues.name !== name
  63. || currentValues.description !== description
  64. || currentValues.allowCreateProject !== allowCreateProject
  65. || currentValues.memberPermission !== memberPermission
  66. ) {
  67. isDisabled = false
  68. }
  69. return (
  70. <div className={styles.listWrapper}>
  71. <div className={styles.container}>
  72. <UploadAvatar type="organization" path={avatar} xhrParams={{id}} />
  73. <hr/>
  74. <div className={styles.form}>
  75. <Form>
  76. <Row>
  77. <Col>
  78. <FormItem className={utilStyles.hide}>
  79. {getFieldDecorator('id', {})(
  80. <Input />
  81. )}
  82. </FormItem>
  83. <FormItem
  84. {...commonFormItemStyle}
  85. label="名称"
  86. >
  87. {getFieldDecorator('name', {
  88. initialValue: '',
  89. rules: [{ required: true }, {
  90. // validator: this.checkNameUnique
  91. }]
  92. })(
  93. <Input placeholder="名称"/>
  94. )}
  95. </FormItem>
  96. </Col>
  97. <Col>
  98. <FormItem
  99. {...commonFormItemStyle}
  100. label="描述"
  101. >
  102. {getFieldDecorator('description', {
  103. })(
  104. <Input placeholder="描述" />
  105. )}
  106. </FormItem>
  107. </Col>
  108. </Row>
  109. <Row className={styles.permissionZone}>
  110. <Col>
  111. <FormItem
  112. label="组织成员创建项目"
  113. >
  114. {getFieldDecorator('allowCreateProject', {
  115. initialValue: true
  116. })(
  117. <Radio.Group size="small">
  118. <RadioButton value={false}>禁止</RadioButton>
  119. <RadioButton value={true}>允许</RadioButton>
  120. </Radio.Group>
  121. )}
  122. </FormItem>
  123. </Col>
  124. <Col>
  125. <FormItem
  126. // {...commonFormItemStyle}
  127. label="组织成员对项目的权限"
  128. >
  129. {getFieldDecorator('memberPermission', {
  130. initialValue: 1
  131. })(
  132. <Radio.Group size="small">
  133. <RadioButton value={0}>不可见任何</RadioButton>
  134. <RadioButton value={1}>只可见公开</RadioButton>
  135. </Radio.Group>
  136. )}
  137. </FormItem>
  138. </Col>
  139. <Col>
  140. <Button
  141. onClick={this.props.editOrganization(this.props.form.getFieldsValue())}
  142. disabled={isDisabled}
  143. >
  144. 保存修改
  145. </Button>
  146. </Col>
  147. </Row>
  148. <Row className={styles.dangerZone}>
  149. <div className={styles.title}>
  150. 删除组织
  151. </div>
  152. <div className={styles.titleDesc}>
  153. <p className={styles.desc}>删除后无法恢复,请确定此次操作</p>
  154. <p className={styles.button}>
  155. <Button type="danger" onClick={this.confirmDelete}>删除{name}</Button>
  156. </p>
  157. </div>
  158. </Row>
  159. </Form>
  160. </div>
  161. </div>
  162. </div>
  163. )
  164. }
  165. }
  166. export default Form.create<ISettingProps & FormComponentProps>()(Setting)