-
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.
BackupScheduleSetting: enable fetching and updating schedule time (#9…
…5449) * Add useScheduledTimeQuery hook * Add useScheduledTimeMutation * Add backup schedule setting in development environment * Query and update schedule time * Use isFetching instead of isLoading for query * Add details on who updated the schedule time * Import TranslateResult * Update messages * Wrap settings page in SiteOffsetProvider context * Add local time support * Adjust scheduledBy type to be a `string | null` * Add backup schedule setting to cloud horizon env * Refactor convertHourToRange Refactor convertHourToRange to consider UTC as a 24-hour format. Also, I’m shifting from building the time range manually, to use moment().
- Loading branch information
Showing
6 changed files
with
177 additions
and
18 deletions.
There are no files selected for viewing
123 changes: 105 additions & 18 deletions
123
client/components/jetpack/backup-schedule-setting/index.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useMutation, UseMutationResult, UseMutationOptions } from '@tanstack/react-query'; | ||
import wpcom from 'calypso/lib/wp'; | ||
import { useSelector } from 'calypso/state'; | ||
import { getSelectedSiteId } from 'calypso/state/ui/selectors'; | ||
|
||
export interface UpdateSchedulePayload { | ||
scheduledHour: number; // The new scheduled hour (0-23) | ||
} | ||
|
||
export interface UpdateScheduleResponse { | ||
ok: boolean; | ||
error: string; | ||
} | ||
|
||
export default function useScheduledTimeMutation< | ||
TData = UpdateScheduleResponse, | ||
TError = Error, | ||
TContext = unknown, | ||
>( | ||
options: UseMutationOptions< TData, TError, UpdateSchedulePayload, TContext > = {} | ||
): UseMutationResult< TData, TError, UpdateSchedulePayload, TContext > { | ||
const siteId = useSelector( getSelectedSiteId ) as number; | ||
|
||
return useMutation< TData, TError, UpdateSchedulePayload, TContext >( { | ||
...options, | ||
mutationFn: ( { scheduledHour }: UpdateSchedulePayload ): Promise< TData > => { | ||
return wpcom.req.post( { | ||
path: `/sites/${ siteId }/rewind/scheduled`, | ||
apiNamespace: 'wpcom/v2', | ||
body: { schedule_hour: scheduledHour }, | ||
} ); | ||
}, | ||
} ); | ||
} |
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,34 @@ | ||
import { useQuery, UseQueryResult } from '@tanstack/react-query'; | ||
import wpcom from 'calypso/lib/wp'; | ||
|
||
export interface ScheduledTimeApi { | ||
ok: boolean; | ||
scheduled_hour: number; | ||
scheduled_by: string | null; | ||
} | ||
|
||
export interface ScheduledTime { | ||
scheduledHour: number; | ||
scheduledBy: string | null; | ||
} | ||
|
||
const useScheduledTimeQuery = ( blogId: number ): UseQueryResult< ScheduledTime, Error > => { | ||
const queryKey = [ 'jetpack-backup-scheduled-time', blogId ]; | ||
|
||
return useQuery< ScheduledTimeApi, Error, ScheduledTime >( { | ||
queryKey, | ||
queryFn: async () => | ||
wpcom.req.get( { | ||
path: `/sites/${ blogId }/rewind/scheduled`, | ||
apiNamespace: 'wpcom/v2', | ||
} ), | ||
refetchIntervalInBackground: false, | ||
refetchOnWindowFocus: false, | ||
select: ( data ) => ( { | ||
scheduledHour: data.scheduled_hour, | ||
scheduledBy: data.scheduled_by, | ||
} ), | ||
} ); | ||
}; | ||
|
||
export default useScheduledTimeQuery; |
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