Skip to content

Commit

Permalink
feat(management/application): add Token Lifetime option to the action…
Browse files Browse the repository at this point in the history
… list (#855)
  • Loading branch information
a0m0rajab authored Nov 14, 2024
2 parents 8cb6b79 + c74f5d6 commit b5c3931
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
57 changes: 55 additions & 2 deletions apps/web/src/app/[lang]/app/[type]/management/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
$Volo_Abp_LanguageManagement_Dto_UpdateLanguageDto,
$Volo_Abp_TextTemplateManagement_TextTemplates_TemplateDefinitionDto,
} from "@ayasofyazilim/saas/AdministrationService";
import type { Volo_Abp_Identity_IdentityRoleDto } from "@ayasofyazilim/saas/IdentityService";
import type {
Volo_Abp_Identity_IdentityRoleDto,
Volo_Abp_OpenIddict_Applications_Dtos_ApplicationDto,
Volo_Abp_OpenIddict_Applications_Dtos_ApplicationTokenLifetimeDto,
} from "@ayasofyazilim/saas/IdentityService";
import {
$Volo_Abp_Identity_ClaimTypeDto,
$Volo_Abp_Identity_CreateClaimTypeDto,
Expand All @@ -21,6 +25,7 @@ import {
$Volo_Abp_Identity_OrganizationUnitDto,
$Volo_Abp_Identity_UpdateClaimTypeDto,
$Volo_Abp_OpenIddict_Applications_Dtos_ApplicationDto,
$Volo_Abp_OpenIddict_Applications_Dtos_ApplicationTokenLifetimeDto,
$Volo_Abp_OpenIddict_Applications_Dtos_CreateApplicationInput,
$Volo_Abp_OpenIddict_Applications_Dtos_UpdateApplicationInput,
$Volo_Abp_OpenIddict_Scopes_Dtos_CreateScopeInput,
Expand All @@ -39,18 +44,20 @@ import {
$Volo_Saas_Host_Dtos_SaasTenantDto,
$Volo_Saas_Host_Dtos_SaasTenantUpdateDto,
} from "@ayasofyazilim/saas/SaasService";
import { createZodObject } from "@repo/ayasofyazilim-ui/lib/create-zod-object";
import { CustomCombobox } from "@repo/ayasofyazilim-ui/organisms/auto-form";
import type { AutoFormInputComponentProps } from "node_modules/@repo/ayasofyazilim-ui/src/organisms/auto-form/types";
import { DependencyType } from "node_modules/@repo/ayasofyazilim-ui/src/organisms/auto-form/types";
import { useEffect, useState } from "react";
import { z } from "zod";
import type { ErrorTypes } from "src/lib";
import type { DataConfigArray } from "src/types";
import { getBaseLink } from "src/utils";
import type { ErrorTypes } from "src/lib";
import {
getAllRolesApi,
moveAllUsersApi,
} from "../../actions/IdentityService/actions";
import { putApplicationTokenLifetimeApi } from "../../actions/IdentityService/put-actions";
import {
getAllEditionsApi,
moveAllTenantsApi,
Expand Down Expand Up @@ -147,6 +154,52 @@ export const dataConfig: DataConfigArray = {
"consentType",
],
schema: $Volo_Abp_OpenIddict_Applications_Dtos_ApplicationDto,
actionList: () => [
{
type: "Dialog",
cta: "Token Lifetime",
description: "Token Lifetime",
componentType: "Autoform",
autoFormArgs: {
submit: {
cta: "Save",
},
formSchema: createZodObject(
$Volo_Abp_OpenIddict_Applications_Dtos_ApplicationTokenLifetimeDto,
),
},

callback: (values, triggerData, onOpenChange) => {
const _values =
values as Volo_Abp_OpenIddict_Applications_Dtos_ApplicationTokenLifetimeDto;
const _triggerData =
triggerData as Volo_Abp_OpenIddict_Applications_Dtos_ApplicationDto;

const putApplicationTokenLifetime = async (
tokenLifetimeData: Volo_Abp_OpenIddict_Applications_Dtos_ApplicationTokenLifetimeDto,
applicationId: string,
) => {
const response = await putApplicationTokenLifetimeApi({
id: applicationId,
requestBody: tokenLifetimeData,
});

if (response.type === "success") {
toast.success("Token lifetime updated successfully.");
onOpenChange && onOpenChange(false);
} else {
toast.error(
response.message || "Failed to update token lifetime.",
);
}
};
void putApplicationTokenLifetime(
_values,
_triggerData.id || "",
);
},
},
],
},
editFormSchema: {
formPositions: [
Expand Down
16 changes: 16 additions & 0 deletions apps/web/src/app/[lang]/app/actions/IdentityService/put-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use server";
import type { PutApiOpeniddictApplicationsByIdTokenLifetimeData } from "@ayasofyazilim/saas/IdentityService";
import { structuredError, structuredResponse } from "src/lib";
import { getApiRequests } from "../api-requests";

export async function putApplicationTokenLifetimeApi(
data: PutApiOpeniddictApplicationsByIdTokenLifetimeData,
) {
try {
const requests = await getApiRequests();
const dataResponse = await requests.applications.putTokenLifetime(data);
return structuredResponse(dataResponse);
} catch (error) {
return structuredError(error);
}
}
13 changes: 12 additions & 1 deletion apps/web/src/app/[lang]/app/actions/api-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import type {
PutApiIdentityRolesByIdClaimsData,
PutApiIdentityRolesByIdMoveAllUsersData,
PutApiIdentityUsersByIdClaimsData,
PutApiOpeniddictApplicationsByIdTokenLifetimeData,
} from "@ayasofyazilim/saas/IdentityService";
import type {
GetApiLocationServiceCitiesData,
Expand Down Expand Up @@ -79,7 +80,7 @@ import {
export type ApiRequestTypes = keyof Awaited<ReturnType<typeof getApiRequests>>;
export type GetTableDataTypes = Exclude<
ApiRequestTypes,
"locations" | "editions"
"locations" | "editions" | "applications"
>;
export type DeleteTableDataTypes = Exclude<
ApiRequestTypes,
Expand All @@ -90,6 +91,7 @@ export type DeleteTableDataTypes = Exclude<
| "users"
| "tags"
| "editions"
| "applications"
>;
export type GetDetailTableDataTypes = Exclude<
ApiRequestTypes,
Expand All @@ -101,6 +103,7 @@ export type GetDetailTableDataTypes = Exclude<
| "tags"
| "editions"
| "billing"
| "applications"
>;

export async function getApiRequests() {
Expand Down Expand Up @@ -584,6 +587,14 @@ export async function getApiRequests() {
id,
}),
},
applications: {
putTokenLifetime: async (
data: PutApiOpeniddictApplicationsByIdTokenLifetimeData,
) =>
await identityClient.applications.putApiOpeniddictApplicationsByIdTokenLifetime(
data,
),
},
};
return tableRequests;
}
Expand Down

0 comments on commit b5c3931

Please sign in to comment.