mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 03:17:11 +00:00
chore(admin): convert ApiTokenPermissions to TS
This commit is contained in:
parent
26ef626a0d
commit
069a1d0f8f
@ -1,25 +0,0 @@
|
||||
import React, { createContext, useContext } from 'react';
|
||||
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const ApiTokenPermissionsContext = createContext({});
|
||||
|
||||
const ApiTokenPermissionsContextProvider = ({ children, ...rest }) => {
|
||||
return (
|
||||
<ApiTokenPermissionsContext.Provider value={rest}>
|
||||
{children}
|
||||
</ApiTokenPermissionsContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
const useApiTokenPermissionsContext = () => useContext(ApiTokenPermissionsContext);
|
||||
|
||||
ApiTokenPermissionsContextProvider.propTypes = {
|
||||
children: PropTypes.node.isRequired,
|
||||
};
|
||||
|
||||
export {
|
||||
ApiTokenPermissionsContext,
|
||||
ApiTokenPermissionsContextProvider,
|
||||
useApiTokenPermissionsContext,
|
||||
};
|
||||
@ -0,0 +1,62 @@
|
||||
/* eslint-disable check-file/filename-naming-convention */
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
import { Entity } from '@strapi/types';
|
||||
|
||||
interface PseudoEvent {
|
||||
target: { value: string };
|
||||
}
|
||||
|
||||
interface APITokenPermissionsContextProviderProps {
|
||||
selectedAction: string[] | null;
|
||||
routes: string[];
|
||||
selectedActions: string[];
|
||||
data: {
|
||||
allActionsIds: Entity.ID[];
|
||||
permissions: {
|
||||
apiId: string;
|
||||
label: string;
|
||||
controllers: { controller: string; actions: { actionId: string; action: string } }[];
|
||||
}[];
|
||||
};
|
||||
onChange: ({ target: { value } }: PseudoEvent) => void;
|
||||
onChangeSelectAll: ({ target: { value } }: PseudoEvent) => void;
|
||||
setSelectedAction: ({ target: { value } }: PseudoEvent) => void;
|
||||
}
|
||||
|
||||
interface ApiTokenPermissionsContextProviderProps extends APITokenPermissionsContextProviderProps {
|
||||
children: React.ReactNode[];
|
||||
}
|
||||
|
||||
const ApiTokenPermissionsContext = React.createContext<APITokenPermissionsContextProviderProps>({
|
||||
selectedAction: null,
|
||||
routes: [],
|
||||
selectedActions: [],
|
||||
data: {
|
||||
allActionsIds: [],
|
||||
permissions: [],
|
||||
},
|
||||
onChange: () => {},
|
||||
onChangeSelectAll: () => {},
|
||||
setSelectedAction: () => {},
|
||||
});
|
||||
|
||||
const ApiTokenPermissionsContextProvider = ({
|
||||
children,
|
||||
...rest
|
||||
}: ApiTokenPermissionsContextProviderProps) => {
|
||||
return (
|
||||
<ApiTokenPermissionsContext.Provider value={rest}>
|
||||
{children}
|
||||
</ApiTokenPermissionsContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
const useApiTokenPermissionsContext = () => React.useContext(ApiTokenPermissionsContext);
|
||||
|
||||
export {
|
||||
ApiTokenPermissionsContext,
|
||||
ApiTokenPermissionsContextProvider,
|
||||
useApiTokenPermissionsContext,
|
||||
};
|
||||
@ -3,7 +3,7 @@ import React from 'react';
|
||||
import { Flex, GridItem, Typography } from '@strapi/design-system';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import { useApiTokenPermissionsContext } from '../../../../../../../contexts/ApiTokenPermissions';
|
||||
import { useApiTokenPermissionsContext } from '../../../../../../../contexts/apiTokenPermissions';
|
||||
import BoundRoute from '../BoundRoute';
|
||||
|
||||
const ActionBoundRoutes = () => {
|
||||
|
||||
@ -17,7 +17,7 @@ import PropTypes from 'prop-types';
|
||||
import { useIntl } from 'react-intl';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { useApiTokenPermissionsContext } from '../../../../../../../contexts/ApiTokenPermissions';
|
||||
import { useApiTokenPermissionsContext } from '../../../../../../../contexts/apiTokenPermissions';
|
||||
|
||||
import CheckboxWrapper from './CheckBoxWrapper';
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ import React, { memo } from 'react';
|
||||
import { Flex, Grid, GridItem, Typography } from '@strapi/design-system';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import { useApiTokenPermissionsContext } from '../../../../../../../contexts/ApiTokenPermissions';
|
||||
import { useApiTokenPermissionsContext } from '../../../../../../../contexts/apiTokenPermissions';
|
||||
import ActionBoundRoutes from '../ActionBoundRoutes';
|
||||
import ContentTypesSection from '../ContenTypesSection';
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ import { useQuery } from 'react-query';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { useHistory, useRouteMatch } from 'react-router-dom';
|
||||
|
||||
import { ApiTokenPermissionsContextProvider } from '../../../../../contexts/ApiTokenPermissions';
|
||||
import { ApiTokenPermissionsContextProvider } from '../../../../../contexts/apiTokenPermissions';
|
||||
import { formatAPIErrors } from '../../../../../utils';
|
||||
import { selectAdminPermissions } from '../../../../App/selectors';
|
||||
import { API_TOKEN_TYPE } from '../../../components/Tokens/constants';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user