File size: 1,121 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import { useMutation } from '@tanstack/react-query';
import wp from 'calypso/lib/wp';
import { SiteId } from 'calypso/types';
import { log } from '../logger';
import { MigrationStatus } from '../types';
const request = async ( {
siteId,
status,
}: {
siteId: SiteId;
status: MigrationStatus;
} ): Promise< Response > => {
await wp.req.post( {
path: `/sites/${ siteId }/site-migration-status-sticker`,
apiNamespace: 'wpcom/v2',
body: {
status_sticker: status,
},
} );
return { status: 'success' };
};
interface Response {
status: 'success' | 'skipped';
}
interface Variables {
status: MigrationStatus;
}
export const useUpdateMigrationStatus = ( siteId: SiteId | undefined ) => {
return useMutation< Response, Error, Variables >( {
mutationKey: [ 'migration-status', siteId ],
mutationFn: ( { status } ) => {
if ( ! siteId ) {
throw new Error( 'Site ID is required' );
}
return request( { siteId, status } );
},
onError: ( error ) => {
log( {
message: 'Error updating migration status',
siteId,
extra: {
error: error.message,
},
} );
},
} );
};
|