Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Shadow PR for 36320 (external contribution test) #36381

Closed
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ function PageSettings(props: { page: Page }) {

const [pageName, setPageName] = useState(page.pageName);
const [isPageNameSaving, setIsPageNameSaving] = useState(false);
const [isPageNameValid, setIsPageNameValid] = useState<string | undefined>(
undefined,
);
const [pageNameError, setPageNameError] = useState<string | null>(null);

const [customSlug, setCustomSlug] = useState(page.customSlug);
const [isCustomSlugSaving, setIsCustomSlugSaving] = useState(false);
Expand Down Expand Up @@ -126,16 +124,20 @@ function PageSettings(props: { page: Page }) {
}
}, [isUpdatingEntity]);

useEffect(() => {
setPageNameError(null);
}, [page]);

const savePageName = useCallback(() => {
if (!canManagePages || !!isPageNameValid || page.pageName === pageName)
if (!canManagePages || pageNameError !== null || page.pageName === pageName)
return;
const payload: UpdatePageActionPayload = {
id: page.pageId,
name: pageName,
};
setIsPageNameSaving(true);
dispatch(updatePageAction(payload));
}, [page.pageId, page.pageName, pageName, isPageNameValid]);
}, [page.pageId, page.pageName, pageName, pageNameError]);

const saveCustomSlug = useCallback(() => {
if (!canManagePages || page.customSlug === customSlug) return;
Expand All @@ -161,14 +163,14 @@ function PageSettings(props: { page: Page }) {
);

const onPageNameChange = (value: string) => {
let isValid = undefined;
let errorMessage = null;
if (!value || value.trim().length === 0) {
isValid = PAGE_SETTINGS_NAME_EMPTY_MESSAGE();
errorMessage = PAGE_SETTINGS_NAME_EMPTY_MESSAGE();
} else if (value !== page.pageName && hasActionNameConflict(value)) {
isValid = PAGE_SETTINGS_ACTION_NAME_CONFLICT_ERROR(value);
errorMessage = PAGE_SETTINGS_ACTION_NAME_CONFLICT_ERROR(value);
}

setIsPageNameValid(isValid);
setPageNameError(errorMessage);
alex-golovanov marked this conversation as resolved.
Show resolved Hide resolved
setPageName(toValidPageName(value));
};

Expand All @@ -183,13 +185,13 @@ function PageSettings(props: { page: Page }) {
<div
className={classNames({
"pt-1 pb-2 relative": true,
"pb-4": !isPageNameValid,
"pb-4": !pageNameError,
})}
>
{isPageNameSaving && <TextLoaderIcon />}
<Input
defaultValue={pageName}
errorMessage={isPageNameValid}
errorMessage={pageNameError}
id="t--page-settings-name"
isDisabled={!canManagePages}
label={PAGE_SETTINGS_PAGE_NAME_LABEL()}
Expand Down
Loading