index.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React, { useCallback, forwardRef, useImperativeHandle } from 'react'
  21. import { Form, message } from 'antd'
  22. import BaseForm from './BaseForm'
  23. import AuthForm from './AuthForm'
  24. import { copyTextToClipboard } from '../utils'
  25. import { TCopyType, Tmode } from '../types'
  26. import { IProjectRoles } from 'containers/Organizations/component/ProjectRole'
  27. import { IOrganizationMember } from 'containers/Organizations/types'
  28. import { FormComponentProps } from 'antd/lib/form'
  29. import styles from '../SharePanel.less'
  30. interface IConfigFormProps extends FormComponentProps {
  31. mode: Tmode
  32. shareUrl: string
  33. password: string
  34. loading: boolean
  35. projectRoles: IProjectRoles[]
  36. organizationMembers: IOrganizationMember[]
  37. onSetRoles: (roles: number[]) => void
  38. onSetViewers: (viewers: number[]) => void
  39. onGetToken: () => void
  40. }
  41. const ConfigForm: React.FC<IConfigFormProps> = (
  42. {
  43. form,
  44. mode,
  45. shareUrl,
  46. loading,
  47. password,
  48. projectRoles,
  49. organizationMembers,
  50. onSetRoles,
  51. onSetViewers,
  52. onGetToken
  53. },
  54. ref
  55. ) => {
  56. useImperativeHandle(ref, () => ({ form }))
  57. const copy = useCallback(
  58. (copytype: TCopyType) => () => {
  59. const text =
  60. copytype === 'link' ? shareUrl : `链接:${shareUrl} 口令:${password}`
  61. copyTextToClipboard(
  62. text,
  63. () => message.success('复制链接成功'),
  64. () => message.warning('复制链接失败,请稍后重试')
  65. )
  66. },
  67. [shareUrl, password]
  68. )
  69. let content
  70. switch (mode) {
  71. case 'NORMAL':
  72. content = (
  73. <BaseForm
  74. form={form}
  75. shareUrl={shareUrl}
  76. loading={loading}
  77. onCopy={copy}
  78. onGetToken={onGetToken}
  79. />
  80. )
  81. break
  82. case 'PASSWORD':
  83. content = (
  84. <BaseForm
  85. form={form}
  86. shareUrl={shareUrl}
  87. password={password}
  88. loading={loading}
  89. onCopy={copy}
  90. onGetToken={onGetToken}
  91. />
  92. )
  93. break
  94. case 'AUTH':
  95. content = (
  96. <AuthForm
  97. form={form}
  98. projectRoles={projectRoles}
  99. organizationMembers={organizationMembers}
  100. shareUrl={shareUrl}
  101. loading={loading}
  102. onSetRoles={onSetRoles}
  103. onSetViewers={onSetViewers}
  104. onGetToken={onGetToken}
  105. onCopy={copy}
  106. />
  107. )
  108. break
  109. }
  110. return <Form className={styles.panelContent}>{content}</Form>
  111. }
  112. export default Form.create<IConfigFormProps>()(forwardRef(ConfigForm))