From 79446c0e77d148024285bce33966839991a3f307 Mon Sep 17 00:00:00 2001 From: pascal-fischer <32096965+pascal-fischer@users.noreply.github.com> Date: Thu, 6 Jul 2023 17:16:10 +0200 Subject: [PATCH] remove formatted expiry logic and fix sent expires_in (#220) --- src/components/SetupKeyEdit.tsx | 6 +----- src/components/SetupKeyNew.tsx | 10 +++------- src/store/setup-key/types.ts | 2 -- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/components/SetupKeyEdit.tsx b/src/components/SetupKeyEdit.tsx index 51c4d95f..a0e67f84 100644 --- a/src/components/SetupKeyEdit.tsx +++ b/src/components/SetupKeyEdit.tsx @@ -27,7 +27,6 @@ import { RuleObject } from "antd/lib/form"; import { CustomTagProps } from "rc-select/lib/BaseSelect"; import { Group } from "../store/group/types"; import { useGetTokenSilently } from "../utils/token"; -import { expiresInToSeconds, ExpiresInValue } from "../views/ExpiresInInput"; import moment from "moment"; import { Container } from "./Container"; import Paragraph from "antd/es/typography/Paragraph"; @@ -37,7 +36,6 @@ import { useGetGroupTagHelpers } from "../utils/groups"; const { Option } = Select; const { Text } = Typography; -const ExpiresInDefault: ExpiresInValue = { number: 30, interval: "day" }; const customExpiresFormat = (value: Date): string | null => { return formatDate(value); @@ -95,7 +93,6 @@ const SetupKeyNew = () => { const fSetupKey = { ...setupKey, autoGroupNames: setupKey.auto_groups ? formKeyGroups : [], - expiresInFormatted: ExpiresInDefault, exp: moment(setupKey.expires), last: moment(setupKey.last_used), } as FormSetupKey; @@ -115,7 +112,7 @@ const SetupKeyNew = () => { (s) => !allGroupsNames.includes(s) ); - const expiresIn = expiresInToSeconds(formSetupKey.expiresInFormatted); + const expiresIn = formSetupKey.expires_in * 24 * 3600 // the api expects seconds while the form returns days return { id: formSetupKey.id, name: formSetupKey.name, @@ -287,7 +284,6 @@ const SetupKeyNew = () => { form={form} onValuesChange={onChange} initialValues={{ - expiresIn: ExpiresInDefault, usage_limit: 1, }} > diff --git a/src/components/SetupKeyNew.tsx b/src/components/SetupKeyNew.tsx index aa2c0ce7..05b77676 100644 --- a/src/components/SetupKeyNew.tsx +++ b/src/components/SetupKeyNew.tsx @@ -26,7 +26,6 @@ import { RuleObject } from "antd/lib/form"; import { CustomTagProps } from "rc-select/lib/BaseSelect"; import { Group } from "../store/group/types"; import { useGetTokenSilently } from "../utils/token"; -import { expiresInToSeconds, ExpiresInValue } from "../views/ExpiresInInput"; import moment from "moment"; import { Container } from "./Container"; import Paragraph from "antd/es/typography/Paragraph"; @@ -36,7 +35,6 @@ import {useGetGroupTagHelpers} from "../utils/groups"; const { Option } = Select; const { Text } = Typography; -const ExpiresInDefault: ExpiresInValue = { number: 30, interval: "day" }; const SetupKeyNew = () => { const { optionRender, blueTagRender } = useGetGroupTagHelpers(); @@ -88,7 +86,6 @@ const SetupKeyNew = () => { const fSetupKey = { ...setupKey, autoGroupNames: setupKey.auto_groups ? formKeyGroups : [], - expiresInFormatted: ExpiresInDefault, exp: moment(setupKey.expires), last: moment(setupKey.last_used), } as FormSetupKey; @@ -108,7 +105,7 @@ const SetupKeyNew = () => { (s) => !allGroupsNames.includes(s) ); - const expiresIn = expiresInToSeconds(formSetupKey.expiresInFormatted); + const expiresIn = formSetupKey.expires_in * 24 * 3600 // the api expects seconds we have days return { id: formSetupKey.id, name: formSetupKey.name, @@ -374,7 +371,7 @@ const SetupKeyNew = () => { form={form} onValuesChange={onChange} initialValues={{ - expiresIn: ExpiresInDefault, + expires_in: 7, usage_limit: 1, }} > @@ -488,13 +485,12 @@ const SetupKeyNew = () => {