Chore: Duplicate certain user fields to workspaceMember (#1514)
* Move certain user fields to workspaceMember Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Merge main Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Update the generated GraphQL Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Update hooks Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Rework typing * Fix tests * Remove console logs --------- Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -15,6 +15,7 @@ import { useTableViews } from '@/views/hooks/useTableViews';
|
||||
import {
|
||||
UpdateOneCompanyMutationVariables,
|
||||
useGetCompaniesQuery,
|
||||
useGetWorkspaceMembersLazyQuery,
|
||||
useUpdateOneCompanyMutation,
|
||||
} from '~/generated/graphql';
|
||||
import { companiesFilters } from '~/pages/companies/companies-filters';
|
||||
@ -33,6 +34,7 @@ export function CompanyTable() {
|
||||
const [updateEntityMutation] = useUpdateOneCompanyMutation();
|
||||
const upsertEntityTableItem = useUpsertEntityTableItem();
|
||||
|
||||
const [getWorkspaceMember] = useGetWorkspaceMembersLazyQuery();
|
||||
const { createView, deleteView, submitCurrentView, updateView } =
|
||||
useTableViews({
|
||||
objectId: 'company',
|
||||
@ -44,6 +46,40 @@ export function CompanyTable() {
|
||||
const { setContextMenuEntries } = useCompanyTableContextMenuEntries();
|
||||
const { setActionBarEntries } = useCompanyTableActionBarEntries();
|
||||
|
||||
async function updateCompany(variables: UpdateOneCompanyMutationVariables) {
|
||||
const workspaceMemberAccountOwner = variables.data.accountOwner
|
||||
? (
|
||||
await getWorkspaceMember({
|
||||
variables: {
|
||||
where: {
|
||||
userId: { equals: variables.data.accountOwner.connect?.id },
|
||||
},
|
||||
},
|
||||
})
|
||||
).data?.workspaceMembers?.[0]
|
||||
: undefined;
|
||||
|
||||
const data = {
|
||||
...variables.data,
|
||||
workspaceMemberAccountOwner: {
|
||||
connect: { id: workspaceMemberAccountOwner?.id },
|
||||
},
|
||||
};
|
||||
|
||||
updateEntityMutation({
|
||||
variables: {
|
||||
...variables,
|
||||
data,
|
||||
},
|
||||
onCompleted: (data) => {
|
||||
if (!data.updateOneCompany) {
|
||||
return;
|
||||
}
|
||||
upsertEntityTableItem(data.updateOneCompany);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<EntityTableEffect
|
||||
@ -75,17 +111,7 @@ export function CompanyTable() {
|
||||
variables,
|
||||
}: {
|
||||
variables: UpdateOneCompanyMutationVariables;
|
||||
}) =>
|
||||
updateEntityMutation({
|
||||
variables,
|
||||
onCompleted: (data) => {
|
||||
if (!data.updateOneCompany) {
|
||||
return;
|
||||
}
|
||||
upsertEntityTableItem(data.updateOneCompany);
|
||||
},
|
||||
})
|
||||
}
|
||||
}) => updateCompany(variables)}
|
||||
/>
|
||||
</ViewBarContext.Provider>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user