Skip to content

Commit

Permalink
add PaymentPageConfig, fix image scaling in alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
stCarolas committed Dec 24, 2023
1 parent fb53bfb commit 3935ebf
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 28 deletions.
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ REACT_APP_RECIPIENT_API_ENDPOINT=http://localhost:8084
REACT_APP_MEDIA_API_ENDPOINT=http://localhost:8085
REACT_APP_LOG_API_ENDPOINT=http://localhost:8000
REACT_APP_WS_ENDPOINT=ws://127.0.0.1:15674/ws
REACT_APP_CDN_ENDPOINT=http://localhost:9000/public
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ REACT_APP_RECIPIENT_API_ENDPOINT=https://widgets.oda.digital
REACT_APP_MEDIA_API_ENDPOINT=https://api.oda.digital
REACT_APP_LOG_API_ENDPOINT=https://api.oda.digital
REACT_APP_WS_ENDPOINT=wss://api.oda.digital/ws
REACT_APP_CDN_ENDPOINT=https://api.oda.digital/images
10 changes: 5 additions & 5 deletions src/components/ConfigurationPage/ConfigurationPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import WidgetConfiguration from "./WidgetConfiguration";
import Toolbar from "./Toolbar";
import Toolbar, { Page } from "./Toolbar";
import { WidgetsContext } from "./WidgetsContext";
import axios from "axios";
import { useLoaderData } from "react-router";
Expand All @@ -9,7 +9,7 @@ import { defaultSettings } from "./WidgetSettings";
const backgroundColor = (
<style
dangerouslySetInnerHTML={{
__html: `html, body {background-color: #0c122e}`,
__html: `html, body {background-color: #0c122e; height: 100%;}`,
}}
/>
);
Expand Down Expand Up @@ -109,9 +109,9 @@ export default function ConfigurationPage({}: {}) {
);

return (
<>
<div className="configuration-container">
{backgroundColor}
<Toolbar />
<Toolbar page={Page.WIDGETS}/>
<div className="widget-list">
<WidgetsContext.Provider value={context}>
{widgets.map((data) => (
Expand Down Expand Up @@ -153,6 +153,6 @@ export default function ConfigurationPage({}: {}) {
</div>
)}
</div>
</>
</div>
);
}
46 changes: 33 additions & 13 deletions src/components/ConfigurationPage/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,48 @@
import React from "react";
import "./css/Toolbar.css";
import { useNavigate } from "react-router";

export default function Toolbar() {
enum Page {
WIDGETS,
GATEWAYS,
PAYMENTPAGE,
}

export default function Toolbar({ page }: { page: Page }) {
const navigate = useNavigate();
return (
<div className="toolbar">
<div className="toolbar-title">
<img className="oda-logo" src={`${process.env.PUBLIC_URL}/favicon.png`}/>
</div>
<button className="toolbar-button">
<span className="material-symbols-sharp">rss_feed</span>
<span className="toolbar-button-title">News</span>
</button>
<button className="toolbar-button active">
<img
className="oda-logo"
src={`${process.env.PUBLIC_URL}/favicon.png`}
/>
</div>
<button
className={`toolbar-button ${page === Page.WIDGETS ? "active" : ""}`}
onClick={() => navigate(`/configuration/widgets`)}
>
<span className="material-symbols-sharp">widgets</span>
<span className="toolbar-button-title">Widgets</span>
</button>
<button className="toolbar-button">
<span className="material-symbols-sharp">credit_card</span>
<span className="toolbar-button-title">Payment Gateways</span>
</button>
<button className="toolbar-button">
<button
className={`toolbar-button ${
page === Page.PAYMENTPAGE ? "active" : ""
}`}
onClick={() => navigate(`/configuration/payment-page`)}
>
<span className="material-symbols-sharp">language</span>
<span className="toolbar-button-title">Donation page</span>
</button>
<button
className={`toolbar-button ${page === Page.GATEWAYS ? "active" : ""}`}
onClick={() => navigate(`/configuration/gateways`)}
>
<span className="material-symbols-sharp">credit_card</span>
<span className="toolbar-button-title">Payment Gateways</span>
</button>
</div>
);
}

export { Page };
4 changes: 2 additions & 2 deletions src/components/ConfigurationPage/css/Toolbar.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.toolbar {
position: fixed;
/* position: fixed; */
height: 100%;
width: 250px;
border-right: 1px solid #674afd;
Expand Down Expand Up @@ -38,7 +38,7 @@

.toolbar-title {
color: white;
margin-top: 20px;
padding-top: 20px;
padding-bottom: 10px;
font-weight: 900;
text-align: center;
Expand Down
6 changes: 3 additions & 3 deletions src/components/ConfigurationPage/css/WidgetList.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.widget-list {
margin-left: 400px;
max-width: 700px;
margin-left: 100px;
margin-right: 100px;
padding-top: 20px;
flex: 1 0 auto;
}

.widget-list-title {
Expand All @@ -11,4 +12,3 @@
width: 200px;
color: #7987bf;
}

5 changes: 5 additions & 0 deletions src/components/ConfigurationPage/css/WidgetSettings.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.configuration-container {
height: 100%;
display: flex;
}

.widget-settings {
margin-top: 10px;
color: white;
Expand Down
1 change: 1 addition & 0 deletions src/components/PaymentAlerts/PaymentAlerts.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ html, body, .PaymentAlerts {
.PaymentAlerts {
display: flex;
flex-direction: column;
justify-content: flex-start;
}
7 changes: 3 additions & 4 deletions src/components/PaymentAlerts/PaymentAlerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,13 @@ function PaymentAlerts({}: {}) {
/>
))}
<div className="PaymentAlerts h-100">
<div className={`${imageWidth && imageHeight ? "text-center" : "image-container"}`}>
{image && (
<img
src={image}
style={calculateImageStyle(imageWidth, imageHeight)}
className="alert-image"
className="alert-image image-container"
/>
)}
</div>
<div className="message">
<div style={headerStyle} className="message-header">
{alert.amount != undefined && alert.amount != null
Expand Down Expand Up @@ -364,7 +362,8 @@ function calculateImageStyle(
height: imageHeight + "px",
}
: {
objectFit: "contain"
objectFit: "fill",
maxWidth: "100%"
};
}

Expand Down
52 changes: 52 additions & 0 deletions src/components/PaymentPageConfig/PaymentPageConfig.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.paymentpageconfig {
color: white;
margin-left: 100px;
margin-right: 100px;
padding-top: 50px;
padding-left: 20px;
padding-right: 20px;
flex: 1 0 auto;
margin-top: 10px;
}

.paymentpage {
height: 100%;
display: flex;
}

.widgetsettingsitem {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}

.widgetsettingsname {
flex: 1 0 auto;
}

.widgetsettingsvalue {
display: inline-block;
width: 120px;
border-radius: 5px;
border: 1px solid #684aff;
background: none;
color: white;
text-align: center;
}

.widgetsettingsvalue:focus-visible,
.widgetsettingsvalue:focus {
outline:none;
}

.backgroundimage {
width: 400px;
height: 300px;
display: inline-block;
flex: 0 0 auto;
border: 1px solid #684aff;
}

.backgroundimage:hover {
cursor:pointer;
}
107 changes: 107 additions & 0 deletions src/components/PaymentPageConfig/PaymentPageConfigComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React, { ChangeEvent, useState } from "react";
import Toolbar, { Page } from "../ConfigurationPage/Toolbar";
import classes from "./PaymentPageConfig.module.css";
import { useLoaderData, useNavigate } from "react-router";
import axios from "axios";

const backgroundColor = (
<style
dangerouslySetInnerHTML={{
__html: `html, body {background-color: #0c122e; height: 100%;}`,
}}
/>
);

function uploadFile(file, name) {
return axios.put(
`${process.env.REACT_APP_FILE_API_ENDPOINT}/files/${name}?public=true`,
{ file: file },
{
headers: {
"Content-Type": "multipart/form-data",
},
},
);
}

export default function PaymentPageConfigComponent({}: {}) {
const { recipientId } = useLoaderData();
const navigate = useNavigate();
const [isRequestsEnabled, setRequestsEnabled] = useState(false);
const handleBackUpload = (e: ChangeEvent<HTMLInputElement>) => {
if (e.target.files) {
const file = e.target.files[0];
console.log(file);
uploadFile(file, `back-${recipientId}.jpg`).then(() => navigate(0));
}
};
const handleLogoUpload = (e: ChangeEvent<HTMLInputElement>) => {
if (e.target.files) {
const file = e.target.files[0];
console.log(file);
uploadFile(file, `logo-${recipientId}.png`).then(() => navigate(0));
}
};

const handleTogglingRequests = (e: ChangeEvent<HTMLSelectElement>) => {
if (e.target.value) {
setRequestsEnabled(e.target.value === "enabled");
}
};

return (
<div className={classes.paymentpage}>
{backgroundColor}
<Toolbar page={Page.PAYMENTPAGE} />
<div className={classes.paymentpageconfig}>
<div className={classes.widgetsettingsitem}>
<div className={classes.widgetsettingsname}>Фоновое изображение</div>
<label className="upload-button">
<input type="file" onChange={handleBackUpload} />
<img
className={classes.backgroundimage}
src={`${
process.env.REACT_APP_CDN_ENDPOINT
}/back-${recipientId}.jpg?random=${Date.now()}`}
/>
</label>
</div>
<div className={classes.widgetsettingsitem}>
<div className={classes.widgetsettingsname}>Логотип канала</div>
<label className="upload-button">
<input type="file" onChange={handleLogoUpload} />
<img
className={classes.backgroundimage}
src={`${
process.env.REACT_APP_CDN_ENDPOINT
}/logo-${recipientId}.png?random=${Date.now()}`}
/>
</label>
</div>
<div className={classes.widgetsettingsitem}>
<div className={classes.widgetsettingsname}>
Реквесты музыки/видео
</div>
<select
value={isRequestsEnabled ? "enabled" : "disabled"}
className="widget-settings-value select"
style={{ width: "120px" }}
onChange={handleTogglingRequests}
>
<option key="enabled">enabled</option>
<option key="disabled">disabled</option>
</select>
</div>
<div className={classes.widgetsettingsitem}>
<div className={classes.widgetsettingsname}>
Стоимость реквестов (за одно видео, в рублях)
</div>
<input
type="number"
className={classes.widgetsettingsvalue}
/>
</div>
</div>
</div>
);
}
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import axios from "axios";
import Login from "./components/Login/Login";
import DonationTimer from "./components/DonationTimer/DonationTimer";
import type { Params } from "react-router-dom";
import PaymentPageConfigComponent from "./components/PaymentPageConfig/PaymentPageConfigComponent";

async function widgetSettingsLoader({
params,
Expand Down Expand Up @@ -68,7 +69,7 @@ const router = createBrowserRouter([
},
{
path: "/configuration/payment-page",
element: <ConfigurationPage />,
element: <PaymentPageConfigComponent/>,
loader: widgetSettingsLoader,
},
{
Expand Down

0 comments on commit 3935ebf

Please sign in to comment.