feat: update tonggao
This commit is contained in:
@ -1,33 +1,35 @@
|
||||
import { BaseEventOrig, Button, ButtonProps, Image, InputProps } from '@tarojs/components';
|
||||
import Taro, { UploadTask } from '@tarojs/taro';
|
||||
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { Dialog } from '@taroify/core';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
|
||||
import BlFormInput from '@/components/bl-form-input';
|
||||
import BlFormItem from '@/components/bl-form-item';
|
||||
import LoadingDialog from '@/components/loading-dialog';
|
||||
import CompanyPublishJobBuy from '@/components/product-dialog/steps-ui/company-publish-job-buy';
|
||||
import SafeBottomPadding from '@/components/safe-bottom-padding';
|
||||
import { EventName, PageUrl } from '@/constants/app';
|
||||
import { CertificationStatusType } from '@/constants/company';
|
||||
import { CollectEventName, ReportEventId } from '@/constants/event';
|
||||
import { ProductType } from '@/constants/product';
|
||||
import useCachedJobId from '@/hooks/use-cached-job';
|
||||
import useUserInfo from '@/hooks/use-user-info';
|
||||
import { ICertificationRequest } from '@/types/company';
|
||||
import { isValidIdCard, isValidPhone, logWithPrefix } from '@/utils/common';
|
||||
import { postCertification, getPhone } from '@/utils/company';
|
||||
import { collectEvent, reportEvent } from '@/utils/event';
|
||||
import { postPublishJob } from '@/utils/job';
|
||||
import { chooseMedia } from '@/utils/material';
|
||||
import { redirectTo } from '@/utils/route';
|
||||
import { requestProductBalance } from '@/utils/product';
|
||||
import { redirectTo } from '@/utils/route';
|
||||
import Toast from '@/utils/toast';
|
||||
import { dispatchUpdateUser, requestUserInfo } from '@/utils/user';
|
||||
import { uploadVideo } from '@/utils/video';
|
||||
|
||||
import './index.less';
|
||||
import { requestProductBalance } from '@/utils/product';
|
||||
import { ProductType } from '@/constants/product';
|
||||
import useCachedJob from '@/hooks/use-cached-job';
|
||||
import { postCreateJob } from '@/utils/job';
|
||||
import { Dialog } from '@taroify/core';
|
||||
import CompanyPublishJobBuy from '@/components/product-dialog/steps-ui/company-publish-job-buy';
|
||||
import { clearCachedJobId } from '@/store/actions';
|
||||
import store from '@/store';
|
||||
|
||||
const PREFIX = 'page-certification';
|
||||
const log = logWithPrefix(PREFIX);
|
||||
@ -107,7 +109,8 @@ export default function Certification() {
|
||||
const [company, setCompany] = useState('');
|
||||
const [open, setOpen] = useState(false);
|
||||
const [showBuy, setShowBuy] = useState(false);
|
||||
const cachedJobData = useCachedJob();
|
||||
const cachedJobId = useCachedJobId();
|
||||
const createdJobIdRef = useRef('');
|
||||
|
||||
const handleClickIdCardLeft = useCallback(async () => {
|
||||
reportEvent(ReportEventId.CLICK_UPLOAD_ID_CARD, { type: 'left' });
|
||||
@ -141,25 +144,28 @@ export default function Certification() {
|
||||
setCompany(value);
|
||||
}, []);
|
||||
|
||||
const handleCreateJob = useCallback(async () => {
|
||||
if (cachedJobData.employType) {
|
||||
const handleCloseBuy = useCallback(() => {
|
||||
setShowBuy(false);
|
||||
redirectTo(PageUrl.CertificationManage);
|
||||
}, []);
|
||||
|
||||
const handlePublishJob = useCallback(async () => {
|
||||
try {
|
||||
Taro.showLoading();
|
||||
try {
|
||||
await postCreateJob(cachedJobData);
|
||||
Taro.eventCenter.trigger(EventName.COMPANY_JOB_PUBLISH_CHANGED);
|
||||
await Toast.success('通告创建成功', 1500, true);
|
||||
redirectTo(PageUrl.CertificationManage);
|
||||
} catch (e) {
|
||||
console.error('submit error', e);
|
||||
Toast.error('通告审核失败请重试');
|
||||
collectEvent(CollectEventName.PUBLISH_JOB_FAILED, e);
|
||||
} finally {
|
||||
Taro.hideLoading();
|
||||
}
|
||||
} else {
|
||||
Toast.error('数据出错');
|
||||
await postPublishJob(cachedJobId!);
|
||||
await Toast.success('通告发布成功', 1500, true);
|
||||
store.dispatch(clearCachedJobId());
|
||||
Taro.eventCenter.trigger(EventName.COMPANY_JOB_PUBLISH_CHANGED);
|
||||
redirectTo(PageUrl.CertificationManage);
|
||||
} catch (e) {
|
||||
console.error('submit error', e);
|
||||
Toast.error('通告发布失败');
|
||||
collectEvent(CollectEventName.PUBLISH_JOB_FAILED, e);
|
||||
redirectTo(PageUrl.CertificationManage);
|
||||
} finally {
|
||||
Taro.hideLoading();
|
||||
}
|
||||
}, [cachedJobData]);
|
||||
}, [cachedJobId]);
|
||||
|
||||
const handleSubmit = useCallback(async () => {
|
||||
reportEvent(ReportEventId.CLICK_CERTIFICATION_SUBMIT);
|
||||
@ -185,15 +191,13 @@ export default function Certification() {
|
||||
return;
|
||||
}
|
||||
dispatchUpdateUser({ bossAuthStatus: CertificationStatusType.Success });
|
||||
// 判断付钱没有
|
||||
|
||||
const [time] = await requestProductBalance(ProductType.CompanyPublishJob);
|
||||
if (time <= 0) {
|
||||
// 付钱
|
||||
setShowBuy(true);
|
||||
Taro.hideLoading();
|
||||
} else {
|
||||
// 获取data创建
|
||||
await handleCreateJob();
|
||||
await handlePublishJob();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('submit error', e);
|
||||
@ -210,6 +214,7 @@ export default function Certification() {
|
||||
try {
|
||||
const { phoneNumber } = await getPhone(e.detail.code);
|
||||
setRevisedPhone(phoneNumber);
|
||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||
} catch (e) {
|
||||
Toast.error('获取手机号失败');
|
||||
}
|
||||
@ -299,9 +304,9 @@ export default function Certification() {
|
||||
<div>
|
||||
<LoadingDialog open={open} text="认证中" />
|
||||
</div>
|
||||
<Dialog open={showBuy} onClose={() => setShowBuy(false)}>
|
||||
<Dialog open={showBuy} onClose={handleCloseBuy}>
|
||||
<Dialog.Content>
|
||||
<CompanyPublishJobBuy onNext={handleCreateJob} defaultSelect={1} />
|
||||
<CompanyPublishJobBuy onNext={handlePublishJob} />
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user