mirror of
https://github.com/Funkoala14/CreatorCenter_OOIN.git
synced 2025-06-08 05:28:14 +08:00
[dev]templates
This commit is contained in:
parent
63dfd70117
commit
4a22f0a37d
@ -22,7 +22,11 @@ export default function TemplateList({ activeTab, openModal, setFormData }) {
|
|||||||
mission: template.type,
|
mission: template.type,
|
||||||
platform: template.platform,
|
platform: template.platform,
|
||||||
service: template.service,
|
service: template.service,
|
||||||
template: template.message,
|
content: template.content,
|
||||||
|
title: template.title,
|
||||||
|
category: template.category,
|
||||||
|
collaboration_type: template.collaboration_type,
|
||||||
|
is_public: template.is_public,
|
||||||
});
|
});
|
||||||
openModal();
|
openModal();
|
||||||
}
|
}
|
||||||
|
@ -19,23 +19,23 @@ export const BRAND_SOURCES = [
|
|||||||
|
|
||||||
export const CAMPAIGN_SERVICES = [
|
export const CAMPAIGN_SERVICES = [
|
||||||
{
|
{
|
||||||
value: 'fufei',
|
value: 'paid_promotion',
|
||||||
name: '达人短视频(付费)',
|
name: '达人短视频(付费)',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'chunyong',
|
value: 'affiliate',
|
||||||
name: '达人短视频(纯佣)',
|
name: '达人短视频(纯佣)',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'dai',
|
value: 'sponsored_content',
|
||||||
name: '直播(代播)',
|
name: '直播(代播)',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'dabao',
|
value: 'brand_ambassador',
|
||||||
name: '直播(达播)',
|
name: '直播(达播)',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'chun',
|
value: 'other',
|
||||||
name: '纯素材短视频',
|
name: '纯素材短视频',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -3,7 +3,7 @@ import SearchBar from '../components/SearchBar';
|
|||||||
import { Footprints, Plus } from 'lucide-react';
|
import { Footprints, Plus } from 'lucide-react';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { addTemplateApi, editTemplateApi, fetchTemplates } from '../store/slices/inboxSlice';
|
import { addTemplateThunk, editTemplateThunk, fetchTemplates } from '../store/slices/inboxSlice';
|
||||||
import TemplateList from '../components/TemplateList';
|
import TemplateList from '../components/TemplateList';
|
||||||
import { CAMPAIGN_SERVICES } from '../lib/constant';
|
import { CAMPAIGN_SERVICES } from '../lib/constant';
|
||||||
|
|
||||||
@ -12,10 +12,14 @@ export default function InboxTemplate() {
|
|||||||
const [showAddTemplateModal, setShowAddTemplateModal] = useState(false);
|
const [showAddTemplateModal, setShowAddTemplateModal] = useState(false);
|
||||||
const [showEditTemplateModal, setShowEditTemplateModal] = useState(false);
|
const [showEditTemplateModal, setShowEditTemplateModal] = useState(false);
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
mission: '',
|
title: 'TikTok合作邀请',
|
||||||
platform: '',
|
content: `Hi {tiktok id},\n\n我是{sender name},来自OOIN Media。我们对您的TikTok内容印象深刻,希望能就付费推广活动进行合作。\n\n请问您对单个TikTok视频的报价是多少?如果我们计划多个视频合作,是否有批量折扣?\n\n期待您的回复!`,
|
||||||
service: '',
|
category: 1,
|
||||||
template: '',
|
mission: 'initial_contact',
|
||||||
|
platform: 'tiktok',
|
||||||
|
service: 'text',
|
||||||
|
collaboration_type: 'paid_promotion',
|
||||||
|
is_public: true,
|
||||||
});
|
});
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
@ -102,15 +106,14 @@ function AddTemplateModal({ show, formData, setFormData, handleClose, type = 'ad
|
|||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
console.log(formData);
|
console.log(formData);
|
||||||
if(type === 'add') {
|
if (type === 'add') {
|
||||||
dispatch(addTemplateApi(formData));
|
dispatch(addTemplateThunk(formData));
|
||||||
} else {
|
} else {
|
||||||
dispatch(editTemplateApi(formData));
|
dispatch(editTemplateThunk(formData));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {}, [formData]);
|
||||||
}, [formData]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal show={show} onHide={handleClose}>
|
<Modal show={show} onHide={handleClose}>
|
||||||
@ -119,6 +122,17 @@ function AddTemplateModal({ show, formData, setFormData, handleClose, type = 'ad
|
|||||||
</Modal.Header>
|
</Modal.Header>
|
||||||
<Modal.Body>
|
<Modal.Body>
|
||||||
<Form>
|
<Form>
|
||||||
|
<Form.Group className='mb-3' controlId='formBasicEmail'>
|
||||||
|
<Form.Label>Title</Form.Label>
|
||||||
|
<Form.Control
|
||||||
|
required
|
||||||
|
type='text'
|
||||||
|
placeholder='Enter title'
|
||||||
|
value={formData.title}
|
||||||
|
name='title'
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
<Form.Group className='mb-3' controlId='formBasicEmail'>
|
<Form.Group className='mb-3' controlId='formBasicEmail'>
|
||||||
<Form.Label>Mission</Form.Label>
|
<Form.Label>Mission</Form.Label>
|
||||||
<Form.Select
|
<Form.Select
|
||||||
@ -132,10 +146,11 @@ function AddTemplateModal({ show, formData, setFormData, handleClose, type = 'ad
|
|||||||
<option value='' disabled>
|
<option value='' disabled>
|
||||||
Select mission
|
Select mission
|
||||||
</option>
|
</option>
|
||||||
<option value='initial'>初步建联</option>
|
<option value='initial_contact'>初步建联</option>
|
||||||
<option value='bargain'>砍价邮件</option>
|
<option value='negotiation'>砍价邮件</option>
|
||||||
<option value='script'>脚本邮件</option>
|
<option value='script'>脚本邮件</option>
|
||||||
<option value='cooperation'>合作追踪</option>
|
<option value='follow_up'>合作追踪</option>
|
||||||
|
<option value='other'>其他</option>
|
||||||
</Form.Select>
|
</Form.Select>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Group className='mb-3' controlId='formBasicEmail'>
|
<Form.Group className='mb-3' controlId='formBasicEmail'>
|
||||||
@ -151,10 +166,10 @@ function AddTemplateModal({ show, formData, setFormData, handleClose, type = 'ad
|
|||||||
<option value='' disabled>
|
<option value='' disabled>
|
||||||
Select platform
|
Select platform
|
||||||
</option>
|
</option>
|
||||||
<option value='TikTok'>TikTok</option>
|
<option value='tiktok'>TikTok</option>
|
||||||
<option value='Instagram'>Instagram</option>
|
<option value='instagram'>Instagram</option>
|
||||||
<option value='Facebook'>Facebook</option>
|
<option value='facebook'>Facebook</option>
|
||||||
<option value='YouTube'>Youtube</option>
|
<option value='youtube'>Youtube</option>
|
||||||
</Form.Select>
|
</Form.Select>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Group className='mb-3' controlId='formBasicEmail'>
|
<Form.Group className='mb-3' controlId='formBasicEmail'>
|
||||||
@ -182,8 +197,8 @@ function AddTemplateModal({ show, formData, setFormData, handleClose, type = 'ad
|
|||||||
as='textarea'
|
as='textarea'
|
||||||
rows={10}
|
rows={10}
|
||||||
placeholder='Enter template'
|
placeholder='Enter template'
|
||||||
value={formData.template}
|
value={formData.content}
|
||||||
name='template'
|
name='content'
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
||||||
import { format, isToday, parseISO } from 'date-fns';
|
import { format, isToday, parseISO } from 'date-fns';
|
||||||
import api from '@/services/api';
|
import api from '@/services/api';
|
||||||
|
import { setNotificationBarMessage } from './notificationBarSlice';
|
||||||
|
|
||||||
const mockTemplates = [
|
const mockTemplates = [
|
||||||
{
|
{
|
||||||
@ -157,7 +158,8 @@ const mockChatHistory = [
|
|||||||
{
|
{
|
||||||
id: '13',
|
id: '13',
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,',
|
content:
|
||||||
|
'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,',
|
||||||
created_at: '2025-03-22 06:39:46',
|
created_at: '2025-03-22 06:39:46',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -189,32 +191,52 @@ export const fetchChatHistory = createAsyncThunk('inbox/fetchChatHistory', async
|
|||||||
return { chatHistory: mockChatHistory, chatId: id };
|
return { chatHistory: mockChatHistory, chatId: id };
|
||||||
});
|
});
|
||||||
|
|
||||||
export const fetchTemplates = createAsyncThunk('inbox/fetchTemplates', async (type) => {
|
export const fetchTemplates = createAsyncThunk('inbox/fetchTemplates', async (_, { rejectWithValue }) => {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
try {
|
||||||
if (type === 'all') {
|
const response = await api.get('/template/');
|
||||||
return mockTemplates;
|
if (response.code === 200) {
|
||||||
|
return response.data.results;
|
||||||
|
} else {
|
||||||
|
throw new Error(response.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return rejectWithValue(error.response.data.message);
|
||||||
}
|
}
|
||||||
return mockTemplates.filter((item) => item.type === type);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const editTemplateApi = createAsyncThunk('inbox/editTemplate', async (formData) => {
|
export const editTemplateThunk = createAsyncThunk(
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
'inbox/editTemplate',
|
||||||
const {id, ...rest} = formData;
|
async (formData, { rejectWithValue, dispatch }) => {
|
||||||
const index = mockTemplates.findIndex((item) => item.id === id);
|
try {
|
||||||
mockTemplates[index] = { ...mockTemplates[index], ...rest };
|
const response = await api.put(`/template/${formData.id}/`, formData);
|
||||||
return mockTemplates;
|
if (response.code === 200) {
|
||||||
});
|
return response.data;
|
||||||
|
} else {
|
||||||
|
throw new Error(response.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
dispatch(setNotificationBarMessage({ message: error.message, type: 'error' }));
|
||||||
|
return rejectWithValue(error.response.data.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export const addTemplateApi = createAsyncThunk('inbox/addTemplate', async (formData) => {
|
export const addTemplateThunk = createAsyncThunk(
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
'inbox/addTemplate',
|
||||||
const newTemplate = {
|
async (formData, { rejectWithValue, dispatch }) => {
|
||||||
id: mockTemplates.length + 1,
|
try {
|
||||||
message: formData.template,
|
const response = await api.post('/template/', formData);
|
||||||
...formData,
|
if (response.code === 200) {
|
||||||
};
|
return response.data;
|
||||||
const newTemplates = [...mockTemplates, newTemplate];
|
} else {
|
||||||
return newTemplates;
|
throw new Error(response.message);
|
||||||
});
|
}
|
||||||
|
} catch (error) {
|
||||||
|
dispatch(setNotificationBarMessage({ message: error.message, type: 'error' }));
|
||||||
|
return rejectWithValue(error.response.data.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
inboxList: [],
|
inboxList: [],
|
||||||
@ -278,26 +300,25 @@ const inboxSlice = createSlice({
|
|||||||
state.templatesStatus = 'succeeded';
|
state.templatesStatus = 'succeeded';
|
||||||
state.templates = action.payload;
|
state.templates = action.payload;
|
||||||
})
|
})
|
||||||
.addCase(editTemplateApi.pending, (state) => {
|
.addCase(editTemplateThunk.pending, (state) => {
|
||||||
state.templatesStatus = 'loading';
|
state.templatesStatus = 'loading';
|
||||||
})
|
})
|
||||||
.addCase(editTemplateApi.fulfilled, (state, action) => {
|
.addCase(editTemplateThunk.fulfilled, (state, action) => {
|
||||||
state.templatesStatus = 'succeeded';
|
state.templatesStatus = 'succeeded';
|
||||||
state.templates = action.payload;
|
state.templates = action.payload;
|
||||||
})
|
})
|
||||||
.addCase(editTemplateApi.rejected, (state, action) => {
|
.addCase(editTemplateThunk.rejected, (state, action) => {
|
||||||
state.templatesStatus = 'failed';
|
state.templatesStatus = 'failed';
|
||||||
state.error = action.payload;
|
state.error = action.payload;
|
||||||
})
|
})
|
||||||
.addCase(addTemplateApi.pending, (state) => {
|
.addCase(addTemplateThunk.pending, (state) => {
|
||||||
state.templatesStatus = 'loading';
|
state.templatesStatus = 'loading';
|
||||||
})
|
})
|
||||||
.addCase(addTemplateApi.fulfilled, (state, action) => {
|
.addCase(addTemplateThunk.fulfilled, (state, action) => {
|
||||||
console.log(action.payload);
|
|
||||||
state.templatesStatus = 'succeeded';
|
state.templatesStatus = 'succeeded';
|
||||||
state.templates = action.payload;
|
state.templates = action.payload;
|
||||||
})
|
})
|
||||||
.addCase(addTemplateApi.rejected, (state, action) => {
|
.addCase(addTemplateThunk.rejected, (state, action) => {
|
||||||
state.templatesStatus = 'failed';
|
state.templatesStatus = 'failed';
|
||||||
state.error = action.payload;
|
state.error = action.payload;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user