environments/review-accounts-h-uli5de/deployments/3523
parent
25d3925b76
commit
e01ee84ee9
@ -0,0 +1,18 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntity } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks/useApi';
|
||||
import { type PatronUser, patronUserSchema } from 'soapbox/schemas';
|
||||
|
||||
function usePatronUser(url?: string) {
|
||||
const api = useApi();
|
||||
|
||||
const { entity: patronUser, ...result } = useEntity<PatronUser>(
|
||||
[Entities.PATRON_USERS, url || ''],
|
||||
() => api.get(`/api/patron/v1/accounts/${encodeURIComponent(url!)}`),
|
||||
{ schema: patronUserSchema, enabled: !!url },
|
||||
);
|
||||
|
||||
return { patronUser, ...result };
|
||||
}
|
||||
|
||||
export { usePatronUser };
|
@ -0,0 +1,15 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const patronUserSchema = z.object({
|
||||
is_patron: z.boolean().catch(false),
|
||||
url: z.string().url(),
|
||||
}).transform((patron) => {
|
||||
return {
|
||||
id: patron.url,
|
||||
...patron,
|
||||
};
|
||||
});
|
||||
|
||||
type PatronUser = z.infer<typeof patronUserSchema>;
|
||||
|
||||
export { patronUserSchema, type PatronUser };
|
Loading…
Reference in new issue