AdminAppContainer.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. isMailerActive: false,
  23. fromAddress: '',
  24. smtpHost: '',
  25. smtpPort: '',
  26. smtpUser: '',
  27. smtpPassword: '',
  28. sesAccessKeyId: '',
  29. sesSecretAccessKey: '',
  30. region: '',
  31. customEndpoint: '',
  32. bucket: '',
  33. accessKeyId: '',
  34. secretAccessKey: '',
  35. isEnabledPlugins: true,
  36. };
  37. }
  38. /**
  39. * Workaround for the mangling in production build to break constructor.name
  40. */
  41. static getClassName() {
  42. return 'AdminAppContainer';
  43. }
  44. /**
  45. * retrieve app sttings data
  46. */
  47. async retrieveAppSettingsData() {
  48. const response = await this.appContainer.apiv3.get('/app-settings/');
  49. const { appSettingsParams } = response.data;
  50. this.setState({
  51. title: appSettingsParams.title,
  52. confidential: appSettingsParams.confidential,
  53. globalLang: appSettingsParams.globalLang,
  54. fileUpload: appSettingsParams.fileUpload,
  55. siteUrl: appSettingsParams.siteUrl,
  56. envSiteUrl: appSettingsParams.envSiteUrl,
  57. isSetSiteUrl: !!appSettingsParams.siteUrl,
  58. isMailerActive: appSettingsParams.isMailerActive,
  59. fromAddress: appSettingsParams.fromAddress,
  60. smtpHost: appSettingsParams.smtpHost,
  61. smtpPort: appSettingsParams.smtpPort,
  62. smtpUser: appSettingsParams.smtpUser,
  63. smtpPassword: appSettingsParams.smtpPassword,
  64. sesAccessKeyId: appSettingsParams.sesAccessKeyId,
  65. sesSecretAccessKey: appSettingsParams.sesSecretAccessKey,
  66. region: appSettingsParams.region,
  67. customEndpoint: appSettingsParams.customEndpoint,
  68. bucket: appSettingsParams.bucket,
  69. accessKeyId: appSettingsParams.accessKeyId,
  70. secretAccessKey: appSettingsParams.secretAccessKey,
  71. isEnabledPlugins: appSettingsParams.isEnabledPlugins,
  72. });
  73. }
  74. /**
  75. * Change title
  76. */
  77. changeTitle(title) {
  78. this.setState({ title });
  79. }
  80. /**
  81. * Change confidential
  82. */
  83. changeConfidential(confidential) {
  84. this.setState({ confidential });
  85. }
  86. /**
  87. * Change globalLang
  88. */
  89. changeGlobalLang(globalLang) {
  90. this.setState({ globalLang });
  91. }
  92. /**
  93. * Change fileUpload
  94. */
  95. changeFileUpload(fileUpload) {
  96. this.setState({ fileUpload });
  97. }
  98. /**
  99. * Change site url
  100. */
  101. changeSiteUrl(siteUrl) {
  102. this.setState({ siteUrl });
  103. }
  104. /**
  105. * Change from address
  106. */
  107. changeFromAddress(fromAddress) {
  108. this.setState({ fromAddress });
  109. }
  110. /**
  111. * Change smtp host
  112. */
  113. changeSmtpHost(smtpHost) {
  114. this.setState({ smtpHost });
  115. }
  116. /**
  117. * Change smtp port
  118. */
  119. changeSmtpPort(smtpPort) {
  120. this.setState({ smtpPort });
  121. }
  122. /**
  123. * Change smtp user
  124. */
  125. changeSmtpUser(smtpUser) {
  126. this.setState({ smtpUser });
  127. }
  128. /**
  129. * Change smtp password
  130. */
  131. changeSmtpPassword(smtpPassword) {
  132. this.setState({ smtpPassword });
  133. }
  134. /**
  135. * Change sesAccessKeyId
  136. */
  137. changeSesAccessKeyId(sesAccessKeyId) {
  138. this.setState({ sesAccessKeyId });
  139. }
  140. /**
  141. * Change sesSecretAccessKey
  142. */
  143. changeSesSecretAccessKey(sesSecretAccessKey) {
  144. this.setState({ sesSecretAccessKey });
  145. }
  146. /**
  147. * Change region
  148. */
  149. changeRegion(region) {
  150. this.setState({ region });
  151. }
  152. /**
  153. * Change custom endpoint
  154. */
  155. changeCustomEndpoint(customEndpoint) {
  156. this.setState({ customEndpoint });
  157. }
  158. /**
  159. * Change bucket name
  160. */
  161. changeBucket(bucket) {
  162. this.setState({ bucket });
  163. }
  164. /**
  165. * Change access key id
  166. */
  167. changeAccessKeyId(accessKeyId) {
  168. this.setState({ accessKeyId });
  169. }
  170. /**
  171. * Change secret access key
  172. */
  173. changeSecretAccessKey(secretAccessKey) {
  174. this.setState({ secretAccessKey });
  175. }
  176. /**
  177. * Change secret key
  178. */
  179. changeIsEnabledPlugins(isEnabledPlugins) {
  180. this.setState({ isEnabledPlugins });
  181. }
  182. /**
  183. * Update app setting
  184. * @memberOf AdminAppContainer
  185. * @return {Array} Appearance
  186. */
  187. async updateAppSettingHandler() {
  188. const response = await this.appContainer.apiv3.put('/app-settings/app-setting', {
  189. title: this.state.title,
  190. confidential: this.state.confidential,
  191. globalLang: this.state.globalLang,
  192. fileUpload: this.state.fileUpload,
  193. });
  194. const { appSettingParams } = response.data;
  195. return appSettingParams;
  196. }
  197. /**
  198. * Update site url setting
  199. * @memberOf AdminAppContainer
  200. * @return {Array} Appearance
  201. */
  202. async updateSiteUrlSettingHandler() {
  203. const response = await this.appContainer.apiv3.put('/app-settings/site-url-setting', {
  204. siteUrl: this.state.siteUrl,
  205. });
  206. const { siteUrlSettingParams } = response.data;
  207. return siteUrlSettingParams;
  208. }
  209. /**
  210. * Update from adress
  211. * @memberOf AdminAppContainer
  212. * @return {Array} Appearance
  213. */
  214. async updateFromAdressHandler() {
  215. const response = await this.appContainer.apiv3.put('/app-settings/from-address', {
  216. fromAddress: this.state.fromAddress,
  217. });
  218. const { mailSettingParams } = response.data;
  219. return mailSettingParams;
  220. }
  221. /**
  222. * Update smtp setting
  223. * @memberOf AdminAppContainer
  224. * @return {Array} Appearance
  225. */
  226. async updateSmtpSettingHandler() {
  227. const response = await this.appContainer.apiv3.put('/app-settings/smtp-setting', {
  228. smtpHost: this.state.smtpHost,
  229. smtpPort: this.state.smtpPort,
  230. smtpUser: this.state.smtpUser,
  231. smtpPassword: this.state.smtpPassword,
  232. });
  233. const { mailSettingParams } = response.data;
  234. this.setState({ isMailerActive: mailSettingParams.isMailerActive });
  235. return mailSettingParams;
  236. }
  237. /**
  238. * Update ses setting
  239. * @memberOf AdminAppContainer
  240. * @return {Array} Appearance
  241. */
  242. async updateSesSettingHandler() {
  243. const response = await this.appContainer.apiv3.put('/app-settings/ses-setting', {
  244. sesAccessKeyId: this.state.sesAccessKeyId,
  245. sesSecretAccessKey: this.state.sesSecretAccessKey,
  246. });
  247. const { mailSettingParams } = response.data;
  248. this.setState({ isMailerActive: mailSettingParams.isMailerActive });
  249. return mailSettingParams;
  250. }
  251. /**
  252. * send test e-mail
  253. * @memberOf AdminAppContainer
  254. */
  255. async sendTestEmail() {
  256. return this.appContainer.apiv3.post('/app-settings/smtp-test');
  257. }
  258. /**
  259. * Update AWS setting
  260. * @memberOf AdminAppContainer
  261. * @return {Array} Appearance
  262. */
  263. async updateAwsSettingHandler() {
  264. const response = await this.appContainer.apiv3.put('/app-settings/aws-setting', {
  265. region: this.state.region,
  266. customEndpoint: this.state.customEndpoint,
  267. bucket: this.state.bucket,
  268. accessKeyId: this.state.accessKeyId,
  269. secretAccessKey: this.state.secretAccessKey,
  270. });
  271. const { awsSettingParams } = response.data;
  272. return awsSettingParams;
  273. }
  274. /**
  275. * Update plugin setting
  276. * @memberOf AdminAppContainer
  277. * @return {Array} Appearance
  278. */
  279. async updatePluginSettingHandler() {
  280. const response = await this.appContainer.apiv3.put('/app-settings/plugin-setting', {
  281. isEnabledPlugins: this.state.isEnabledPlugins,
  282. });
  283. const { pluginSettingParams } = response.data;
  284. return pluginSettingParams;
  285. }
  286. }