Fixed id scrolling when clicking from Store

This commit is contained in:
Lucas Oliveira 2024-06-04 11:52:08 -03:00
commit 98e40f25e6
3 changed files with 36 additions and 31 deletions

View file

@ -41,12 +41,23 @@ import {
} from "../../../../types/components"; } from "../../../../types/components";
import { gradients } from "../../../../utils/styleUtils"; import { gradients } from "../../../../utils/styleUtils";
import { useStoreStore } from "../../../../stores/storeStore"; import { useStoreStore } from "../../../../stores/storeStore";
import { useParams } from "react-router-dom";
export default function GeneralPage() { export default function GeneralPage() {
const setCurrentFlowId = useFlowsManagerStore( const setCurrentFlowId = useFlowsManagerStore(
(state) => state.setCurrentFlowId, (state) => state.setCurrentFlowId,
); );
const { scrollId } = useParams();
useEffect(() => {
const element = document.getElementById(scrollId ?? "null");
if (element) {
// 👇 Will scroll smoothly to the top of the next section
element.scrollIntoView({ behavior: "smooth" });
}
}, [scrollId]);
const [inputState, setInputState] = useState<patchUserInputStateType>( const [inputState, setInputState] = useState<patchUserInputStateType>(
CONTROL_PATCH_USER_STATE, CONTROL_PATCH_USER_STATE,
); );
@ -272,9 +283,9 @@ export default function GeneralPage() {
handleSaveKey(); handleSaveKey();
}} }}
> >
<Card x-chunk="dashboard-04-chunk-2"> <Card x-chunk="dashboard-04-chunk-2" id="api">
<CardHeader> <CardHeader>
<CardTitle>API Key</CardTitle> <CardTitle>Store API Key</CardTitle>
<CardDescription> <CardDescription>
{(hasApiKey && !validApiKey {(hasApiKey && !validApiKey
? INVALID_API_KEY ? INVALID_API_KEY

View file

@ -180,24 +180,21 @@ export default function StorePage(): JSX.Element {
title={STORE_TITLE} title={STORE_TITLE}
description={STORE_DESC} description={STORE_DESC}
button={ button={
<> <Button
{StoreApiKeyModal && ( data-testid="api-key-button-store"
<StoreApiKeyModal disabled={loading}> disabled={loading}
<Button className={cn(
data-testid="api-key-button-store" `${!validApiKey ? "animate-pulse border-error" : ""}`,
disabled={loading} loading ? "cursor-not-allowed" : "",
className={cn(
`${!validApiKey ? "animate-pulse border-error" : ""}`,
loading ? "cursor-not-allowed" : "",
)}
variant="primary"
>
<IconComponent name="Key" className="mr-2 w-4" />
API Key
</Button>
</StoreApiKeyModal>
)} )}
</> variant="primary"
onClick={() => {
navigate("/settings/general/api");
}}
>
<IconComponent name="Key" className="mr-2 w-4" />
API Key
</Button>
} }
> >
<div className="flex h-full w-full flex-col justify-between"> <div className="flex h-full w-full flex-col justify-between">

View file

@ -56,7 +56,7 @@ const Router = () => {
> >
<Route index element={<Navigate replace to={"general"} />} /> <Route index element={<Navigate replace to={"general"} />} />
<Route path="global-variables" element={<GlobalVariablesPage />} /> <Route path="global-variables" element={<GlobalVariablesPage />} />
<Route path="general" element={<GeneralPage />} /> <Route path="general/:scrollId?" element={<GeneralPage />} />
<Route path="shortcuts" element={<ShortcutsPage />} /> <Route path="shortcuts" element={<ShortcutsPage />} />
</Route> </Route>
<Route <Route
@ -80,17 +80,14 @@ const Router = () => {
} }
/> />
<Route path="/playground/:id/"> <Route path="/playground/:id/">
element= <Route
{ path=""
<Route element={
path="" <ProtectedRoute>
element={ <PlaygroundPage />
<ProtectedRoute> </ProtectedRoute>
<PlaygroundPage /> }
</ProtectedRoute> />
}
/>
}
</Route> </Route>
<Route path="/flow/:id/"> <Route path="/flow/:id/">
<Route <Route