mirror of
https://github.com/umami-software/umami.git
synced 2026-02-16 02:25:35 +01:00
Added SettingsContext.
This commit is contained in:
parent
3f657d97b2
commit
4fca98d25d
22 changed files with 106 additions and 83 deletions
|
|
@ -1,61 +0,0 @@
|
|||
'use client';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Item, Loading, Tabs, useToasts } from 'react-basics';
|
||||
import UserEditForm from '../UserEditForm';
|
||||
import PageHeader from 'components/layout/PageHeader';
|
||||
import useApi from 'components/hooks/useApi';
|
||||
import UserWebsites from '../UserWebsites';
|
||||
import useMessages from 'components/hooks/useMessages';
|
||||
|
||||
export function UserSettings({ userId }) {
|
||||
const { formatMessage, labels, messages } = useMessages();
|
||||
const [edit, setEdit] = useState(false);
|
||||
const [values, setValues] = useState(null);
|
||||
const [tab, setTab] = useState('details');
|
||||
const { get, useQuery } = useApi();
|
||||
const { showToast } = useToasts();
|
||||
const { data, isLoading } = useQuery({
|
||||
queryKey: ['user', userId],
|
||||
queryFn: () => {
|
||||
if (userId) {
|
||||
return get(`/users/${userId}`);
|
||||
}
|
||||
},
|
||||
gcTime: 0,
|
||||
});
|
||||
|
||||
const handleSave = data => {
|
||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||
if (data) {
|
||||
setValues(state => ({ ...state, ...data }));
|
||||
}
|
||||
|
||||
if (edit) {
|
||||
setEdit(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
setValues(data);
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
if (isLoading || !values) {
|
||||
return <Loading size="lg" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={values?.username} />
|
||||
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30, fontSize: 14 }}>
|
||||
<Item key="details">{formatMessage(labels.details)}</Item>
|
||||
<Item key="websites">{formatMessage(labels.websites)}</Item>
|
||||
</Tabs>
|
||||
{tab === 'details' && <UserEditForm userId={userId} data={values} onSave={handleSave} />}
|
||||
{tab === 'websites' && <UserWebsites userId={userId} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default UserSettings;
|
||||
Loading…
Add table
Add a link
Reference in a new issue