Skip to content

Commit

Permalink
add selecting first tab on setting opening
Browse files Browse the repository at this point in the history
  • Loading branch information
stCarolas committed Mar 20, 2024
1 parent e484cc1 commit 1c6eb93
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/ConfigurationPage/WidgetSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class PaymentsWidgetSettings extends AbstractWidgetSettings {
class PaymentAlertsWidgetSettings extends AbstractWidgetSettings {
public alerts: any[];
constructor(properties: WidgetProperty[], alerts: any[]) {
log.debug({ alerts: alerts}, `creating payment-alerts settings`);
log.debug({ alerts: alerts }, `creating payment-alerts settings`);
super(
properties,
[
Expand Down
1 change: 0 additions & 1 deletion src/components/ConfigurationPage/settings/BaseSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default function BaseSettings({
propertyFilter,
}: {
id: string;
onChange: Function;
customHandler?: Function;
propertyFilter?: (prop: WidgetProperty) => boolean;
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export default function PaymentAlertSettings({

return (
<>
<BaseSettings id={id} onChange={onChange} />
<BaseSettings id={id}/>
{previews()}
{selected > -1 && (
<div className="payment-alert-settings">
Expand Down
19 changes: 17 additions & 2 deletions src/components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useContext, useState } from "react";
import React, { useContext, useEffect, useState } from "react";
import { WidgetsContext } from "../ConfigurationPage/WidgetsContext";
import classes from "./Tabs.module.css";
import { log } from "../../logging";

export default function Tabs({
widgetId,
Expand All @@ -9,8 +10,22 @@ export default function Tabs({
widgetId: string;
onChange: (tab: string) => void;
}) {
const [tab, setTab] = useState<string>("");
const { config } = useContext(WidgetsContext);
const [tab, setTab] = useState<string>("");

useEffect(() => {
const settings = config.get(widgetId);
log.debug({settings: settings},"trying to find first tab");
if (!settings) {
return;
}
const firstTab = settings.tabDescriptions.keys().next();
if (firstTab) {
log.debug({ tab: firstTab.value }, "settings first tab");
onChange(firstTab.value);
setTab(firstTab.value);
}
},[config]);

const tabs = () => {
const settings = config.get(widgetId);
Expand Down

0 comments on commit 1c6eb93

Please sign in to comment.