| 1 |
www |
1 |
import {axios} from "../../../utils";
|
|
|
2 |
import React, { useEffect, useState } from "react";
|
|
|
3 |
import { useForm } from "react-hook-form";
|
|
|
4 |
import { connect } from "react-redux";
|
|
|
5 |
import styled from "styled-components";
|
|
|
6 |
import { addNotification } from "../../../redux/notification/notification.actions";
|
|
|
7 |
import Spinner from "../../../shared/loading-spinner/Spinner";
|
|
|
8 |
import SwitchInput from "./switch-input/SwitchInput";
|
|
|
9 |
|
|
|
10 |
const StyledSettings = styled.div`
|
|
|
11 |
.notbat {
|
|
|
12 |
display: flex;
|
|
|
13 |
justify-content: space-between;
|
|
|
14 |
align-items: center;
|
|
|
15 |
padding: 1rem;
|
|
|
16 |
border-bottom: 1px solid #f2f2f2;
|
|
|
17 |
position: relative;
|
|
|
18 |
}
|
|
|
19 |
`;
|
|
|
20 |
|
|
|
21 |
const StyledSpinnerContainer = styled.div`
|
|
|
22 |
position: absolute;
|
|
|
23 |
left: 0;
|
|
|
24 |
top: 0;
|
|
|
25 |
width: 100%;
|
|
|
26 |
height: 100%;
|
|
|
27 |
background: rgba(255, 255, 255, 0.4);
|
|
|
28 |
display: flex;
|
|
|
29 |
justify-content: center;
|
|
|
30 |
align-items: center;
|
|
|
31 |
z-index: 300;
|
|
|
32 |
`;
|
|
|
33 |
|
|
|
34 |
const Notifications = (props) => {
|
|
|
35 |
// redux destructuring
|
|
|
36 |
const { addNotification } = props;
|
|
|
37 |
// states
|
|
|
38 |
const [loading, setLoading] = useState(false);
|
|
|
39 |
|
|
|
40 |
const { register, handleSubmit, setValue } = useForm();
|
|
|
41 |
|
|
|
42 |
const handleOnSubmit = async (data) => {
|
|
|
43 |
setLoading(true);
|
|
|
44 |
const formData = new FormData();
|
|
|
45 |
Object.entries(data).map(([key, value]) => {
|
|
|
46 |
if (value) formData.append(key, value);
|
|
|
47 |
});
|
|
|
48 |
await axios
|
|
|
49 |
.post("/account-settings/notification", formData)
|
|
|
50 |
.then((response) => {
|
|
|
51 |
const resData = response.data;
|
|
|
52 |
if (resData.success) {
|
|
|
53 |
addNotification({
|
|
|
54 |
style: "success",
|
|
|
55 |
msg: resData.data,
|
|
|
56 |
});
|
|
|
57 |
} else {
|
|
|
58 |
const errorMessage =
|
|
|
59 |
typeof resData.data === "string"
|
|
|
60 |
? resData.data
|
|
|
61 |
: "Ha ocurrido un error, Por favor intente mas tarde";
|
|
|
62 |
addNotification({
|
|
|
63 |
style: "danger",
|
|
|
64 |
msg: errorMessage,
|
|
|
65 |
});
|
|
|
66 |
}
|
|
|
67 |
});
|
|
|
68 |
setLoading(false);
|
|
|
69 |
};
|
|
|
70 |
|
|
|
71 |
useEffect(async () => {
|
|
|
72 |
setLoading(true);
|
|
|
73 |
await axios.get("/account-settings/notification").then((response) => {
|
|
|
74 |
const resData = response.data;
|
|
|
75 |
if (resData.success) {
|
|
|
76 |
Object.entries(resData.data).map(([key, value]) => {
|
|
|
77 |
setValue(key, value);
|
|
|
78 |
});
|
|
|
79 |
}
|
|
|
80 |
});
|
|
|
81 |
setLoading(false);
|
|
|
82 |
}, []);
|
|
|
83 |
|
|
|
84 |
return (
|
|
|
85 |
<StyledSettings className="acc-setting">
|
|
|
86 |
<h3>Notificationes</h3>
|
|
|
87 |
<form onSubmit={handleSubmit(handleOnSubmit)}>
|
|
|
88 |
<div className="notbat">
|
|
|
89 |
Cuando recibo una solicitud de conexión
|
|
|
90 |
<SwitchInput register={register} name="receive_connection_request" />
|
|
|
91 |
</div>
|
|
|
92 |
<div className="notbat">
|
|
|
93 |
Cuando aceptan mi solicitud de conexión
|
|
|
94 |
<SwitchInput
|
|
|
95 |
register={register}
|
|
|
96 |
name="accept_my_request_connection"
|
|
|
97 |
/>
|
|
|
98 |
</div>
|
|
|
99 |
<div className="notbat">
|
|
|
100 |
Cuando recibo una solicitud para unirme a un grupo
|
|
|
101 |
<SwitchInput register={register} name="receive_invitation_group" />
|
|
|
102 |
</div>
|
|
|
103 |
<div className="notbat">
|
|
|
104 |
Cuando aceptan mi solicitud para unirme a un grupo
|
|
|
105 |
<SwitchInput
|
|
|
106 |
register={register}
|
|
|
107 |
name="accept_my_request_join_group"
|
|
|
108 |
/>
|
|
|
109 |
</div>
|
|
|
110 |
<div className="notbat">
|
|
|
111 |
Cuando recibo una solicitud para unirme a una empresa
|
|
|
112 |
<SwitchInput register={register} name="receive_invitation_company" />
|
|
|
113 |
</div>
|
|
|
114 |
<div className="notbat">
|
|
|
115 |
Cuando le dan me gusta a una de mis publicaciones
|
|
|
116 |
<SwitchInput register={register} name="like_my_feed" />
|
|
|
117 |
</div>
|
|
|
118 |
<div className="notbat">
|
|
|
119 |
Cuando comentan una de mis publicaciones
|
|
|
120 |
<SwitchInput register={register} name="comment_my_feed" />
|
|
|
121 |
</div>
|
|
|
122 |
<div className="notbat">
|
|
|
123 |
Cuando comparten una de mis publicaciones
|
|
|
124 |
<SwitchInput register={register} name="share_my_feed" />
|
|
|
125 |
</div>
|
|
|
126 |
<div className="notbat">
|
|
|
127 |
Cuando recibo un mensaje
|
|
|
128 |
<SwitchInput register={register} name="receive_inmail" />
|
|
|
129 |
</div>
|
|
|
130 |
{/* <div className="notbat">
|
|
|
131 |
Cuando recibo una invitación a una conferencia
|
|
|
132 |
<SwitchInput register={register} name="receive_invitation_meeting" />
|
|
|
133 |
</div>
|
|
|
134 |
<div className="notbat">
|
|
|
135 |
Cuando esta próxima la conferencia
|
|
|
136 |
<SwitchInput register={register} name="receive_reminder_meeting" />
|
|
|
137 |
</div>
|
|
|
138 |
<div className="notbat">
|
|
|
139 |
Cuando esten disponible los archivos de una conferencia
|
|
|
140 |
<SwitchInput
|
|
|
141 |
register={register}
|
|
|
142 |
name="receive_records_available_meeting"
|
|
|
143 |
/>
|
|
|
144 |
</div> */}
|
|
|
145 |
<div className="notbat">
|
|
|
146 |
Cuando recibo una solicitud para unirse a mi grupo
|
|
|
147 |
<SwitchInput
|
|
|
148 |
register={register}
|
|
|
149 |
name="receive_request_join_my_group"
|
|
|
150 |
/>
|
|
|
151 |
</div>
|
|
|
152 |
<div className="save-stngs pd2">
|
|
|
153 |
<ul>
|
|
|
154 |
<li>
|
|
|
155 |
<button type="submit" className="btn-save-basic">
|
|
|
156 |
Guardar
|
|
|
157 |
</button>
|
|
|
158 |
</li>
|
|
|
159 |
</ul>
|
|
|
160 |
</div>
|
|
|
161 |
{/* <!--save-stngs end--> */}
|
|
|
162 |
{/* <?php echo $this->form()->closeTag($form); ?> */}
|
|
|
163 |
</form>
|
|
|
164 |
{loading && (
|
|
|
165 |
<StyledSpinnerContainer>
|
|
|
166 |
<Spinner />
|
|
|
167 |
</StyledSpinnerContainer>
|
|
|
168 |
)}
|
|
|
169 |
</StyledSettings>
|
|
|
170 |
);
|
|
|
171 |
};
|
|
|
172 |
|
|
|
173 |
// const mapStateToProps = (state) => ({
|
|
|
174 |
|
|
|
175 |
// })
|
|
|
176 |
|
|
|
177 |
const mapDispatchToProps = {
|
|
|
178 |
addNotification: (notification) => addNotification(notification),
|
|
|
179 |
};
|
|
|
180 |
|
|
|
181 |
export default connect(null, mapDispatchToProps)(Notifications);
|