Skip to content

Commit

Permalink
fix(project): demo config reset doesnt work (#609)
Browse files Browse the repository at this point in the history
refactor(project): remove unnecessary form target
refactor(project): update snapshot
  • Loading branch information
royschut authored Sep 27, 2024
1 parent 5231d86 commit 003e3e5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
21 changes: 3 additions & 18 deletions platforms/web/src/components/DemoConfigDialog/DemoConfigDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { type ChangeEventHandler, type MouseEventHandler, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { type NavigateFunction, useNavigate } from 'react-router';
import { Helmet } from 'react-helmet';
import { createURL } from '@jwp/ott-common/src/utils/urlFormatting';
import { CONFIG_QUERY_KEY } from '@jwp/ott-common/src/constants';
Expand All @@ -12,6 +11,7 @@ import LoadingOverlay from '@jwp/ott-ui-react/src/components/LoadingOverlay/Load
import DevStackTrace from '@jwp/ott-ui-react/src/components/DevStackTrace/DevStackTrace';
import type { BootstrapData } from '@jwp/ott-hooks-react/src/useBootstrapApp';
import { AppError } from '@jwp/ott-common/src/utils/error';
import { PATH_HOME } from '@jwp/ott-common/src/paths';

import styles from './DemoConfigDialog.module.scss';

Expand All @@ -32,26 +32,11 @@ const initialState: State = {
loaded: false,
};

export function getConfigNavigateCallback(navigate: NavigateFunction) {
return (configSource: string) => {
navigate(
{
pathname: '/',
search: new URLSearchParams([[CONFIG_QUERY_KEY, configSource]]).toString(),
},
{ replace: true },
);
};
}

const DemoConfigDialog = ({ query }: { query: BootstrapData }) => {
const { data, isLoading, error, refetch, isSuccess } = query;
const { configSource: selectedConfigSource } = data || {};

const { t } = useTranslation('demo');
const navigate = useNavigate();
const navigateCallback = getConfigNavigateCallback(navigate);

const [state, setState] = useState<State>(initialState);

const errorTitle = error && error instanceof AppError ? error.payload.title : '';
Expand Down Expand Up @@ -91,7 +76,7 @@ const DemoConfigDialog = ({ query }: { query: BootstrapData }) => {

const clearConfig = () => {
setState(initialState);
navigateCallback('');
window.location.href = createURL(PATH_HOME, { [CONFIG_QUERY_KEY]: '' });
};

const isValidSource = (configSource: string) => configSource.match(regex)?.some((m) => m === configSource);
Expand Down Expand Up @@ -170,7 +155,7 @@ const DemoConfigDialog = ({ query }: { query: BootstrapData }) => {
helpLink={'https://docs.jwplayer.com/platform/docs/ott-create-an-app-config'}
error={typeof state.error === 'string' ? undefined : state.error}
>
<form method={'GET'} target={'/'}>
<form method={'GET'}>
<TextField
required
disabled={isLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ exports[`<DemoConfigDialog> > renders and matches snapshot error dialog 1`] = `
</p>
<form
method="GET"
target="/"
>
<div
class="_formField_a245e1 _textField_0fa545 _maxWidth_561a54"
Expand Down

0 comments on commit 003e3e5

Please sign in to comment.