Files
twenty/front/src/modules/people/editable-field/components/PeopleFullNameEditableField.tsx
Weiko 43b0945028 Reorganize context/states/selectors in dedicated folders (#1205)
* Reorganize context/states/selectors in dedicated folders

* linter
2023-08-14 15:29:47 -07:00

60 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useState } from 'react';
import { FieldRecoilScopeContext } from '@/ui/editable-field/states/recoil-scope-contexts/FieldRecoilScopeContext';
import { DoubleTextInputEdit } from '@/ui/input/double-text/components/DoubleTextInputEdit';
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
import { Person, useUpdateOnePersonMutation } from '~/generated/graphql';
type OwnProps = {
people: Pick<Person, 'id' | 'firstName' | 'lastName'>;
};
export function PeopleFullNameEditableField({ people }: OwnProps) {
const [internalValueFirstName, setInternalValueFirstName] = useState(
people.firstName,
);
const [internalValueLastName, setInternalValueLastName] = useState(
people.lastName,
);
const [updatePeople] = useUpdateOnePersonMutation();
async function handleChange(
newValueFirstName: string,
newValueLastName: string,
) {
setInternalValueFirstName(newValueFirstName);
setInternalValueLastName(newValueLastName);
handleSubmit(newValueFirstName, newValueLastName);
}
async function handleSubmit(
newValueFirstName: string,
newValueLastName: string,
) {
await updatePeople({
variables: {
where: {
id: people.id,
},
data: {
firstName: newValueFirstName ?? '',
lastName: newValueLastName ?? '',
},
},
});
}
return (
<RecoilScope SpecificContext={FieldRecoilScopeContext}>
<DoubleTextInputEdit
firstValuePlaceholder={'First name'} // Hack: Fake character to prevent password-manager from filling the field
secondValuePlaceholder={'Last name'} // Hack: Fake character to prevent password-manager from filling the field
firstValue={internalValueFirstName ?? ''}
secondValue={internalValueLastName ?? ''}
onChange={handleChange}
/>
</RecoilScope>
);
}