1
- import React , { useState } from "react" ;
1
+ import React , { useEffect , useState } from "react" ;
2
2
import style from "./edit.module.scss" ;
3
- import { Button2 } from "../../../../../components/util/Button/index" ;
4
- import SunEditor from "suneditor-react" ;
5
- import "suneditor/dist/css/suneditor.min.css" ;
6
- import { SimpleToast } from "../../../../../components/util/Toast" ;
7
- import { UpdateBoardCast } from "../../../../../service/Broadcast.jsx" ;
3
+ import { TextField } from "@material-ui/core" ;
4
+ import CloseIcon from "@material-ui/icons/Close" ;
8
5
9
6
export function Edit ( props ) {
10
- const [ toast , setToast ] = useState ( {
11
- toastStatus : false ,
12
- toastType : "" ,
13
- toastMessage : "" ,
14
- } ) ;
7
+ const [ a , seta ] = useState ( ) ;
8
+ function scrolls ( ) {
9
+ let b = window . scrollY ;
10
+ seta ( b ) ;
11
+ }
12
+ useEffect ( ( ) => {
13
+ window . addEventListener ( "scroll" , scrolls ) ;
14
+ } , [ ] ) ;
15
15
16
- const handleCloseToast = ( event , reason ) => {
17
- if ( reason === "clickaway" ) {
18
- return ;
19
- }
20
- setToast ( { ...toast , toastStatus : false } ) ;
21
- props . setVisible ( false ) ;
22
- } ;
23
-
24
- const handleInputChange = ( e ) => {
25
- const { name, value } = e . target ;
26
- props . handleChange ( { target : { name, value } } ) ;
27
- } ;
28
-
29
- const handleContentChange = ( content ) => {
30
- props . handleChange ( { target : { name : 'content' , value : content } } ) ;
31
- } ;
32
-
33
- const handleSubmit = async ( e ) => {
34
- e . preventDefault ( ) ;
35
- const { data } = props ;
36
- const newData = {
37
- id : data . _id ,
38
- content :data . content ,
39
- link : data . link ,
40
- expiresOn : data . expiresOn ,
41
- imageUrl : data . imageUrl ,
42
- tags : data . tags ,
43
- isApproved : data . isApproved ,
44
- title : data . title ,
45
- } ;
46
-
47
- try {
48
- await UpdateBoardCast ( newData , setToast , toast ) ;
49
- setToast ( {
50
- toastStatus : true ,
51
- toastType : "success" ,
52
- toastMessage : "Broadcast updated successfully!" ,
53
- } ) ;
54
- } catch ( error ) {
55
- console . error ( "Error updating broadcast:" , error ) ;
56
- setToast ( {
57
- toastStatus : true ,
58
- toastType : "error" ,
59
- toastMessage : "Failed to update broadcast. Please try again." ,
60
- } ) ;
61
- }
62
- } ;
63
-
64
- const { visible, data} = props ;
65
16
let dark = props . theme ;
66
-
67
- return visible ? (
68
- < div className = { style [ "popup" ] } >
69
- < div className = {
70
- dark
71
- ? `${ style [ "card" ] } ${ style [ "card-dark" ] } `
72
- : `${ style [ "card" ] } ${ style [ "card-light" ] } `
73
- } >
74
- < form className = { style [ "editor" ] } onSubmit = { handleSubmit } >
75
- < div className = { style [ "motive" ] } >
76
- < h1 className = {
77
- dark
78
- ? `${ style [ "header-text" ] } ${ style [ "header-text-dark" ] } `
79
- : `${ style [ "header-text" ] } ${ style [ "header-text-light" ] } `
80
- } > Edit Broadcast</ h1 >
81
- < div className = {
82
- dark
83
- ? `${ style . dash } ${ style [ "dash-dark" ] } `
84
- : `${ style . dash } ${ style [ "dash-light" ] } `
85
- } />
86
- </ div >
87
- < div >
88
- < div className = {
89
- dark
90
- ? `${ style [ "input" ] } ${ style [ "input-dark" ] } `
91
- : `${ style [ "input" ] } ${ style [ "input-light" ] } `
92
- } >
93
- < input
94
- type = "text"
95
- name = "title"
96
- // className={style["form-control-input"]}
97
- placeholder = "Title"
98
- value = { data . title }
99
- onChange = { handleInputChange }
100
- />
101
- < i className = "fas fa-pencil-alt" />
102
- </ div >
103
- </ div >
104
- < div >
105
- < div className = {
106
- dark
107
- ? `${ style [ "input" ] } ${ style [ "input-dark" ] } `
108
- : `${ style [ "input" ] } ${ style [ "input-light" ] } `
109
- } >
110
- < SunEditor
111
- name = "content"
112
- placeholder = "Description"
113
- setContents = { data . content }
114
- onChange = { handleContentChange }
115
- height = "100px"
116
- className = { style [ "edit" ] }
117
- onSetContents = { ( content ) =>
118
- handleInputChange ( { target : { name : "content" , value : content } } )
119
- }
120
- />
121
- </ div >
122
- </ div >
123
- < div >
124
- < div className = {
125
- dark
126
- ? `${ style [ "input" ] } ${ style [ "input-dark" ] } `
127
- : `${ style [ "input" ] } ${ style [ "input-light" ] } `
128
- } >
129
- < input
130
- type = "text"
131
- name = "link"
132
- placeholder = "Resource Link"
133
- value = { data . link }
134
- onChange = { handleInputChange }
135
- />
136
- < i className = "fas fa-link" />
137
- </ div >
17
+ return props . visible ? (
18
+ < div className = { style [ "popup" ] } style = { { top : a } } >
19
+ < div className = { dark ? style [ "div-dark" ] : style [ "div" ] } >
20
+ < h1 className = { style [ "heading" ] } >
21
+ Edit modal
22
+ < CloseIcon
23
+ style = { { float : "right" , cursor : "pointer" } }
24
+ onClick = { ( ) => props . setVisible ( false ) }
25
+ />
26
+ </ h1 >
27
+ < form >
28
+ < div className = { style [ "form" ] } >
29
+ < h5 > Title:</ h5 >
30
+ < TextField
31
+ type = "text"
32
+ name = "title"
33
+ placeholder = "Title"
34
+ multiline
35
+ value = { props . data . title }
36
+ className = { style [ "input" ] }
37
+ InputProps = { {
38
+ className : `${ dark ? style [ "input-dark" ] : "" } ` ,
39
+ } }
40
+ onChange = { props . handleChange }
41
+ />
138
42
</ div >
139
- < div className = { style [ "submit-btn" ] } >
140
- < Button2
141
- className = { style [ "submit-btn-text" ] }
142
- label = "Update"
143
- type = "submit"
43
+ < div className = { style . form } >
44
+ < h5 > Description:</ h5 >
45
+ < TextField
46
+ type = "text"
47
+ name = "desc"
48
+ multiline
49
+ placeholder = "Description"
50
+ value = { props . data . desc }
51
+ className = { style [ "input" ] }
52
+ InputProps = { {
53
+ className : `${ dark ? style [ "input-dark" ] : "" } ` ,
54
+ } }
55
+ onChange = { props . handleChange }
144
56
/>
145
- < Button2
146
- className = { style [ "submit-btn-text" ] }
147
- label = "Cancel"
148
- type = "button"
149
- onClick = { ( ) => props . setVisible ( false ) }
57
+ </ div >
58
+ < div className = { style . form } >
59
+ < h5 > Link:</ h5 >
60
+ < TextField
61
+ type = "text"
62
+ name = "link"
63
+ placeholder = "Link"
64
+ className = { style [ "input" ] }
65
+ InputProps = { {
66
+ className : `${ dark ? style [ "input-dark" ] : "" } ` ,
67
+ } }
68
+ onChange = { props . handleChange }
69
+ value = { props . data . link }
70
+ multiline
150
71
/>
151
72
</ div >
73
+ < button
74
+ className = { style [ "btns1" ] }
75
+ onClick = { ( ) => props . setVisible ( false ) }
76
+ >
77
+ Edit
78
+ </ button >
152
79
</ form >
153
80
</ div >
154
- { toast . toastStatus && (
155
- < div className = { style [ "toast-overlay" ] } >
156
- < SimpleToast
157
- open = { toast . toastStatus }
158
- message = { toast . toastMessage }
159
- handleCloseToast = { handleCloseToast }
160
- severity = { toast . toastType }
161
- />
162
- </ div >
163
- ) }
164
81
</ div >
165
82
) : null ;
166
- }
83
+ }
0 commit comments