Skip to content

Commit

Permalink
Add create user credential hook
Browse files Browse the repository at this point in the history
  • Loading branch information
nathandf committed Jul 16, 2024
1 parent 660ba13 commit f47dce8
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 51 deletions.
20 changes: 20 additions & 0 deletions lib/tapisui-api/src/systems/createUserCredential.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Systems } from '@tapis/tapis-typescript';
import { apiGenerator, errorDecoder } from '../utils';

const createUserCredential = (
params: Systems.CreateUserCredentialRequest,
basePath: string,
jwt: string
) => {
const api: Systems.CredentialsApi = apiGenerator<Systems.CredentialsApi>(
Systems,
Systems.CredentialsApi,
basePath,
jwt
);
return errorDecoder<Systems.RespBasic>(() =>
api.createUserCredential(params)
);
};

export default createUserCredential;
1 change: 1 addition & 0 deletions lib/tapisui-api/src/systems/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { default as undeleteSystem } from './undeleteSystem';
export { default as shareSystemPublic } from './shareSystemPublic';
export { default as unShareSystemPublic } from './unShareSystemPublic';
export { default as createChildSystem } from './createChildSystem';
export { default as createUserCredential } from './createUserCredential'
1 change: 1 addition & 0 deletions lib/tapisui-hooks/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 50 additions & 51 deletions lib/tapisui-hooks/src/systems/useCreateCredential.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
// import { useMutation, MutateOptions, useQueryClient } from 'react-query';
// import { Systems } from '@tapis/tapis-typescript';
// import { Systems as API } from '@tapis/tapisui-api';
// import { useTapisConfig } from '../../';
// import QueryKeys from './queryKeys';
import { useMutation, MutateOptions, useQueryClient } from 'react-query';
import { Systems } from '@tapis/tapis-typescript';
import { Systems as API } from '@tapis/tapisui-api';
import { useTapisConfig } from '../../';
import QueryKeys from './queryKeys';

// type CreateUserCredentialHookParams = {
// systemId: string;
// username: string;
// reqUpdateCredential: Systems.ReqUpdateCredential
// };
type CreateUserCredentialHookParams = {
systemId: string;
userName: string;
reqUpdateCredential: Systems.ReqUpdateCredential
};

// const useCreate = () => {
// const { basePath, accessToken } = useTapisConfig();
// const jwt = accessToken?.access_token || '';
// const queryClient = useQueryClient();
const useCreate = () => {
const { basePath, accessToken } = useTapisConfig();
const jwt = accessToken?.access_token || '';
const queryClient = useQueryClient();

// // The useMutation react-query hook is used to call operations that make server-side changes
// // (Other hooks would be used for data retrieval)
// //
// // In this case, create helper is called to perform the operation
// const { mutate, isLoading, isError, isSuccess, data, error, reset } =
// useMutation<Systems.RespBasic, Error, CreateUserCredentialHookParams>(
// [QueryKeys.createUserCredential, basePath, jwt],
// (params) => API.createUserCredential({ reqGroup: params }, basePath, jwt)
// );
// The useMutation react-query hook is used to call operations that make server-side changes
// (Other hooks would be used for data retrieval)
//
// In this case, create helper is called to perform the operation
const { mutate, isLoading, isError, isSuccess, data, error, reset } =
useMutation<Systems.RespBasic, Error, CreateUserCredentialHookParams>(
[QueryKeys.createUserCredential, basePath, jwt],
(params) => API.createUserCredentials(params, basePath, jwt)
);

// const invalidate = () => {
// queryClient.invalidateQueries(QueryKeys.list);
// };
const invalidate = () => {
queryClient.invalidateQueries(QueryKeys.list);
};

// // Return hook object with loading states and login function
// return {
// isLoading,
// isError,
// isSuccess,
// data,
// error,
// reset,
// invalidate,
// create: (
// params: CreateGroupHookParams,
// // react-query options to allow callbacks such as onSuccess
// options?: MutateOptions<
// Systems.RespResourceURL,
// Error,
// CreateGroupHookParams
// >
// ) => {
// // Call mutate to trigger a single post-like API operation
// return mutate(params, options);
// },
// };
// };
// Return hook object with loading states and login function
return {
isLoading,
isError,
isSuccess,
data,
error,
reset,
invalidate,
create: (
params: CreateUserCredentialHookParams,
// react-query options to allow callbacks such as onSuccess
options?: MutateOptions<
Systems.RespBasic,
Error,
CreateUserCredentialHookParams
>
) => {
// Call mutate to trigger a single post-like API operation
return mutate(params, options);
},
};
};

// export default useCreate;
export {};
export default useCreate;

0 comments on commit f47dce8

Please sign in to comment.