mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
Refactor contexts. Do not share reload in interface
This commit is contained in:
parent
b9d0dd4c20
commit
83e08ca7fc
|
@ -11,7 +11,6 @@ interface IAuthContext {
|
||||||
logout: (callback?: DataCallback) => void
|
logout: (callback?: DataCallback) => void
|
||||||
signup: (data: IUserSignupData, callback?: DataCallback<IUserProfile>) => void
|
signup: (data: IUserSignupData, callback?: DataCallback<IUserProfile>) => void
|
||||||
updatePassword: (data: IUserUpdatePassword, callback?: () => void) => void
|
updatePassword: (data: IUserUpdatePassword, callback?: () => void) => void
|
||||||
reload: (callback?: () => void) => void
|
|
||||||
loading: boolean
|
loading: boolean
|
||||||
error: ErrorInfo
|
error: ErrorInfo
|
||||||
setError: (error: ErrorInfo) => void
|
setError: (error: ErrorInfo) => void
|
||||||
|
@ -40,7 +39,7 @@ export const AuthState = ({ children }: AuthStateProps) => {
|
||||||
const reload = useCallback(
|
const reload = useCallback(
|
||||||
(callback?: () => void) => {
|
(callback?: () => void) => {
|
||||||
getAuth({
|
getAuth({
|
||||||
onError: () => { setUser(undefined); },
|
onError: () => setUser(undefined),
|
||||||
onSuccess: currentUser => {
|
onSuccess: currentUser => {
|
||||||
if (currentUser.id) {
|
if (currentUser.id) {
|
||||||
setUser(currentUser);
|
setUser(currentUser);
|
||||||
|
@ -58,7 +57,7 @@ export const AuthState = ({ children }: AuthStateProps) => {
|
||||||
data: data,
|
data: data,
|
||||||
showError: true,
|
showError: true,
|
||||||
setLoading: setLoading,
|
setLoading: setLoading,
|
||||||
onError: error => { setError(error); },
|
onError: error => setError(error),
|
||||||
onSuccess: newData => reload(() => {
|
onSuccess: newData => reload(() => {
|
||||||
if (callback) callback(newData);
|
if (callback) callback(newData);
|
||||||
})
|
})
|
||||||
|
@ -81,8 +80,10 @@ export const AuthState = ({ children }: AuthStateProps) => {
|
||||||
data: data,
|
data: data,
|
||||||
showError: true,
|
showError: true,
|
||||||
setLoading: setLoading,
|
setLoading: setLoading,
|
||||||
onError: error => { setError(error); },
|
onError: error => setError(error),
|
||||||
onSuccess: newData => reload(() => { if (callback) callback(newData); })
|
onSuccess: newData => reload(() => {
|
||||||
|
if (callback) callback(newData);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,13 +94,12 @@ export const AuthState = ({ children }: AuthStateProps) => {
|
||||||
data: data,
|
data: data,
|
||||||
showError: true,
|
showError: true,
|
||||||
setLoading: setLoading,
|
setLoading: setLoading,
|
||||||
onError: error => { setError(error); },
|
onError: error => setError(error),
|
||||||
onSuccess: () => {
|
onSuccess: () => reload(() => {
|
||||||
setUser(undefined);
|
|
||||||
reload();
|
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
}});
|
})
|
||||||
}, [setUser, reload]);
|
});
|
||||||
|
}, [reload]);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
reload();
|
reload();
|
||||||
|
@ -107,7 +107,7 @@ export const AuthState = ({ children }: AuthStateProps) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthContext.Provider
|
<AuthContext.Provider
|
||||||
value={{ user, login, logout, signup, loading, error, reload, setError, updatePassword }}
|
value={{ user, login, logout, signup, loading, error, setError, updatePassword }}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</AuthContext.Provider>
|
</AuthContext.Provider>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { ErrorInfo } from '../components/BackendError';
|
import { ErrorInfo } from '../components/BackendError';
|
||||||
import { DataCallback, getLibrary, postNewRSForm } from '../utils/backendAPI';
|
import { DataCallback, deleteRSForm, getLibrary, postCloneRSForm, postNewRSForm } from '../utils/backendAPI';
|
||||||
import { ILibraryFilter, IRSFormCreateData, IRSFormMeta, matchRSFormMeta } from '../utils/models';
|
import { ILibraryFilter, IRSFormCreateData, IRSFormData, IRSFormMeta, matchRSFormMeta } from '../utils/models';
|
||||||
import { useAuth } from './AuthContext';
|
import { useAuth } from './AuthContext';
|
||||||
|
|
||||||
interface ILibraryContext {
|
interface ILibraryContext {
|
||||||
|
@ -12,9 +12,10 @@ interface ILibraryContext {
|
||||||
error: ErrorInfo
|
error: ErrorInfo
|
||||||
setError: (error: ErrorInfo) => void
|
setError: (error: ErrorInfo) => void
|
||||||
|
|
||||||
reload: (callback?: () => void) => void
|
|
||||||
filter: (params: ILibraryFilter) => IRSFormMeta[]
|
filter: (params: ILibraryFilter) => IRSFormMeta[]
|
||||||
createSchema: (data: IRSFormCreateData, callback?: DataCallback<IRSFormMeta>) => void
|
createSchema: (data: IRSFormCreateData, callback?: DataCallback<IRSFormMeta>) => void
|
||||||
|
cloneSchema: (target:number, data: IRSFormCreateData, callback: DataCallback<IRSFormData>) => void
|
||||||
|
destroySchema: (target: number, callback?: () => void) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const LibraryContext = createContext<ILibraryContext | null>(null)
|
const LibraryContext = createContext<ILibraryContext | null>(null)
|
||||||
|
@ -88,10 +89,40 @@ export const LibraryState = ({ children }: LibraryStateProps) => {
|
||||||
});
|
});
|
||||||
}, [reload]);
|
}, [reload]);
|
||||||
|
|
||||||
|
const destroySchema = useCallback(
|
||||||
|
(target: number, callback?: () => void) => {
|
||||||
|
setError(undefined)
|
||||||
|
deleteRSForm(String(target), {
|
||||||
|
showError: true,
|
||||||
|
setLoading: setProcessing,
|
||||||
|
onError: error => setError(error),
|
||||||
|
onSuccess: () => reload(() => {
|
||||||
|
if (callback) callback();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}, [setError, reload]);
|
||||||
|
|
||||||
|
const cloneSchema = useCallback(
|
||||||
|
(target: number, data: IRSFormCreateData, callback: DataCallback<IRSFormData>) => {
|
||||||
|
if (!user) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setError(undefined)
|
||||||
|
postCloneRSForm(String(target), {
|
||||||
|
data: data,
|
||||||
|
showError: true,
|
||||||
|
setLoading: setProcessing,
|
||||||
|
onError: error => setError(error),
|
||||||
|
onSuccess: newSchema => reload(() => {
|
||||||
|
if (callback) callback(newSchema);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}, [reload, setError, user]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LibraryContext.Provider value={{
|
<LibraryContext.Provider value={{
|
||||||
items, loading, processing, error, setError,
|
items, loading, processing, error, setError,
|
||||||
reload, filter, createSchema
|
filter, createSchema, cloneSchema, destroySchema
|
||||||
}}>
|
}}>
|
||||||
{ children }
|
{ children }
|
||||||
</LibraryContext.Provider>
|
</LibraryContext.Provider>
|
||||||
|
|
|
@ -4,18 +4,17 @@ import { toast } from 'react-toastify'
|
||||||
import { type ErrorInfo } from '../components/BackendError'
|
import { type ErrorInfo } from '../components/BackendError'
|
||||||
import { useRSFormDetails } from '../hooks/useRSFormDetails'
|
import { useRSFormDetails } from '../hooks/useRSFormDetails'
|
||||||
import {
|
import {
|
||||||
type DataCallback, deleteRSForm, getTRSFile,
|
type DataCallback, getTRSFile,
|
||||||
patchConstituenta, patchDeleteConstituenta,
|
patchConstituenta, patchDeleteConstituenta,
|
||||||
patchMoveConstituenta, patchResetAliases, patchRSForm,
|
patchMoveConstituenta, patchResetAliases, patchRSForm,
|
||||||
patchUploadTRS, postClaimRSForm, postCloneRSForm, postNewConstituenta
|
patchUploadTRS, postClaimRSForm, postNewConstituenta
|
||||||
} from '../utils/backendAPI'
|
} from '../utils/backendAPI'
|
||||||
import {
|
import {
|
||||||
IConstituentaList, IConstituentaMeta, ICstCreateData,
|
IConstituentaList, IConstituentaMeta, ICstCreateData,
|
||||||
ICstMovetoData, ICstUpdateData, IRSForm, IRSFormCreateData,
|
ICstMovetoData, ICstUpdateData, IRSForm,
|
||||||
IRSFormData, IRSFormMeta, IRSFormUpdateData, IRSFormUploadData
|
IRSFormMeta, IRSFormUpdateData, IRSFormUploadData
|
||||||
} from '../utils/models'
|
} from '../utils/models'
|
||||||
import { useAuth } from './AuthContext'
|
import { useAuth } from './AuthContext'
|
||||||
import { useLibrary } from './LibraryContext'
|
|
||||||
|
|
||||||
interface IRSFormContext {
|
interface IRSFormContext {
|
||||||
schema?: IRSForm
|
schema?: IRSForm
|
||||||
|
@ -36,11 +35,10 @@ interface IRSFormContext {
|
||||||
toggleTracking: () => void
|
toggleTracking: () => void
|
||||||
|
|
||||||
update: (data: IRSFormUpdateData, callback?: DataCallback<IRSFormMeta>) => void
|
update: (data: IRSFormUpdateData, callback?: DataCallback<IRSFormMeta>) => void
|
||||||
destroy: (callback?: () => void) => void
|
|
||||||
claim: (callback?: DataCallback<IRSFormMeta>) => void
|
claim: (callback?: DataCallback<IRSFormMeta>) => void
|
||||||
download: (callback: DataCallback<Blob>) => void
|
download: (callback: DataCallback<Blob>) => void
|
||||||
upload: (data: IRSFormUploadData, callback: () => void) => void
|
upload: (data: IRSFormUploadData, callback: () => void) => void
|
||||||
clone: (data: IRSFormCreateData, callback: DataCallback<IRSFormData>) => void
|
|
||||||
resetAliases: (callback: () => void) => void
|
resetAliases: (callback: () => void) => void
|
||||||
|
|
||||||
cstCreate: (data: ICstCreateData, callback?: DataCallback<IConstituentaMeta>) => void
|
cstCreate: (data: ICstCreateData, callback?: DataCallback<IConstituentaMeta>) => void
|
||||||
|
@ -69,7 +67,6 @@ export const RSFormState = ({ schemaID, children }: RSFormStateProps) => {
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const { schema, reload, error, setError, setSchema, loading } = useRSFormDetails({ target: schemaID });
|
const { schema, reload, error, setError, setSchema, loading } = useRSFormDetails({ target: schemaID });
|
||||||
const [ processing, setProcessing ] = useState(false);
|
const [ processing, setProcessing ] = useState(false);
|
||||||
const library = useLibrary();
|
|
||||||
|
|
||||||
const [ isForceAdmin, setIsForceAdmin ] = useState(false);
|
const [ isForceAdmin, setIsForceAdmin ] = useState(false);
|
||||||
const [ isReadonly, setIsReadonly ] = useState(false);
|
const [ isReadonly, setIsReadonly ] = useState(false);
|
||||||
|
@ -130,21 +127,6 @@ export const RSFormState = ({ schemaID, children }: RSFormStateProps) => {
|
||||||
});
|
});
|
||||||
}, [schemaID, setError, setSchema, schema]);
|
}, [schemaID, setError, setSchema, schema]);
|
||||||
|
|
||||||
const destroy = useCallback(
|
|
||||||
(callback?: () => void) => {
|
|
||||||
setError(undefined)
|
|
||||||
deleteRSForm(schemaID, {
|
|
||||||
showError: true,
|
|
||||||
setLoading: setProcessing,
|
|
||||||
onError: error => setError(error),
|
|
||||||
onSuccess: () => {
|
|
||||||
setSchema(undefined);
|
|
||||||
library.reload();
|
|
||||||
if (callback) callback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, [schemaID, setError, setSchema, library]);
|
|
||||||
|
|
||||||
const claim = useCallback(
|
const claim = useCallback(
|
||||||
(callback?: DataCallback<IRSFormMeta>) => {
|
(callback?: DataCallback<IRSFormMeta>) => {
|
||||||
if (!schema || !user) {
|
if (!schema || !user) {
|
||||||
|
@ -162,24 +144,6 @@ export const RSFormState = ({ schemaID, children }: RSFormStateProps) => {
|
||||||
});
|
});
|
||||||
}, [schemaID, setError, schema, user, setSchema]);
|
}, [schemaID, setError, schema, user, setSchema]);
|
||||||
|
|
||||||
const clone = useCallback(
|
|
||||||
(data: IRSFormCreateData, callback: DataCallback<IRSFormData>) => {
|
|
||||||
if (!schema || !user) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setError(undefined)
|
|
||||||
postCloneRSForm(schemaID, {
|
|
||||||
data: data,
|
|
||||||
showError: true,
|
|
||||||
setLoading: setProcessing,
|
|
||||||
onError: error => setError(error),
|
|
||||||
onSuccess: newSchema => {
|
|
||||||
library.reload();
|
|
||||||
if (callback) callback(newSchema);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, [schemaID, setError, schema, user, library]);
|
|
||||||
|
|
||||||
const resetAliases = useCallback(
|
const resetAliases = useCallback(
|
||||||
(callback?: () => void) => {
|
(callback?: () => void) => {
|
||||||
if (!schema || !user) {
|
if (!schema || !user) {
|
||||||
|
@ -276,7 +240,7 @@ export const RSFormState = ({ schemaID, children }: RSFormStateProps) => {
|
||||||
toggleForceAdmin: () => { setIsForceAdmin(prev => !prev) },
|
toggleForceAdmin: () => { setIsForceAdmin(prev => !prev) },
|
||||||
toggleReadonly: () => { setIsReadonly(prev => !prev) },
|
toggleReadonly: () => { setIsReadonly(prev => !prev) },
|
||||||
toggleTracking,
|
toggleTracking,
|
||||||
update, download, upload, destroy, claim, resetAliases, clone,
|
update, download, upload, claim, resetAliases,
|
||||||
cstUpdate, cstCreate, cstDelete, cstMoveTo
|
cstUpdate, cstCreate, cstDelete, cstMoveTo
|
||||||
}}>
|
}}>
|
||||||
{ children }
|
{ children }
|
||||||
|
|
|
@ -6,6 +6,7 @@ import Checkbox from '../../components/Common/Checkbox';
|
||||||
import Modal from '../../components/Common/Modal';
|
import Modal from '../../components/Common/Modal';
|
||||||
import TextArea from '../../components/Common/TextArea';
|
import TextArea from '../../components/Common/TextArea';
|
||||||
import TextInput from '../../components/Common/TextInput';
|
import TextInput from '../../components/Common/TextInput';
|
||||||
|
import { useLibrary } from '../../context/LibraryContext';
|
||||||
import { useRSForm } from '../../context/RSFormContext';
|
import { useRSForm } from '../../context/RSFormContext';
|
||||||
import { IRSFormCreateData } from '../../utils/models';
|
import { IRSFormCreateData } from '../../utils/models';
|
||||||
import { getCloneTitle } from '../../utils/staticUI';
|
import { getCloneTitle } from '../../utils/staticUI';
|
||||||
|
@ -21,7 +22,8 @@ function DlgCloneRSForm({ hideWindow }: DlgCloneRSFormProps) {
|
||||||
const [comment, setComment] = useState('');
|
const [comment, setComment] = useState('');
|
||||||
const [common, setCommon] = useState(false);
|
const [common, setCommon] = useState(false);
|
||||||
|
|
||||||
const { schema, clone } = useRSForm();
|
const { cloneSchema } = useLibrary();
|
||||||
|
const { schema } = useRSForm();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (schema) {
|
if (schema) {
|
||||||
|
@ -33,13 +35,16 @@ function DlgCloneRSForm({ hideWindow }: DlgCloneRSFormProps) {
|
||||||
}, [schema, schema?.title, schema?.alias, schema?.comment, schema?.is_common]);
|
}, [schema, schema?.title, schema?.alias, schema?.comment, schema?.is_common]);
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
|
if (!schema) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const data: IRSFormCreateData = {
|
const data: IRSFormCreateData = {
|
||||||
title: title,
|
title: title,
|
||||||
alias: alias,
|
alias: alias,
|
||||||
comment: comment,
|
comment: comment,
|
||||||
is_common: common
|
is_common: common
|
||||||
};
|
};
|
||||||
clone(data, newSchema => {
|
cloneSchema(schema.id, data, newSchema => {
|
||||||
toast.success(`Схема создана: ${newSchema.alias}`);
|
toast.success(`Схема создана: ${newSchema.alias}`);
|
||||||
navigate(`/rsforms/${newSchema.id}`);
|
navigate(`/rsforms/${newSchema.id}`);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { useCallback, useLayoutEffect, useState } from 'react';
|
import { useCallback, useLayoutEffect, useState } from 'react';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { useNavigate } from 'react-router-dom';
|
|
||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
|
|
||||||
import Checkbox from '../../components/Common/Checkbox';
|
import Checkbox from '../../components/Common/Checkbox';
|
||||||
|
@ -13,15 +12,18 @@ import { useAuth } from '../../context/AuthContext';
|
||||||
import { useRSForm } from '../../context/RSFormContext';
|
import { useRSForm } from '../../context/RSFormContext';
|
||||||
import { useUsers } from '../../context/UsersContext';
|
import { useUsers } from '../../context/UsersContext';
|
||||||
import { IRSFormCreateData } from '../../utils/models';
|
import { IRSFormCreateData } from '../../utils/models';
|
||||||
import { claimOwnershipProc, deleteRSFormProc, downloadRSFormProc, shareCurrentURLProc } from '../../utils/procedures';
|
import { claimOwnershipProc, downloadRSFormProc, shareCurrentURLProc } from '../../utils/procedures';
|
||||||
|
|
||||||
function EditorRSForm() {
|
interface EditorRSFormProps {
|
||||||
const navigate = useNavigate();
|
onDestroy: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
function EditorRSForm({ onDestroy }: EditorRSFormProps) {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const { getUserLabel } = useUsers();
|
const { getUserLabel } = useUsers();
|
||||||
const {
|
const {
|
||||||
schema, update, download,
|
schema, update, download,
|
||||||
isEditable, isOwned, isClaimable, processing, destroy, claim
|
isEditable, isOwned, isClaimable, processing, claim
|
||||||
} = useRSForm();
|
} = useRSForm();
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
|
|
||||||
|
@ -66,9 +68,6 @@ function EditorRSForm() {
|
||||||
update(data, () => toast.success('Изменения сохранены'));
|
update(data, () => toast.success('Изменения сохранены'));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete =
|
|
||||||
useCallback(() => { deleteRSFormProc(destroy, navigate); }, [destroy, navigate]);
|
|
||||||
|
|
||||||
const handleDownload = useCallback(() => {
|
const handleDownload = useCallback(() => {
|
||||||
const fileName = (schema?.alias ?? 'Schema') + '.trs';
|
const fileName = (schema?.alias ?? 'Schema') + '.trs';
|
||||||
downloadRSFormProc(download, fileName);
|
downloadRSFormProc(download, fileName);
|
||||||
|
@ -97,7 +96,7 @@ function EditorRSForm() {
|
||||||
<MiniButton
|
<MiniButton
|
||||||
tooltip='Удалить схему'
|
tooltip='Удалить схему'
|
||||||
disabled={!isEditable}
|
disabled={!isEditable}
|
||||||
onClick={handleDelete}
|
onClick={onDestroy}
|
||||||
icon={<DumpBinIcon size={5} color={isEditable ? 'text-red' : ''} />}
|
icon={<DumpBinIcon size={5} color={isEditable ? 'text-red' : ''} />}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { toast } from 'react-toastify';
|
||||||
import BackendError from '../../components/BackendError';
|
import BackendError from '../../components/BackendError';
|
||||||
import ConceptTab from '../../components/Common/ConceptTab';
|
import ConceptTab from '../../components/Common/ConceptTab';
|
||||||
import { Loader } from '../../components/Common/Loader';
|
import { Loader } from '../../components/Common/Loader';
|
||||||
|
import { useLibrary } from '../../context/LibraryContext';
|
||||||
import { useRSForm } from '../../context/RSFormContext';
|
import { useRSForm } from '../../context/RSFormContext';
|
||||||
import { prefixes, TIMEOUT_UI_REFRESH } from '../../utils/constants';
|
import { prefixes, TIMEOUT_UI_REFRESH } from '../../utils/constants';
|
||||||
import { CstType, ICstCreateData, SyntaxTree } from '../../utils/models';
|
import { CstType, ICstCreateData, SyntaxTree } from '../../utils/models';
|
||||||
|
@ -36,6 +37,7 @@ function RSTabs() {
|
||||||
error, schema, loading,
|
error, schema, loading,
|
||||||
cstCreate, cstDelete
|
cstCreate, cstDelete
|
||||||
} = useRSForm();
|
} = useRSForm();
|
||||||
|
const { destroySchema } = useLibrary();
|
||||||
|
|
||||||
const [activeTab, setActiveTab] = useState(RSTabsList.CARD);
|
const [activeTab, setActiveTab] = useState(RSTabsList.CARD);
|
||||||
const [activeID, setActiveID] = useState<number | undefined>(undefined)
|
const [activeID, setActiveID] = useState<number | undefined>(undefined)
|
||||||
|
@ -151,7 +153,6 @@ function RSTabs() {
|
||||||
});
|
});
|
||||||
}, [afterDelete, cstDelete, schema, activeID, activeTab, navigateTo]);
|
}, [afterDelete, cstDelete, schema, activeID, activeTab, navigateTo]);
|
||||||
|
|
||||||
|
|
||||||
const promptDeleteCst = useCallback(
|
const promptDeleteCst = useCallback(
|
||||||
(selected: number[], callback?: (items: number[]) => void) => {
|
(selected: number[], callback?: (items: number[]) => void) => {
|
||||||
setAfterDelete(() => (
|
setAfterDelete(() => (
|
||||||
|
@ -174,6 +175,17 @@ function RSTabs() {
|
||||||
navigateTo(RSTabsList.CST_EDIT, cstID)
|
navigateTo(RSTabsList.CST_EDIT, cstID)
|
||||||
}, [navigateTo]);
|
}, [navigateTo]);
|
||||||
|
|
||||||
|
const onDestroySchema = useCallback(
|
||||||
|
() => {
|
||||||
|
if (!schema || !window.confirm('Вы уверены, что хотите удалить данную схему?')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
destroySchema(schema.id, () => {
|
||||||
|
toast.success('Схема удалена');
|
||||||
|
navigate('/library?filter=personal');
|
||||||
|
});
|
||||||
|
}, [schema, destroySchema, navigate]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='w-full'>
|
<div className='w-full'>
|
||||||
{ loading && <Loader /> }
|
{ loading && <Loader /> }
|
||||||
|
@ -213,6 +225,7 @@ function RSTabs() {
|
||||||
>
|
>
|
||||||
<TabList className='flex items-start w-fit clr-bg-pop'>
|
<TabList className='flex items-start w-fit clr-bg-pop'>
|
||||||
<RSTabsMenu
|
<RSTabsMenu
|
||||||
|
onDestroy={onDestroySchema}
|
||||||
showCloneDialog={() => setShowClone(true)}
|
showCloneDialog={() => setShowClone(true)}
|
||||||
showUploadDialog={() => setShowUpload(true)}
|
showUploadDialog={() => setShowUpload(true)}
|
||||||
/>
|
/>
|
||||||
|
@ -226,7 +239,9 @@ function RSTabs() {
|
||||||
</TabList>
|
</TabList>
|
||||||
|
|
||||||
<TabPanel className='flex items-start w-full gap-2'>
|
<TabPanel className='flex items-start w-full gap-2'>
|
||||||
<EditorRSForm />
|
<EditorRSForm
|
||||||
|
onDestroy={onDestroySchema}
|
||||||
|
/>
|
||||||
{schema.stats && <RSFormStats stats={schema.stats}/>}
|
{schema.stats && <RSFormStats stats={schema.stats}/>}
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
|
||||||
|
|
||||||
import Button from '../../components/Common/Button';
|
import Button from '../../components/Common/Button';
|
||||||
import Checkbox from '../../components/Common/Checkbox';
|
import Checkbox from '../../components/Common/Checkbox';
|
||||||
|
@ -9,21 +8,21 @@ import { CloneIcon, CrownIcon, DownloadIcon, DumpBinIcon, EyeIcon, EyeOffIcon, M
|
||||||
import { useAuth } from '../../context/AuthContext';
|
import { useAuth } from '../../context/AuthContext';
|
||||||
import { useRSForm } from '../../context/RSFormContext';
|
import { useRSForm } from '../../context/RSFormContext';
|
||||||
import useDropdown from '../../hooks/useDropdown';
|
import useDropdown from '../../hooks/useDropdown';
|
||||||
import { claimOwnershipProc, deleteRSFormProc, downloadRSFormProc, shareCurrentURLProc } from '../../utils/procedures';
|
import { claimOwnershipProc, downloadRSFormProc, shareCurrentURLProc } from '../../utils/procedures';
|
||||||
|
|
||||||
interface RSTabsMenuProps {
|
interface RSTabsMenuProps {
|
||||||
showUploadDialog: () => void
|
showUploadDialog: () => void
|
||||||
showCloneDialog: () => void
|
showCloneDialog: () => void
|
||||||
|
onDestroy: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
function RSTabsMenu({showUploadDialog, showCloneDialog}: RSTabsMenuProps) {
|
function RSTabsMenu({showUploadDialog, showCloneDialog, onDestroy}: RSTabsMenuProps) {
|
||||||
const navigate = useNavigate();
|
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const {
|
const {
|
||||||
schema,
|
schema,
|
||||||
isOwned, isEditable, isTracking, isReadonly: readonly, isForceAdmin: forceAdmin,
|
isOwned, isEditable, isTracking, isReadonly: readonly, isForceAdmin: forceAdmin,
|
||||||
toggleTracking, toggleForceAdmin, toggleReadonly,
|
toggleTracking, toggleForceAdmin, toggleReadonly,
|
||||||
claim, destroy, download
|
claim, download
|
||||||
} = useRSForm();
|
} = useRSForm();
|
||||||
const schemaMenu = useDropdown();
|
const schemaMenu = useDropdown();
|
||||||
const editMenu = useDropdown();
|
const editMenu = useDropdown();
|
||||||
|
@ -35,8 +34,8 @@ function RSTabsMenu({showUploadDialog, showCloneDialog}: RSTabsMenuProps) {
|
||||||
|
|
||||||
const handleDelete = useCallback(() => {
|
const handleDelete = useCallback(() => {
|
||||||
schemaMenu.hide();
|
schemaMenu.hide();
|
||||||
deleteRSFormProc(destroy, navigate);
|
onDestroy();
|
||||||
}, [destroy, navigate, schemaMenu]);
|
}, [onDestroy, schemaMenu]);
|
||||||
|
|
||||||
const handleDownload = useCallback(() => {
|
const handleDownload = useCallback(() => {
|
||||||
schemaMenu.hide();
|
schemaMenu.hide();
|
||||||
|
|
|
@ -20,19 +20,6 @@ export function claimOwnershipProc(
|
||||||
claim(() => toast.success('Вы стали владельцем схемы'));
|
claim(() => toast.success('Вы стали владельцем схемы'));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteRSFormProc(
|
|
||||||
destroy: (callback?: () => void) => void,
|
|
||||||
navigate: (path: string) => void
|
|
||||||
) {
|
|
||||||
if (!window.confirm('Вы уверены, что хотите удалить данную схему?')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
destroy(() => {
|
|
||||||
toast.success('Схема удалена');
|
|
||||||
navigate('/library?filter=personal');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function downloadRSFormProc(
|
export function downloadRSFormProc(
|
||||||
download: (callback: DataCallback<Blob>) => void,
|
download: (callback: DataCallback<Blob>) => void,
|
||||||
fileName: string
|
fileName: string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user