-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "🍀 Fix Update Broadcast Modal Description Population and Refac…
- Loading branch information
1 parent
223ed8a
commit 18076b8
Showing
4 changed files
with
136 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
223 changes: 70 additions & 153 deletions
223
frontend/src/pages/Broadcast/Component/AllBroadcasts/Edit/Edit.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,166 +1,83 @@ | ||
import React, { useState } from "react"; | ||
import React, { useEffect, useState } from "react"; | ||
import style from "./edit.module.scss"; | ||
import { Button2 } from "../../../../../components/util/Button/index"; | ||
import SunEditor from "suneditor-react"; | ||
import "suneditor/dist/css/suneditor.min.css"; | ||
import { SimpleToast } from "../../../../../components/util/Toast"; | ||
import { UpdateBoardCast } from "../../../../../service/Broadcast.jsx"; | ||
import { TextField } from "@material-ui/core"; | ||
import CloseIcon from "@material-ui/icons/Close"; | ||
|
||
export function Edit(props) { | ||
const [toast, setToast] = useState({ | ||
toastStatus: false, | ||
toastType: "", | ||
toastMessage: "", | ||
}); | ||
const [a, seta] = useState(); | ||
function scrolls() { | ||
let b = window.scrollY; | ||
seta(b); | ||
} | ||
useEffect(() => { | ||
window.addEventListener("scroll", scrolls); | ||
}, []); | ||
|
||
const handleCloseToast = (event, reason) => { | ||
if (reason === "clickaway") { | ||
return; | ||
} | ||
setToast({ ...toast, toastStatus: false }); | ||
props.setVisible(false); | ||
}; | ||
|
||
const handleInputChange = (e) => { | ||
const { name, value } = e.target; | ||
props.handleChange({ target: { name, value } }); | ||
}; | ||
|
||
const handleContentChange = (content) => { | ||
props.handleChange({ target: { name: 'content', value: content } }); | ||
}; | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
const { data } = props; | ||
const newData = { | ||
id: data._id, | ||
content:data.content, | ||
link: data.link, | ||
expiresOn: data.expiresOn, | ||
imageUrl: data.imageUrl, | ||
tags: data.tags, | ||
isApproved: data.isApproved, | ||
title: data.title, | ||
}; | ||
|
||
try { | ||
await UpdateBoardCast(newData,setToast, toast); | ||
setToast({ | ||
toastStatus: true, | ||
toastType: "success", | ||
toastMessage: "Broadcast updated successfully!", | ||
}); | ||
} catch (error) { | ||
console.error("Error updating broadcast:", error); | ||
setToast({ | ||
toastStatus: true, | ||
toastType: "error", | ||
toastMessage: "Failed to update broadcast. Please try again.", | ||
}); | ||
} | ||
}; | ||
|
||
const { visible, data} = props; | ||
let dark = props.theme; | ||
|
||
return visible ? ( | ||
<div className={style["popup"]}> | ||
<div className={ | ||
dark | ||
? `${style["card"]} ${style["card-dark"]} ` | ||
: `${style["card"]} ${style["card-light"]}` | ||
}> | ||
<form className={style["editor"]} onSubmit={handleSubmit}> | ||
<div className={style["motive"]}> | ||
<h1 className={ | ||
dark | ||
? `${style["header-text"]} ${style["header-text-dark"]} ` | ||
: `${style["header-text"]} ${style["header-text-light"]}` | ||
}>Edit Broadcast</h1> | ||
<div className={ | ||
dark | ||
? `${style.dash} ${style["dash-dark"]}` | ||
: `${style.dash} ${style["dash-light"]}` | ||
} /> | ||
</div> | ||
<div> | ||
<div className={ | ||
dark | ||
? `${style["input"]} ${style["input-dark"]} ` | ||
: `${style["input"]} ${style["input-light"]}` | ||
}> | ||
<input | ||
type="text" | ||
name="title" | ||
// className={style["form-control-input"]} | ||
placeholder="Title" | ||
value={data.title} | ||
onChange={handleInputChange} | ||
/> | ||
<i className="fas fa-pencil-alt" /> | ||
</div> | ||
</div> | ||
<div> | ||
<div className={ | ||
dark | ||
? `${style["input"]} ${style["input-dark"]} ` | ||
: `${style["input"]} ${style["input-light"]}` | ||
}> | ||
<SunEditor | ||
name="content" | ||
placeholder="Description" | ||
setContents={data.content} | ||
onChange={handleContentChange} | ||
height="100px" | ||
className={style["edit"]} | ||
onSetContents={(content) => | ||
handleInputChange({ target: { name: "content", value: content } }) | ||
} | ||
/> | ||
</div> | ||
</div> | ||
<div> | ||
<div className={ | ||
dark | ||
? `${style["input"]} ${style["input-dark"]} ` | ||
: `${style["input"]} ${style["input-light"]}` | ||
}> | ||
<input | ||
type="text" | ||
name="link" | ||
placeholder="Resource Link" | ||
value={data.link} | ||
onChange={handleInputChange} | ||
/> | ||
<i className="fas fa-link" /> | ||
</div> | ||
return props.visible ? ( | ||
<div className={style["popup"]} style={{ top: a }}> | ||
<div className={dark ? style["div-dark"] : style["div"]}> | ||
<h1 className={style["heading"]}> | ||
Edit modal | ||
<CloseIcon | ||
style={{ float: "right", cursor: "pointer" }} | ||
onClick={() => props.setVisible(false)} | ||
/> | ||
</h1> | ||
<form> | ||
<div className={style["form"]}> | ||
<h5>Title:</h5> | ||
<TextField | ||
type="text" | ||
name="title" | ||
placeholder="Title" | ||
multiline | ||
value={props.data.title} | ||
className={style["input"]} | ||
InputProps={{ | ||
className: `${dark ? style["input-dark"] : ""}`, | ||
}} | ||
onChange={props.handleChange} | ||
/> | ||
</div> | ||
<div className={style["submit-btn"]}> | ||
<Button2 | ||
className={style["submit-btn-text"]} | ||
label="Update" | ||
type="submit" | ||
<div className={style.form}> | ||
<h5>Description:</h5> | ||
<TextField | ||
type="text" | ||
name="desc" | ||
multiline | ||
placeholder="Description" | ||
value={props.data.desc} | ||
className={style["input"]} | ||
InputProps={{ | ||
className: `${dark ? style["input-dark"] : ""}`, | ||
}} | ||
onChange={props.handleChange} | ||
/> | ||
<Button2 | ||
className={style["submit-btn-text"]} | ||
label="Cancel" | ||
type="button" | ||
onClick={() => props.setVisible(false)} | ||
</div> | ||
<div className={style.form}> | ||
<h5>Link:</h5> | ||
<TextField | ||
type="text" | ||
name="link" | ||
placeholder="Link" | ||
className={style["input"]} | ||
InputProps={{ | ||
className: `${dark ? style["input-dark"] : ""}`, | ||
}} | ||
onChange={props.handleChange} | ||
value={props.data.link} | ||
multiline | ||
/> | ||
</div> | ||
<button | ||
className={style["btns1"]} | ||
onClick={() => props.setVisible(false)} | ||
> | ||
Edit | ||
</button> | ||
</form> | ||
</div> | ||
{toast.toastStatus && ( | ||
<div className={style["toast-overlay"]}> | ||
<SimpleToast | ||
open={toast.toastStatus} | ||
message={toast.toastMessage} | ||
handleCloseToast={handleCloseToast} | ||
severity={toast.toastType} | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
) : null; | ||
} | ||
} |
Oops, something went wrong.