Skip to content

Commit

Permalink
add TestAlert button to PaymentAlertsSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
stCarolas committed May 25, 2024
1 parent 5f16189 commit 73b5c64
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 51 deletions.
1 change: 0 additions & 1 deletion src/components/ConfigurationPage/css/WidgetButton.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
font-size: 16px;
font-weight: 400;
height: 40px;
width: 40px;
outline: none;
outline: 0;
text-align: center;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import axios from "axios";
import ColorPicker from "./ColorPicker";
import BaseSettings from "./BaseSettings";
import BooleanPropertyInput from "./properties/BooleanPropertyInput";
import TestAlertButton from "./TestAlertButton";

interface PaymentAlertSettingsProps {
id: string;
Expand Down Expand Up @@ -59,6 +60,7 @@ export default function PaymentAlertSettings({
const [tab, setTab] = useState("trigger");
const [selected, setSelected] = useState<number>(-2);
const { config, setConfig } = useContext(WidgetsContext);
const [showTestAlert, setShowTestAlert] = useState<boolean>(false);

function addDefaultAlert(): void {
let alerts = config.get(id)?.alerts;
Expand Down Expand Up @@ -272,7 +274,7 @@ export default function PaymentAlertSettings({
const handleFileChange = (e: ChangeEvent<HTMLInputElement>) => {
if (e.target.files) {
const file = e.target.files[0];
const name = file.name.replace(/[^0-9a-z\.]/gi, '');
const name = file.name.replace(/[^0-9a-z\.]/gi, "");
uploadFile(file, name).then((ignore) => {
setConfig((oldConfig) => {
const alertConfig = oldConfig.get(id);
Expand All @@ -292,7 +294,7 @@ export default function PaymentAlertSettings({
const handleVideoUpload = (e: ChangeEvent<HTMLInputElement>) => {
if (e.target.files) {
const file = e.target.files[0];
const name = file.name.replace(/[^0-9a-z\.]/gi, '');
const name = file.name.replace(/[^0-9a-z\.]/gi, "");
uploadFile(file, name).then((ignore) => {
setConfig((oldConfig) => {
const alertConfig = oldConfig.get(id);
Expand All @@ -312,7 +314,7 @@ export default function PaymentAlertSettings({
const handleAudioUpload = (e: ChangeEvent<HTMLInputElement>) => {
if (e.target.files) {
const file = e.target.files[0];
const name = file.name.replace(/[^0-9a-z\.]/gi, '');
const name = file.name.replace(/[^0-9a-z\.]/gi, "");
uploadFile(file, name).then((ignore) => {
setConfig((oldConfig) => {
const alertConfig = oldConfig.get(id);
Expand Down Expand Up @@ -560,7 +562,7 @@ export default function PaymentAlertSettings({
)}
{"image" === tab && (
<div className="upload-button-container">
<label className="upload-button" style={{marginRight: "10px"}}>
<label className="upload-button" style={{ marginRight: "10px" }}>
<input type="file" onChange={handleVideoUpload} />
Загрузить видео
</label>
Expand Down Expand Up @@ -593,7 +595,8 @@ export default function PaymentAlertSettings({

return (
<>
<BaseSettings id={id}/>
<TestAlertButton config={config}/>
<BaseSettings id={id} />
{previews()}
{selected > -1 && (
<div className="payment-alert-settings">
Expand Down
79 changes: 79 additions & 0 deletions src/components/ConfigurationPage/settings/TestAlertButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React, { useState } from "react";
import PopupComponent from "../../Popup/PopupComponent";
import { publish } from "../../../socket";
import { log } from "../../../logging";
import { Config } from "../../../config";
import { useLoaderData } from "react-router";
import { WidgetData } from "../../../types/WidgetData";

export default function TestAlertButton({ config }: { config: Config }) {
const [nickname, setNickname] = useState("");
const [message, setMessage] = useState("");
const [amount, setAmount] = useState("");
const { conf } = useLoaderData() as WidgetData;

function sendTestAlert() {
publish(conf.topic.alerts, {
id: "ae7d3c02-209b-4b69-a95b-2a60de4aff9b",
nickname: nickname ? nickname : "Аноним",
message: message ? message : "Тестовое сообщение",
amount: {
major: amount ? parseInt(amount) : 40,
minor: 0,
currency: "RUB",
},
});
log.debug("Send test alert");
}
return (
<>
<PopupComponent buttonText="Тестовый алерт">
<div>
<div className="test-alert-field-container">
<div className="test-alert-field-label">Nickname</div>
<input
value={nickname}
placeholder="Аноним"
autoComplete="off"
onChange={(e) => {
setNickname(e.target.value);
}}
/>
</div>
<div className="test-alert-field-container">
<div className="test-alert-field-label">Message</div>
<textarea
value={message}
placeholder="Тестовое сообщение"
autoComplete="off"
onChange={(e) => {
setMessage(e.target.value);
}}
/>
</div>
<div className="test-alert-field-container">
<div className="test-alert-field-label">Amount</div>
<input
value={amount}
placeholder="40"
autoComplete="off"
onChange={(e) => {
setAmount(e.target.value);
}}
/>
</div>
<div className="test-alert-buttons">
<button
className="btn btn-dark"
onClick={() => {
sendTestAlert();
}}
>
Test alert
</button>
</div>
</div>
</PopupComponent>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
}

.button {
width: unset!important;
margin-bottom: 10px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export class DonationGoalProperty extends DefaultWidgetProperty {
<div style={{ textAlign: "right" }}>
<button
className="widget-button"
style={{ width: "unset" }}
onClick={(e) => {
this.deleteGoal(updateConfig, index);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ReelItemListProperty extends DefaultWidgetProperty {
updateConfig(this.widgetId, "optionList", updated);
}

copy(){
copy() {
return new ReelItemListProperty(this.widgetId, this.value);
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/MediaWidget/AddMediaPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { useLoaderData } from "react-router";
import { log } from "../../logging";
import { Playlist } from "../../logic/playlist/Playlist";
import { Song } from "./types";
import { WidgetData } from "../../types/WidgetData";

export default function AddMediaPopup({ playlist }: { playlist: Playlist }) {
const [showNewMediaPopup, setShowNewMediaPopup] = useState(false);
const [savedPlaylists, setSavedPlaylists] = useState<Playlist[]>([]);
const { recipientId } = useLoaderData();
const { recipientId } = useLoaderData() as WidgetData;

useEffect(() => {
function toggle() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Payments/Payments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function Payments({}: {}) {
}}
/>
<div style={{ marginBottom: "5px", marginLeft: "5px" }}>
<TestAlertPopup config={conf} socket={clientRef.current} />
<TestAlertPopup config={conf}/>
<Menu>
<MenuEventButton
event="toggleSendAlertPopup"
Expand Down
13 changes: 13 additions & 0 deletions src/components/Popup/PopupComponent.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.popup {
position: fixed;
left: 0px;
top: 0px;
height: 100%;
width: 100%;
background: rgba(30, 30, 30, 0.9);
z-index: 3;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
32 changes: 32 additions & 0 deletions src/components/Popup/PopupComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { useState } from "react";
import classes from "./PopupComponent.module.css";

export default function PopupComponent({
children,
buttonText,
}: {
children: React.ReactNode;
buttonText: string;
}) {
const [showPopup, setShowPopup] = useState<boolean>(false);

return (
<>
<button
className={`widget-button`}
onClick={() => setShowPopup(!showPopup)}
>
{buttonText}
</button>
<div
className={`${classes.popup} ${showPopup ? "" : "visually-hidden"}`}
tabIndex={-1}
>
<button id="close-add-media-popup" onClick={() => setShowPopup(false)}>
<span className="material-symbols-sharp">close</span>
</button>
{children}
</div>
</>
);
}

0 comments on commit 73b5c64

Please sign in to comment.