-
Notifications
You must be signed in to change notification settings - Fork 0
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
34 changed files
with
530 additions
and
414 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import { useHttp } from './core'; | ||
import { apiRequest, createQuery } from './core'; | ||
|
||
export const isValidId = (id?: string) => id && /^[\dA-Za-z]+$/.test(id); | ||
|
||
export type ItemIdResponse = { | ||
item_id: string; | ||
}; | ||
export type ItemIdResponse = typeof useGenerateId.$inferData; | ||
|
||
export const useGenerateId = () => useHttp<ItemIdResponse>('/api/item/next'); | ||
export const useGenerateId = createQuery({ | ||
queryKey: ['generate-id'], | ||
fetcher: async () => { | ||
const response = await apiRequest('/item/next', 'get', {}); | ||
|
||
return response.data; | ||
}, | ||
}); |
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 |
---|---|---|
@@ -1,11 +1,8 @@ | ||
import { ApiRequest, useHttp } from '../core'; | ||
import { ApiRoute, useHttp } from '../core'; | ||
|
||
export const isValidId = (id?: string) => id && /^[\dA-Za-z]+$/.test(id); | ||
|
||
export type ItemIdResponse = ApiRequest< | ||
'/item/next', | ||
'get' | ||
>['response']['data']; | ||
export type ItemIdResponse = ApiRoute<'/item/next', 'get'>['response']['data']; | ||
|
||
// TODO: migrate away from useHttp (to mutation) | ||
export const useGenerateId = () => useHttp<ItemIdResponse>('/api/item/next'); |
Oops, something went wrong.