mirror of
https://github.com/strapi/strapi.git
synced 2025-09-17 12:27:33 +00:00
Add token type select to frontend
This commit is contained in:
parent
40679cefca
commit
c4cd8b1e15
@ -5,6 +5,7 @@ import { Box, Grid, GridItem, Flex, Typography } from '@strapi/design-system';
|
|||||||
import LifeSpanInput from '../../../../../components/Tokens/LifeSpanInput';
|
import LifeSpanInput from '../../../../../components/Tokens/LifeSpanInput';
|
||||||
import TokenName from '../../../../../components/Tokens/TokenName';
|
import TokenName from '../../../../../components/Tokens/TokenName';
|
||||||
import TokenDescription from '../../../../../components/Tokens/TokenDescription';
|
import TokenDescription from '../../../../../components/Tokens/TokenDescription';
|
||||||
|
import TokenTypeSelect from '../../../../../components/Tokens/TokenTypeSelect';
|
||||||
|
|
||||||
const FormTransferTokenContainer = ({
|
const FormTransferTokenContainer = ({
|
||||||
errors,
|
errors,
|
||||||
@ -16,6 +17,30 @@ const FormTransferTokenContainer = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
|
const typeOptions = [
|
||||||
|
{
|
||||||
|
value: 'push',
|
||||||
|
label: {
|
||||||
|
id: 'Settings.transferTokens.types.push',
|
||||||
|
defaultMessage: 'Push',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'pull',
|
||||||
|
label: {
|
||||||
|
id: 'Settings.transferTokens.types.pull',
|
||||||
|
defaultMessage: 'Pull',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'push-pull',
|
||||||
|
label: {
|
||||||
|
id: 'Settings.transferTokens.types.pull',
|
||||||
|
defaultMessage: 'Push & pull',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
background="neutral0"
|
background="neutral0"
|
||||||
@ -59,6 +84,21 @@ const FormTransferTokenContainer = ({
|
|||||||
token={transferToken}
|
token={transferToken}
|
||||||
/>
|
/>
|
||||||
</GridItem>
|
</GridItem>
|
||||||
|
<GridItem key="type" col={6} xs={12}>
|
||||||
|
<TokenTypeSelect
|
||||||
|
values={values}
|
||||||
|
errors={errors}
|
||||||
|
label={{
|
||||||
|
id: 'Settings.tokens.form.type',
|
||||||
|
defaultMessage: 'Token type',
|
||||||
|
}}
|
||||||
|
onChange={(value) => {
|
||||||
|
onChange({ target: { name: 'type', value } });
|
||||||
|
}}
|
||||||
|
options={typeOptions}
|
||||||
|
canEditInputs={canEditInputs}
|
||||||
|
/>
|
||||||
|
</GridItem>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -92,6 +92,8 @@ const TransferTokenCreateView = () => {
|
|||||||
? parseInt(body.lifespan, 10)
|
? parseInt(body.lifespan, 10)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
const permissions = body.type.split('-');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
data: { data: response },
|
data: { data: response },
|
||||||
@ -99,13 +101,13 @@ const TransferTokenCreateView = () => {
|
|||||||
? await post(`/admin/transfer/tokens`, {
|
? await post(`/admin/transfer/tokens`, {
|
||||||
...body,
|
...body,
|
||||||
lifespan: lifespanVal,
|
lifespan: lifespanVal,
|
||||||
permissions: ['push'],
|
permissions,
|
||||||
})
|
})
|
||||||
: await put(`/admin/transfer/tokens/${id}`, {
|
: await put(`/admin/transfer/tokens/${id}`, {
|
||||||
name: body.name,
|
name: body.name,
|
||||||
description: body.description,
|
description: body.description,
|
||||||
type: body.type,
|
type: body.type,
|
||||||
permissions: ['push'],
|
permissions,
|
||||||
});
|
});
|
||||||
|
|
||||||
unlockApp();
|
unlockApp();
|
||||||
@ -173,6 +175,7 @@ const TransferTokenCreateView = () => {
|
|||||||
lifespan: transferToken?.lifespan
|
lifespan: transferToken?.lifespan
|
||||||
? transferToken.lifespan.toString()
|
? transferToken.lifespan.toString()
|
||||||
: transferToken?.lifespan,
|
: transferToken?.lifespan,
|
||||||
|
type: transferToken?.permissions.join('-'),
|
||||||
}}
|
}}
|
||||||
enableReinitialize
|
enableReinitialize
|
||||||
onSubmit={(body, actions) => handleSubmit(body, actions)}
|
onSubmit={(body, actions) => handleSubmit(body, actions)}
|
||||||
|
@ -5,6 +5,7 @@ const schema = yup.object().shape({
|
|||||||
name: yup.string(translatedErrors.string).required(translatedErrors.required),
|
name: yup.string(translatedErrors.string).required(translatedErrors.required),
|
||||||
description: yup.string().nullable(),
|
description: yup.string().nullable(),
|
||||||
lifespan: yup.number().integer().min(0).nullable().defined(translatedErrors.required),
|
lifespan: yup.number().integer().min(0).nullable().defined(translatedErrors.required),
|
||||||
|
type: yup.string(translatedErrors.string).required(translatedErrors.required),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default schema;
|
export default schema;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user