-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
137 changed files
with
2,050 additions
and
996 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
client/a8c-for-agencies/data/team/use-transfer-ownership.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useMutation, UseMutationOptions, UseMutationResult } from '@tanstack/react-query'; | ||
import wpcom from 'calypso/lib/wp'; | ||
import { useSelector } from 'calypso/state'; | ||
import { getActiveAgencyId } from 'calypso/state/a8c-for-agencies/agency/selectors'; | ||
|
||
interface APIError { | ||
status: number; | ||
code: string | null; | ||
message: string; | ||
} | ||
|
||
export interface Params { | ||
id: number; | ||
} | ||
|
||
interface APIResponse { | ||
success: boolean; | ||
} | ||
|
||
function transferOwnershipMutation( params: Params, agencyId?: number ): Promise< APIResponse > { | ||
if ( ! agencyId ) { | ||
throw new Error( 'Agency ID is required to transfer ownership' ); | ||
} | ||
|
||
return wpcom.req.post( { | ||
apiNamespace: 'wpcom/v2', | ||
path: `/agency/${ agencyId }/transfer-ownership`, | ||
method: 'PUT', | ||
body: { | ||
new_owner_id: params.id, | ||
}, | ||
} ); | ||
} | ||
|
||
export default function useTransferOwnershipMutation< TContext = unknown >( | ||
options?: UseMutationOptions< APIResponse, APIError, Params, TContext > | ||
): UseMutationResult< APIResponse, APIError, Params, TContext > { | ||
const agencyId = useSelector( getActiveAgencyId ); | ||
|
||
return useMutation< APIResponse, APIError, Params, TContext >( { | ||
...options, | ||
mutationFn: ( args ) => transferOwnershipMutation( args, agencyId ), | ||
} ); | ||
} |
42 changes: 42 additions & 0 deletions
42
client/a8c-for-agencies/hooks/use-update-tags-for-sites.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useMutation, UseMutationOptions, UseMutationResult } from '@tanstack/react-query'; | ||
import SiteTag from 'calypso/a8c-for-agencies/types/site-tag'; | ||
import wpcom from 'calypso/lib/wp'; | ||
import { useSelector } from 'calypso/state'; | ||
import { getActiveAgencyId } from 'calypso/state/a8c-for-agencies/agency/selectors'; | ||
import { APIError } from 'calypso/state/partner-portal/types'; | ||
|
||
interface UpdateTagsForSitesMutationOptions { | ||
siteIds: number[]; | ||
tags: string[]; | ||
} | ||
|
||
function mutationUpdateSiteTags( { | ||
agencyId, | ||
siteIds, | ||
tags, | ||
}: UpdateTagsForSitesMutationOptions & { agencyId: number | undefined } ): Promise< SiteTag[] > { | ||
if ( ! agencyId ) { | ||
throw new Error( 'Agency ID is required to update the tags' ); | ||
} | ||
|
||
return wpcom.req.put( { | ||
method: 'PUT', | ||
apiNamespace: 'wpcom/v2', | ||
path: `/agency/${ agencyId }/sites/tags`, | ||
body: { | ||
tags, | ||
site_ids: siteIds, | ||
}, | ||
} ); | ||
} | ||
|
||
export default function useUpdateTagsForSitesMutation< TContext = unknown >( | ||
options?: UseMutationOptions< SiteTag[], APIError, UpdateTagsForSitesMutationOptions, TContext > | ||
): UseMutationResult< SiteTag[], APIError, UpdateTagsForSitesMutationOptions, TContext > { | ||
const agencyId = useSelector( getActiveAgencyId ); | ||
|
||
return useMutation< SiteTag[], APIError, UpdateTagsForSitesMutationOptions, TContext >( { | ||
...options, | ||
mutationFn: ( args ) => mutationUpdateSiteTags( { ...args, agencyId } ), | ||
} ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.