/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { SupersetClient, t } from '@superset-ui/core';
import { FormModal, FormItem, Input } from '@superset-ui/core/components';
import { useToasts } from 'src/components/MessageToasts/withToasts';
import { User } from 'src/types/bootstrapTypes';
import { BaseUserListModalProps, FormValues } from '../users/types';
export interface UserInfoModalProps extends BaseUserListModalProps {
isEditMode?: boolean;
user?: User;
}
function UserInfoModal({
show,
onHide,
onSave,
isEditMode,
user,
}: UserInfoModalProps) {
const { addDangerToast, addSuccessToast } = useToasts();
const requiredFields = isEditMode
? ['first_name', 'last_name']
: ['password', 'confirm_password'];
const initialValues = isEditMode
? {
first_name: user?.firstName,
last_name: user?.lastName,
}
: {};
const handleFormSubmit = async (values: FormValues) => {
try {
const { confirm_password, ...payload } = values;
await SupersetClient.put({
endpoint: `/api/v1/me/`,
jsonPayload: { ...payload },
});
addSuccessToast(
isEditMode
? t('The user was updated successfully')
: t('The password reset was successful'),
);
onSave();
} catch (error) {
addDangerToast(t('Something went wrong while saving the user info'));
}
};
const EditModeFields = () => (
<>
>
);
const ResetPasswordFields = () => (
<>
({
validator(_, value) {
if (!value || getFieldValue('password') === value) {
return Promise.resolve();
}
return Promise.reject(new Error(t('Passwords do not match!')));
},
}),
]}
>
>
);
return (
{isEditMode ? : }
);
}
export const UserInfoResetPasswordModal = (
props: Omit,
) => ;
export const UserInfoEditModal = (
props: Omit & { user: User },
) => ;