Skip to content

Commit 107c50b

Browse files
rdonigianCarsonF
andauthored
Make Partner Start Date column editable (#1657)
Co-authored-by: Carson Full <[email protected]>
1 parent 6869e92 commit 107c50b

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

src/components/PartnersDataGrid/PartnerColumns.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export const PartnerColumns: Array<GridColDef<Partner>> = [
4242
field: 'startDate',
4343
...dateColumn(),
4444
width: 130,
45+
editable: true,
46+
isEditable: ({ row }) => row.startDate.canEdit,
4547
},
4648
{
4749
headerName: 'Created Date',
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mutation UpdatePartnerGrid($input: UpdatePartner!) {
2+
updatePartner(input: { partner: $input }) {
3+
partner {
4+
...partnerDataGridRow
5+
}
6+
}
7+
}

src/components/PartnersDataGrid/partnerDataGridRow.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fragment partnerDataGridRow on Partner {
1818
value
1919
}
2020
startDate {
21+
canEdit
2122
value
2223
}
2324
createdAt
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useGridMutation } from '../Grid';
2+
import { PartnerDataGridRowFragmentDoc as PartnerRow } from './partnerDataGridRow.graphql';
3+
import { UpdatePartnerGridDocument as UpdatePartner } from './UpdatePartnerGrid.graphql';
4+
5+
export const useProcessPartnerUpdate = () =>
6+
useGridMutation(PartnerRow, UpdatePartner, (row) => ({
7+
variables: {
8+
input: {
9+
id: row.id,
10+
startDate: row.startDate.value,
11+
},
12+
},
13+
optimisticResponse: {
14+
updatePartner: {
15+
__typename: 'UpdatePartnerOutput',
16+
partner: row,
17+
},
18+
},
19+
}));

src/scenes/Partners/List/PartnerGrid.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
PartnerToolbar,
1818
} from '~/components/PartnersDataGrid/PartnerColumns';
1919
import { PartnerDataGridRowFragment as Partner } from '~/components/PartnersDataGrid/partnerDataGridRow.graphql';
20+
import { useProcessPartnerUpdate } from '~/components/PartnersDataGrid/useProcessPartnerUpdate';
2021
import { PartnersDocument } from './PartnerList.graphql';
2122

2223
export const PartnerGrid = () => {
@@ -42,6 +43,8 @@ export const PartnerGrid = () => {
4243
[dataGridProps.slotProps]
4344
);
4445

46+
const processPartnerUpdate = useProcessPartnerUpdate();
47+
4548
return (
4649
<DataGrid<Partner>
4750
{...DefaultDataGridStyles}
@@ -50,6 +53,7 @@ export const PartnerGrid = () => {
5053
slotProps={slotProps}
5154
columns={PartnerColumns}
5255
initialState={PartnerInitialState}
56+
processRowUpdate={processPartnerUpdate}
5357
headerFilters
5458
hideFooter
5559
sx={[flexLayout, noHeaderFilterButtons, noFooter]}

0 commit comments

Comments
 (0)