AdminAppContainer.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. import { Container } from 'unstated';
  2. /**
  3. * Service container for admin app setting page (AppSettings.jsx)
  4. * @extends {Container} unstated Container
  5. */
  6. export default class AdminAppContainer extends Container {
  7. constructor(appContainer) {
  8. super();
  9. this.appContainer = appContainer;
  10. this.dummyTitle = 0;
  11. this.dummyTitleForError = 1;
  12. this.state = {
  13. retrieveError: null,
  14. // set dummy value tile for using suspense
  15. title: this.dummyTitle,
  16. confidential: '',
  17. globalLang: '',
  18. fileUpload: '',
  19. siteUrl: '',
  20. envSiteUrl: '',
  21. isSetSiteUrl: true,
  22. fromAddress: '',
  23. smtpHost: '',
  24. smtpPort: '',
  25. smtpUser: '',
  26. smtpPassword: '',
  27. gcsApiKeyJsonPath: '',
  28. envGcsApiKeyJsonPath: '',
  29. gcsBucket: '',
  30. envGcsBucket: '',
  31. gcsUploadNamespace: '',
  32. envGcsUploadNamespace: '',
  33. region: '',
  34. customEndpoint: '',
  35. bucket: '',
  36. accessKeyId: '',
  37. secretAccessKey: '',
  38. isEnabledPlugins: true,
  39. };
  40. this.changeTitle = this.changeTitle.bind(this);
  41. this.changeConfidential = this.changeConfidential.bind(this);
  42. this.changeGlobalLang = this.changeGlobalLang.bind(this);
  43. this.changeFileUpload = this.changeFileUpload.bind(this);
  44. this.changeSiteUrl = this.changeSiteUrl.bind(this);
  45. this.changeFromAddress = this.changeFromAddress.bind(this);
  46. this.changeSmtpHost = this.changeSmtpHost.bind(this);
  47. this.changeSmtpPort = this.changeSmtpPort.bind(this);
  48. this.changeSmtpUser = this.changeSmtpUser.bind(this);
  49. this.changeSmtpPassword = this.changeSmtpPassword.bind(this);
  50. this.changeRegion = this.changeRegion.bind(this);
  51. this.changeCustomEndpoint = this.changeCustomEndpoint.bind(this);
  52. this.changeBucket = this.changeBucket.bind(this);
  53. this.changeAccessKeyId = this.changeAccessKeyId.bind(this);
  54. this.changeSecretAccessKey = this.changeSecretAccessKey.bind(this);
  55. this.changeIsEnabledPlugins = this.changeIsEnabledPlugins.bind(this);
  56. this.updateAppSettingHandler = this.updateAppSettingHandler.bind(this);
  57. this.updateSiteUrlSettingHandler = this.updateSiteUrlSettingHandler.bind(this);
  58. this.updateMailSettingHandler = this.updateMailSettingHandler.bind(this);
  59. this.updateAwsSettingHandler = this.updateAwsSettingHandler.bind(this);
  60. this.updatePluginSettingHandler = this.updatePluginSettingHandler.bind(this);
  61. }
  62. /**
  63. * Workaround for the mangling in production build to break constructor.name
  64. */
  65. static getClassName() {
  66. return 'AdminAppContainer';
  67. }
  68. /**
  69. * retrieve app sttings data
  70. */
  71. async retrieveAppSettingsData() {
  72. const response = await this.appContainer.apiv3.get('/app-settings/');
  73. const { appSettingsParams } = response.data;
  74. this.setState({
  75. title: appSettingsParams.title,
  76. confidential: appSettingsParams.confidential,
  77. globalLang: appSettingsParams.globalLang,
  78. fileUpload: appSettingsParams.fileUpload,
  79. siteUrl: appSettingsParams.siteUrl,
  80. envSiteUrl: appSettingsParams.envSiteUrl,
  81. isSetSiteUrl: !!appSettingsParams.siteUrl,
  82. fromAddress: appSettingsParams.fromAddress,
  83. smtpHost: appSettingsParams.smtpHost,
  84. smtpPort: appSettingsParams.smtpPort,
  85. smtpUser: appSettingsParams.smtpUser,
  86. smtpPassword: appSettingsParams.smtpPassword,
  87. region: appSettingsParams.region,
  88. customEndpoint: appSettingsParams.customEndpoint,
  89. bucket: appSettingsParams.bucket,
  90. accessKeyId: appSettingsParams.accessKeyId,
  91. secretAccessKey: appSettingsParams.secretAccessKey,
  92. isEnabledPlugins: appSettingsParams.isEnabledPlugins,
  93. });
  94. }
  95. /**
  96. * Change title
  97. */
  98. changeTitle(title) {
  99. this.setState({ title });
  100. }
  101. /**
  102. * Change confidential
  103. */
  104. changeConfidential(confidential) {
  105. this.setState({ confidential });
  106. }
  107. /**
  108. * Change globalLang
  109. */
  110. changeGlobalLang(globalLang) {
  111. this.setState({ globalLang });
  112. }
  113. /**
  114. * Change fileUpload
  115. */
  116. changeFileUpload(fileUpload) {
  117. this.setState({ fileUpload });
  118. }
  119. /**
  120. * Change site url
  121. */
  122. changeSiteUrl(siteUrl) {
  123. this.setState({ siteUrl });
  124. }
  125. /**
  126. * Change from address
  127. */
  128. changeFromAddress(fromAddress) {
  129. this.setState({ fromAddress });
  130. }
  131. /**
  132. * Change smtp host
  133. */
  134. changeSmtpHost(smtpHost) {
  135. this.setState({ smtpHost });
  136. }
  137. /**
  138. * Change smtp port
  139. */
  140. changeSmtpPort(smtpPort) {
  141. this.setState({ smtpPort });
  142. }
  143. /**
  144. * Change smtp user
  145. */
  146. changeSmtpUser(smtpUser) {
  147. this.setState({ smtpUser });
  148. }
  149. /**
  150. * Change smtp password
  151. */
  152. changeSmtpPassword(smtpPassword) {
  153. this.setState({ smtpPassword });
  154. }
  155. /**
  156. * Change region
  157. */
  158. changeRegion(region) {
  159. this.setState({ region });
  160. }
  161. /**
  162. * Change custom endpoint
  163. */
  164. changeCustomEndpoint(customEndpoint) {
  165. this.setState({ customEndpoint });
  166. }
  167. /**
  168. * Change bucket name
  169. */
  170. changeBucket(bucket) {
  171. this.setState({ bucket });
  172. }
  173. /**
  174. * Change access key id
  175. */
  176. changeAccessKeyId(accessKeyId) {
  177. this.setState({ accessKeyId });
  178. }
  179. /**
  180. * Change secret access key
  181. */
  182. changeSecretAccessKey(secretAccessKey) {
  183. this.setState({ secretAccessKey });
  184. }
  185. /**
  186. * Change gcsApiKeyJsonPath
  187. */
  188. changeGcsApiKeyJsonPath(gcsApiKeyJsonPath) {
  189. this.setState({ gcsApiKeyJsonPath });
  190. }
  191. /**
  192. * Change gcsBucket
  193. */
  194. changeGcsBucket(gcsBucket) {
  195. this.setState({ gcsBucket });
  196. }
  197. /**
  198. * Change gcsUploadNamespace
  199. */
  200. changeGcsUploadNamespace(gcsUploadNamespace) {
  201. this.setState({ gcsUploadNamespace });
  202. }
  203. /**
  204. * Change secret key
  205. */
  206. changeIsEnabledPlugins(isEnabledPlugins) {
  207. this.setState({ isEnabledPlugins });
  208. }
  209. /**
  210. * Update app setting
  211. * @memberOf AdminAppContainer
  212. * @return {Array} Appearance
  213. */
  214. async updateAppSettingHandler() {
  215. const response = await this.appContainer.apiv3.put('/app-settings/app-setting', {
  216. title: this.state.title,
  217. confidential: this.state.confidential,
  218. globalLang: this.state.globalLang,
  219. fileUpload: this.state.fileUpload,
  220. });
  221. const { appSettingParams } = response.data;
  222. return appSettingParams;
  223. }
  224. /**
  225. * Update site url setting
  226. * @memberOf AdminAppContainer
  227. * @return {Array} Appearance
  228. */
  229. async updateSiteUrlSettingHandler() {
  230. const response = await this.appContainer.apiv3.put('/app-settings/site-url-setting', {
  231. siteUrl: this.state.siteUrl,
  232. });
  233. const { siteUrlSettingParams } = response.data;
  234. return siteUrlSettingParams;
  235. }
  236. /**
  237. * Update from adress
  238. * @memberOf AdminAppContainer
  239. * @return {Array} Appearance
  240. */
  241. async updateFromAdressHandler() {
  242. const response = await this.appContainer.apiv3.put('/app-settings/from-address', {
  243. fromAddress: this.state.fromAddress,
  244. });
  245. const { mailSettingParams } = response.data;
  246. return mailSettingParams;
  247. }
  248. /**
  249. * Update mail setting
  250. * @memberOf AdminAppContainer
  251. * @return {Array} Appearance
  252. */
  253. async updateMailSettingHandler() {
  254. const response = await this.appContainer.apiv3.put('/app-settings/mail-setting', {
  255. fromAddress: this.state.fromAddress,
  256. smtpHost: this.state.smtpHost,
  257. smtpPort: this.state.smtpPort,
  258. smtpUser: this.state.smtpUser,
  259. smtpPassword: this.state.smtpPassword,
  260. });
  261. const { mailSettingParams } = response.data;
  262. return mailSettingParams;
  263. }
  264. /**
  265. * Initialize mail setting
  266. * @memberOf AdminAppContainer
  267. * @return {Array} Appearance
  268. */
  269. async initializeMailSettingHandler() {
  270. const response = await this.appContainer.apiv3.delete('/app-settings/mail-setting', {});
  271. const {
  272. mailSettingParams,
  273. } = response.data;
  274. this.setState(mailSettingParams);
  275. return mailSettingParams;
  276. }
  277. /**
  278. * Update AWS setting
  279. * @memberOf AdminAppContainer
  280. * @return {Array} Appearance
  281. */
  282. async updateAwsSettingHandler() {
  283. const response = await this.appContainer.apiv3.put('/app-settings/aws-setting', {
  284. region: this.state.region,
  285. customEndpoint: this.state.customEndpoint,
  286. bucket: this.state.bucket,
  287. accessKeyId: this.state.accessKeyId,
  288. secretAccessKey: this.state.secretAccessKey,
  289. });
  290. const { awsSettingParams } = response.data;
  291. return awsSettingParams;
  292. }
  293. /**
  294. * Update GCP setting
  295. * @memberOf AdminAppContainer
  296. * @return {Array} Appearance
  297. */
  298. async updateGcpSettingHandler() {
  299. // TODO GW-3660 cteaye api
  300. return;
  301. }
  302. /**
  303. * Update plugin setting
  304. * @memberOf AdminAppContainer
  305. * @return {Array} Appearance
  306. */
  307. async updatePluginSettingHandler() {
  308. const response = await this.appContainer.apiv3.put('/app-settings/plugin-setting', {
  309. isEnabledPlugins: this.state.isEnabledPlugins,
  310. });
  311. const { pluginSettingParams } = response.data;
  312. return pluginSettingParams;
  313. }
  314. }