Skip to content
Merged
Changes from all 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
13 changes: 10 additions & 3 deletions packages/apps/staking/src/components/modals/KVStoreModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Tooltip,
Typography,
} from '@mui/material';
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useRef } from 'react'; // <-- Importa useRef
import { useSnackbar } from '../../providers/SnackProvider';
import BaseModal from './BaseModal';

Expand All @@ -44,6 +44,7 @@ const KVStoreModal: React.FC<Props> = ({
>([]);
const [loading, setLoading] = useState(false);
const { showError } = useSnackbar();
const formContainerRef = useRef<HTMLDivElement | null>(null);

useEffect(() => {
if (open) {
Expand All @@ -54,8 +55,7 @@ const KVStoreModal: React.FC<Props> = ({
setFormData(preparedData);
setPendingChanges([]);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open]);
}, [open, initialData]);

const updatePendingChanges = (key: string, value: string) => {
setPendingChanges((prev) => {
Expand Down Expand Up @@ -125,6 +125,12 @@ const KVStoreModal: React.FC<Props> = ({

const handleAddField = () => {
setFormData((prev) => [...prev, { key: '', value: '' }]);

setTimeout(() => {
formContainerRef.current?.lastElementChild?.scrollIntoView({
behavior: 'smooth',
});
}, 100);
};

const handleSave = async () => {
Expand Down Expand Up @@ -169,6 +175,7 @@ const KVStoreModal: React.FC<Props> = ({
Edit KVStore
</Typography>
<Box
ref={formContainerRef}
sx={{
maxHeight: '400px',
overflowY: 'auto',
Expand Down
Loading