* feat: Add support for custom profile attributes in edit profile form feat: Add support for custom profile attributes in edit profile refactor: Normalize whitespace in CustomAttribute type definition fix: Resolve type mismatch for customAttributes in UserInfo interface test: Add test for udpateCustomProfileAttributeValues method fix typing, submit changes to server missing files test: Add tests for CustomProfileField component fix naming fix imports fix feat: Add field_refs hook for managing field references feat: Make `setRef` ref parameter optional with default no-op implementation refactor: Replace CustomProfileField with useFieldRefs for profile form refactor: Optimize edit profile screen imports and custom attributes handling refactor: Move custom attributes logic to remote actions in user.ts address PR reviews test: Add tests for custom attributes in edit profile test: Add tests for EditProfile component with custom attributes fix: Add UserModel type assertion to currentUser in edit profile tests test: Add tests for ProfileForm custom attributes functionality test: Add comprehensive tests for useFieldRefs hook test: Add tests for fetchCustomAttributes and updateCustomAttributes add tests remove unneeded files review changes remove counter from hook remove package.resolved create interface for reuse of record * fix signature type
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {useRef, useCallback} from 'react';
|
|
|
|
import {type FloatingTextInputRef} from '@components/floating_text_input_label';
|
|
|
|
const useFieldRefs = (): [(key: string) => FloatingTextInputRef | undefined, (key: string) => (providedRef: FloatingTextInputRef) => () => void] => {
|
|
const allRefs = useRef<Map<string, FloatingTextInputRef>>();
|
|
|
|
const getAllRefs = useCallback(() => {
|
|
if (!allRefs.current) {
|
|
allRefs.current = new Map();
|
|
}
|
|
return allRefs.current;
|
|
},
|
|
[]);
|
|
|
|
const setRef = useCallback(
|
|
(key: string) => {
|
|
return (providedRef: FloatingTextInputRef) => {
|
|
const refs = getAllRefs();
|
|
refs.set(key, providedRef);
|
|
|
|
return () => {
|
|
refs.delete(key);
|
|
};
|
|
};
|
|
},
|
|
[getAllRefs]);
|
|
|
|
const getRef = useCallback((key: string): FloatingTextInputRef | undefined => {
|
|
const refs = getAllRefs();
|
|
return refs.get(key);
|
|
},
|
|
[getAllRefs]);
|
|
|
|
return [getRef, setRef];
|
|
};
|
|
|
|
export default useFieldRefs;
|