pl-fe: remove account normalizer and so
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@@ -5,10 +5,9 @@ import { useEntityLookup } from 'pl-fe/entity-store/hooks/use-entity-lookup';
|
||||
import { useClient } from 'pl-fe/hooks/use-client';
|
||||
import { useFeatures } from 'pl-fe/hooks/use-features';
|
||||
import { useLoggedIn } from 'pl-fe/hooks/use-logged-in';
|
||||
import { type Account, normalizeAccount } from 'pl-fe/normalizers/account';
|
||||
import { useRelationshipQuery } from 'pl-fe/queries/accounts/use-relationship';
|
||||
|
||||
import type { Account as BaseAccount } from 'pl-api';
|
||||
import type { Account } from 'pl-api';
|
||||
|
||||
interface UseAccountLookupOpts {
|
||||
withRelationship?: boolean;
|
||||
@@ -20,11 +19,11 @@ const useAccountLookup = (acct: string | undefined, opts: UseAccountLookupOpts =
|
||||
const { me } = useLoggedIn();
|
||||
const { withRelationship } = opts;
|
||||
|
||||
const { entity, isUnauthorized, ...result } = useEntityLookup<BaseAccount, Account>(
|
||||
const { entity, isUnauthorized, ...result } = useEntityLookup<Account>(
|
||||
Entities.ACCOUNTS,
|
||||
(account) => account.acct.toLowerCase() === acct?.toLowerCase(),
|
||||
() => client.accounts.lookupAccount(acct!),
|
||||
{ enabled: !!acct, transform: normalizeAccount },
|
||||
{ enabled: !!acct },
|
||||
);
|
||||
|
||||
const {
|
||||
|
||||
@@ -6,10 +6,9 @@ import { useAppSelector } from 'pl-fe/hooks/use-app-selector';
|
||||
import { useClient } from 'pl-fe/hooks/use-client';
|
||||
import { useFeatures } from 'pl-fe/hooks/use-features';
|
||||
import { useLoggedIn } from 'pl-fe/hooks/use-logged-in';
|
||||
import { type Account, normalizeAccount } from 'pl-fe/normalizers/account';
|
||||
import { useRelationshipQuery } from 'pl-fe/queries/accounts/use-relationship';
|
||||
|
||||
import type { Account as BaseAccount } from 'pl-api';
|
||||
import type { Account } from 'pl-api';
|
||||
|
||||
interface UseAccountOpts {
|
||||
withRelationship?: boolean;
|
||||
@@ -21,10 +20,10 @@ const useAccount = (accountId?: string, opts: UseAccountOpts = {}) => {
|
||||
const { me } = useLoggedIn();
|
||||
const { withRelationship } = opts;
|
||||
|
||||
const { entity, isUnauthorized, ...result } = useEntity<BaseAccount, Account>(
|
||||
const { entity, isUnauthorized, ...result } = useEntity<Account>(
|
||||
[Entities.ACCOUNTS, accountId!],
|
||||
() => client.accounts.getAccount(accountId!),
|
||||
{ enabled: !!accountId, transform: normalizeAccount },
|
||||
{ enabled: !!accountId },
|
||||
);
|
||||
|
||||
const meta = useAppSelector((state) => accountId ? state.accounts_meta[accountId] : undefined);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { EntityCallbacks } from 'pl-fe/entity-store/hooks/types';
|
||||
import { useTransaction } from 'pl-fe/entity-store/hooks/use-transaction';
|
||||
import { useClient } from 'pl-fe/hooks/use-client';
|
||||
|
||||
import type { Account } from 'pl-fe/normalizers/account';
|
||||
import type { Account } from 'pl-api';
|
||||
|
||||
const useSuggest = () => {
|
||||
const client = useClient();
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useTransaction } from 'pl-fe/entity-store/hooks/use-transaction';
|
||||
import { useClient } from 'pl-fe/hooks/use-client';
|
||||
|
||||
import type { EntityCallbacks } from 'pl-fe/entity-store/hooks/types';
|
||||
import type { Account } from 'pl-fe/normalizers/account';
|
||||
import type { Account } from 'pl-api';
|
||||
|
||||
const useVerify = () => {
|
||||
const client = useClient();
|
||||
|
||||
@@ -3,9 +3,8 @@ import * as v from 'valibot';
|
||||
import { Entities } from 'pl-fe/entity-store/entities';
|
||||
import { useCreateEntity } from 'pl-fe/entity-store/hooks/use-create-entity';
|
||||
import { useClient } from 'pl-fe/hooks/use-client';
|
||||
import { normalizeGroupMember } from 'pl-fe/normalizers/group-member';
|
||||
|
||||
import type { Group, GroupMember as GroupMember, GroupRole } from 'pl-api';
|
||||
import type { Group, GroupMember, GroupRole } from 'pl-api';
|
||||
|
||||
const useDemoteGroupMember = (group: Pick<Group, 'id'>, groupMember: Pick<GroupMember, 'id'>) => {
|
||||
const client = useClient();
|
||||
@@ -13,7 +12,7 @@ const useDemoteGroupMember = (group: Pick<Group, 'id'>, groupMember: Pick<GroupM
|
||||
const { createEntity } = useCreateEntity(
|
||||
[Entities.GROUP_MEMBERSHIPS, groupMember.id],
|
||||
({ account_ids, role }: { account_ids: string[]; role: GroupRole }) => client.experimental.groups.demoteGroupUsers(group.id, account_ids, role),
|
||||
{ schema: v.pipe(v.any(), v.transform(arr => arr[0])), transform: normalizeGroupMember },
|
||||
{ schema: v.pipe(v.any(), v.transform(arr => arr[0])) },
|
||||
);
|
||||
|
||||
return createEntity;
|
||||
|
||||
@@ -4,10 +4,10 @@ import { Entities } from 'pl-fe/entity-store/entities';
|
||||
import { useDismissEntity } from 'pl-fe/entity-store/hooks/use-dismiss-entity';
|
||||
import { useEntities } from 'pl-fe/entity-store/hooks/use-entities';
|
||||
import { useClient } from 'pl-fe/hooks/use-client';
|
||||
import { normalizeAccount } from 'pl-fe/normalizers/account';
|
||||
|
||||
import { useGroupRelationship } from './use-group-relationship';
|
||||
|
||||
import type { Account } from 'pl-api';
|
||||
import type { ExpandedEntitiesPath } from 'pl-fe/entity-store/hooks/types';
|
||||
|
||||
const useGroupMembershipRequests = (groupId: string) => {
|
||||
@@ -16,11 +16,10 @@ const useGroupMembershipRequests = (groupId: string) => {
|
||||
|
||||
const { groupRelationship: relationship } = useGroupRelationship(groupId);
|
||||
|
||||
const { entities, invalidate, fetchEntities, ...rest } = useEntities(
|
||||
const { entities, invalidate, fetchEntities, ...rest } = useEntities<Account>(
|
||||
path,
|
||||
() => client.experimental.groups.getGroupMembershipRequests(groupId),
|
||||
{
|
||||
transform: normalizeAccount,
|
||||
enabled: relationship?.role === GroupRoles.OWNER || relationship?.role === GroupRoles.ADMIN,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -3,7 +3,6 @@ import * as v from 'valibot';
|
||||
import { Entities } from 'pl-fe/entity-store/entities';
|
||||
import { useCreateEntity } from 'pl-fe/entity-store/hooks/use-create-entity';
|
||||
import { useClient } from 'pl-fe/hooks/use-client';
|
||||
import { normalizeGroupMember } from 'pl-fe/normalizers/group-member';
|
||||
|
||||
import type { Group, GroupMember, GroupRole } from 'pl-api';
|
||||
|
||||
@@ -13,7 +12,7 @@ const usePromoteGroupMember = (group: Pick<Group, 'id'>, groupMember: Pick<Group
|
||||
const { createEntity } = useCreateEntity(
|
||||
[Entities.GROUP_MEMBERSHIPS, groupMember.id],
|
||||
({ account_ids, role }: { account_ids: string[]; role: GroupRole }) => client.experimental.groups.promoteGroupUsers(group.id, account_ids, role),
|
||||
{ schema: v.pipe(v.any(), v.transform(arr => arr[0])), transform: normalizeGroupMember },
|
||||
{ schema: v.pipe(v.any(), v.transform(arr => arr[0])) },
|
||||
);
|
||||
|
||||
return createEntity;
|
||||
|
||||
Reference in New Issue
Block a user