switchStatus.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { newEditAdqAdgroupsDataApi, updateBatchDynamicCreativesInfoApi } from "@/services/gameData"
  3. import { message, notification, Switch } from "antd"
  4. import React from "react"
  5. /**
  6. * 修改启停
  7. */
  8. interface Props {
  9. configuredStatus: string,
  10. isDeleted?: boolean,
  11. accountId: number,
  12. dynamicCreativeId: number,
  13. onChange?: () => void
  14. }
  15. const SwitchStatus: React.FC<Props> = (prosp) => {
  16. const { configuredStatus, isDeleted, accountId, dynamicCreativeId, onChange } = prosp
  17. const updateBatchDynamicCreativesInfo = useAjax((params) => updateBatchDynamicCreativesInfoApi(params))
  18. const switchHandle = (status: boolean) => {
  19. updateBatchDynamicCreativesInfo.run({ accountAdgroupMaps: [accountId + ',' + dynamicCreativeId], suspend: !status }).then(res => {
  20. message.success(`${configuredStatus === 'AD_STATUS_NORMAL' ? '启动' : '暂停'}成功`)
  21. if (res?.fail) {
  22. notification.error({
  23. message: `${configuredStatus === 'AD_STATUS_NORMAL' ? '启动' : '暂停'}失败`,
  24. description: `修改失败${res.fail}条,失败的请到任务列表查看`,
  25. duration: 0
  26. });
  27. }
  28. onChange?.()
  29. })
  30. }
  31. return <Switch size="small" checked={configuredStatus === 'AD_STATUS_NORMAL'} loading={updateBatchDynamicCreativesInfo.loading} disabled={isDeleted} onChange={(checked) => switchHandle(checked)}/>
  32. }
  33. export default React.memo(SwitchStatus)