parent
d50999c353
commit
c3e66ec473
13 changed files with 369 additions and 61 deletions
@ -0,0 +1,160 @@ |
||||
import React, { useMemo, useEffect, useCallback } from "react"; |
||||
import { ScrollView, Appearance, View } from "react-native"; |
||||
import { connect } from "react-redux"; |
||||
import { userProduct, comment, file, form } from "../../redux/actions"; |
||||
import onInput from "../../utils/onInput"; |
||||
|
||||
//components
|
||||
import CustomTextInput from "../CustomTextInput"; |
||||
import CustomPressable from "../Pressable"; |
||||
import Select from "../Select"; |
||||
|
||||
//style
|
||||
import tw from "tailwind-rn"; |
||||
import Colors from "../../constants/Colors"; |
||||
import fontSize from "../../constants/fontSize"; |
||||
|
||||
export const Ticket = ({ |
||||
myProductList, |
||||
status, |
||||
ticket, |
||||
getUserProductList, |
||||
submit, |
||||
upload, |
||||
setTicket, |
||||
grades, |
||||
}) => { |
||||
const colorScheme = Appearance.getColorScheme(); |
||||
let opt = useMemo( |
||||
() => ["واحد مورد نظر", "واحد فروش", "واحد فنی", "واحد محتوایی"], |
||||
[status] |
||||
); |
||||
|
||||
useEffect(() => { |
||||
if (myProductList.length === 0 && status) { |
||||
getUserProductList(); |
||||
} |
||||
}, []); |
||||
|
||||
const send = useCallback(async () => { |
||||
if (!ticket?.subject) { |
||||
setDialog({ |
||||
text: "موضوع پیام خود را وارد کنید.", |
||||
type: "alert", |
||||
accept: () => {}, |
||||
open: true, |
||||
}); |
||||
} else if (!ticket?.unit) { |
||||
setDialog({ |
||||
text: "واحد مورد نظر خود را وارد نکرده اید.", |
||||
type: "alert", |
||||
accept: () => {}, |
||||
open: true, |
||||
}); |
||||
} else { |
||||
const data = { |
||||
fileId: null, |
||||
text: ticket?.text, |
||||
name: !status ? ticket?.name : status.firstName + " " + status.lastName, |
||||
cellphone: !status ? ticket?.cellphone : status?.cellphone, |
||||
unit: ticket?.unit, |
||||
bookId: ticket?.bookId, |
||||
subject: ticket?.subject, |
||||
userId: status?.userId, |
||||
}; |
||||
await submit(data); |
||||
} |
||||
}, [status]); |
||||
|
||||
return ( |
||||
<View style={tw('flex-1 pb-4 px-4')}> |
||||
<ScrollView style={tw("flex flex-1")}> |
||||
{!status && ( |
||||
<> |
||||
<CustomTextInput |
||||
label="نام و نام خانوادگی" |
||||
name="name" |
||||
onChange={(name, value) => setTicket({ name, value })} |
||||
value={ticket?.name || ""} |
||||
regex={(val) => val} |
||||
/> |
||||
<CustomTextInput |
||||
label="شماره تماس" |
||||
name="cellphone" |
||||
onChange={(name, value) => setTicket({ name, value })} |
||||
value={ticket?.cellphone || ""} |
||||
regex={(val) => onInput.phonenumber(val)} |
||||
maxLength="11" |
||||
/> |
||||
</> |
||||
)} |
||||
<Select |
||||
defaultValue={ticket?.unit || myProductList[0]} |
||||
options={status && myProductList?.length ? opt : opt.slice(0, 3)} |
||||
name="unit" |
||||
onChange={(name, value) => setTicket({ name, value })} |
||||
width={"100%"} |
||||
/> |
||||
{ticket?.unit === "واحد محتوایی" && ( |
||||
<Select |
||||
name="bookId" |
||||
defaultValue={ticket?.subject} |
||||
options={[ |
||||
...new Set( |
||||
myProductList?.map((item) => [ |
||||
item?.product?.book?.id, |
||||
`${item?.product?.book.name} پایه ${ |
||||
Object.values(grades)[item.product.book.gradeId] |
||||
}`,
|
||||
]) || [] |
||||
), |
||||
]} |
||||
onChange={(name, value) => setTicket({ name, value })} |
||||
width={"100%"} |
||||
/> |
||||
)} |
||||
<CustomTextInput |
||||
name="subject" |
||||
onChange={(name, value) => setTicket({ name, value })} |
||||
value={ticket?.subject || ""} |
||||
regex={(val) => val} |
||||
label="موضوع" |
||||
/> |
||||
<CustomTextInput |
||||
name="text" |
||||
onChange={(name, value) => setTicket({ name, value })} |
||||
value={ticket?.text || ""} |
||||
regex={(val) => val} |
||||
label="متن پیام" |
||||
multiline={true} |
||||
/> |
||||
<View style={tw("mt-4")}></View> |
||||
</ScrollView> |
||||
<CustomPressable |
||||
title={"ارسال پیام"} |
||||
backgroundColor={Colors.theme1[colorScheme].greenCF} |
||||
color={"white"} |
||||
border={{ color: "#196EC0", width: 0 }} |
||||
width={"100%"} |
||||
onPress={() => send()} |
||||
/> |
||||
</View> |
||||
); |
||||
}; |
||||
|
||||
const mapStateToProps = (state) => ({ |
||||
isDark: state.publicApi.isDark, |
||||
myProductList: state.userProduct.myList, |
||||
status: state.user.status, |
||||
ticket: state.form.ticket, |
||||
grades: state.publicApi.grades, |
||||
}); |
||||
|
||||
const mapDispatchToProps = { |
||||
getUserProductList: userProduct.myList, |
||||
submit: comment.add, |
||||
upload: file.upload, |
||||
setTicket: form.setTicket, |
||||
}; |
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(Ticket); |
@ -0,0 +1,32 @@ |
||||
import proxy from "../proxy"; |
||||
const comment = { |
||||
list: |
||||
(data = {}) => |
||||
async (dispatch) => |
||||
await proxy.get("comment/list", data, { dispatch }), |
||||
info: |
||||
(data = {}) => |
||||
async (dispatch) => { |
||||
await proxy.get("comment/info", data, { dispatch }); |
||||
}, |
||||
add: |
||||
(data = {}, data2) => |
||||
async (dispatch) => { |
||||
await proxy.post("comment/add", data, { dispatch }); |
||||
if (data2) await proxy.get("book/info", data2, { dispatch }); |
||||
}, |
||||
del: |
||||
(data = {}, data2 = {}) => |
||||
async (dispatch) => { |
||||
await proxy.delete("ar/delete", data); |
||||
await proxy.get("ar/list", data2, { dispatch }); |
||||
}, |
||||
update: |
||||
(data = {}, data2 = {}) => |
||||
async (dispatch) => { |
||||
await proxy.put("ar/update", data); |
||||
await proxy.get("ar/list", data2, { dispatch }); |
||||
}, |
||||
}; |
||||
|
||||
export default comment; |
@ -0,0 +1,8 @@ |
||||
const form = { |
||||
setTicket: |
||||
(data = {}) => |
||||
async (dispatch) => |
||||
await dispatch({ type: "form/ticket", data }), |
||||
}; |
||||
|
||||
export default form; |
@ -0,0 +1,34 @@ |
||||
const initialState = { |
||||
loading: false, |
||||
error: null, |
||||
list: null, |
||||
}; |
||||
|
||||
export default function comment(state = initialState, action) { |
||||
let { type, data } = action; |
||||
switch (type) { |
||||
case "comment/list": |
||||
return { ...state, loading: false, error: null }; |
||||
case "comment/update": |
||||
return { ...state, loading: false, error: null }; |
||||
case "comment/add": |
||||
toast.success("ثبت درخواست با موفقیت انجام شد"); |
||||
return { ...state, loading: false, error: null }; |
||||
case "comment/delete": |
||||
return { ...state, loading: false, error: null }; |
||||
case "comment/info": |
||||
return { |
||||
...state, |
||||
loading: false, |
||||
list: data, |
||||
error: null, |
||||
}; |
||||
case "comment/loading": |
||||
return { ...state, loading: true }; |
||||
case "comment/error": |
||||
toast.error(data.message); |
||||
return { ...state, loading: false, error: data.message }; |
||||
default: |
||||
return state; |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
const initialState = { |
||||
loading: false, |
||||
error: null, |
||||
ticket: {}, |
||||
}; |
||||
|
||||
export default function form(state = initialState, action) { |
||||
let { type, data } = action; |
||||
switch (type) { |
||||
case "form/ticket": |
||||
return { |
||||
...state, |
||||
loading: false, |
||||
ticket: { ...state.ticket, [data.name]: data.value }, |
||||
error: null, |
||||
}; |
||||
case "form/loading": |
||||
return { ...state, loading: true }; |
||||
case "form/error": |
||||
return { ...state, loading: false, error: data.message }; |
||||
default: |
||||
return state; |
||||
} |
||||
} |
Loading…
Reference in new issue