parent
11dbca78b6
commit
0651eaf99b
18 changed files with 264 additions and 60 deletions
@ -0,0 +1,9 @@ |
||||
import React from "react"; |
||||
import CircularProgress from "@mui/material/CircularProgress"; |
||||
|
||||
|
||||
export default function CircularIndeterminate({size}) { |
||||
return ( |
||||
<CircularProgress size={size} /> |
||||
); |
||||
} |
@ -0,0 +1,51 @@ |
||||
interface list { |
||||
type: "userFactor/myList"; |
||||
data: any; |
||||
} |
||||
|
||||
interface info { |
||||
type: "userFactor/info"; |
||||
data: any; |
||||
} |
||||
|
||||
interface update { |
||||
type: "userFactor/update"; |
||||
data: any; |
||||
} |
||||
|
||||
interface payment { |
||||
type: "userFactor/payment"; |
||||
data: any; |
||||
} |
||||
|
||||
interface verify { |
||||
type: "userFactor/verify"; |
||||
data: any; |
||||
} |
||||
|
||||
interface deleteUserOffCode { |
||||
type: "userFactor/deleteUserOffCode"; |
||||
data: any; |
||||
} |
||||
|
||||
interface error { |
||||
type: "userFactor/error"; |
||||
data: undefined; |
||||
} |
||||
|
||||
interface loading { |
||||
type: "userFactor/loading"; |
||||
data: undefined; |
||||
} |
||||
|
||||
type UserFactorAction = |
||||
| list |
||||
| info |
||||
| update |
||||
| payment |
||||
| verify |
||||
| deleteUserOffCode |
||||
| loading |
||||
| error; |
||||
|
||||
export default UserFactorAction; |
@ -0,0 +1,40 @@ |
||||
import { toast } from "react-toastify"; |
||||
import {UserFactorAction} from '../actions-type'; |
||||
const initialState = { |
||||
loading: false, |
||||
error: null, |
||||
list: null, |
||||
info: null, |
||||
sum: null, |
||||
checkEmpty: false, |
||||
isVerified: null, |
||||
}; |
||||
export default function userFactor(state = initialState, action : UserFactorAction) { |
||||
let { type, data } = action; |
||||
switch (type) { |
||||
case "userFactor/myList": |
||||
return { ...state, loading: false, list: data, error: null }; |
||||
case "userFactor/info": |
||||
return { ...state, loading: false, info: data, error: null }; |
||||
case "userFactor/update": |
||||
toast.success("درخواست شما با موفقیت انجام شد."); |
||||
return { ...state, loading: false, error: null }; |
||||
// case "userFactor/add":
|
||||
// toast.success("درخواست شما با موفقیت انجام شد.");
|
||||
// return { ...state, loading: false, error: null, sum: data.payPrice };
|
||||
case "userFactor/deleteUserOffCode": |
||||
return { ...state, loading: false, error: null }; |
||||
case "userFactor/payment": |
||||
window.location.replace(data); |
||||
return { ...state, loading: false, error: null, isVerified: false }; |
||||
case "userFactor/verify": |
||||
return { ...state, loading: false, error: null, isVerified: true }; |
||||
case "userFactor/loading": |
||||
return { ...state, loading: true }; |
||||
case "userFactor/error": |
||||
toast.error(data.message); |
||||
return { ...state, loading: false, error: data.message }; |
||||
default: |
||||
return state; |
||||
} |
||||
} |
@ -1,16 +1,63 @@ |
||||
import React from 'react'; |
||||
import './index.scss'; |
||||
import React, { useState } from "react"; |
||||
import { connect } from "react-redux"; |
||||
import { userFactor } from "../../../redux/actions"; |
||||
import "./index.scss"; |
||||
|
||||
export default function DiscountCode() { |
||||
function DiscountCode({ |
||||
codeId, |
||||
setCodeId, |
||||
delCodeId, |
||||
userId, |
||||
factorId, |
||||
code, |
||||
}: any) { |
||||
const [value, setValue] = React.useState(code || ""); |
||||
const setOff = () => { |
||||
setCodeId({ offCodeValue: value, userId: userId, id: Number(factorId) || null }); |
||||
}; |
||||
return ( |
||||
<div className="discount-code d-flex align-items-center justify-content-between"> |
||||
<h3>کارت هدیه یا کد تخفیف دارید؟ </h3> |
||||
<div className="d-flex flex-column"> |
||||
<div className="d-flex"> |
||||
<input type="text" placeholder="کد خود را در این قسمت وارد نمائید" /> |
||||
<button>تایید کد</button> |
||||
{!code ? ( |
||||
<> |
||||
<input |
||||
type="text" |
||||
placeholder="کد خود را در این قسمت وارد نمائید" |
||||
defaultValue={codeId} |
||||
onChange={(e) => setValue(e.target.value)} |
||||
/> |
||||
<button onClick={setOff}>تایید کد</button> |
||||
</> |
||||
) : ( |
||||
<> |
||||
<p> |
||||
کد تخفیف برای شما ثبت شده است |
||||
</p> |
||||
<button |
||||
onClick={() => delCodeId({})} |
||||
className="discount-code__cancel" |
||||
> |
||||
x{" "} |
||||
</button> |
||||
</> |
||||
)} |
||||
</div> |
||||
</div> |
||||
</div> |
||||
) |
||||
); |
||||
} |
||||
|
||||
export default connect( |
||||
(state: any) => ({ |
||||
codeId: state.userFactor.info?.codeId, |
||||
code: state.userFactor.info?.offCode?.code, |
||||
userId: state.user.status.id, |
||||
factorId: state.userFactor.info?.id, |
||||
}), |
||||
{ |
||||
setCodeId: userFactor.update, |
||||
delCodeId: userFactor.deleteUserOffCode, |
||||
} |
||||
)(DiscountCode); |
||||
|
Loading…
Reference in new issue