Skip to content

Commit

Permalink
remove formatted expiry logic and fix sent expires_in
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fischer committed Jul 6, 2023
1 parent bae95d2 commit d3d9891
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
6 changes: 1 addition & 5 deletions src/components/SetupKeyEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -287,7 +284,6 @@ const SetupKeyNew = () => {
form={form}
onValuesChange={onChange}
initialValues={{
expiresIn: ExpiresInDefault,
usage_limit: 1,
}}
>
Expand Down
10 changes: 3 additions & 7 deletions src/components/SetupKeyNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -374,7 +371,7 @@ const SetupKeyNew = () => {
form={form}
onValuesChange={onChange}
initialValues={{
expiresIn: ExpiresInDefault,
expires_in: 7,
usage_limit: 1,
}}
>
Expand Down Expand Up @@ -488,13 +485,12 @@ const SetupKeyNew = () => {
</Col>
<Col>
<Form.Item
name="expiresIn"
name="expires_in"
rules={[
{ required: true, message: "Please enter expiration date" },
]}
>
<InputNumber
defaultValue={7}
placeholder={`2`}
type="number"
addonAfter=" Days"
Expand Down
2 changes: 0 additions & 2 deletions src/store/setup-key/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {ExpiresInValue} from "../../views/ExpiresInInput";
import moment from "moment";

export interface SetupKey {
Expand All @@ -19,7 +18,6 @@ export interface SetupKey {

export interface FormSetupKey extends SetupKey {
autoGroupNames: string[]
expiresInFormatted: ExpiresInValue
exp: moment.Moment
last: moment.Moment
}
Expand Down

0 comments on commit d3d9891

Please sign in to comment.