mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
feat: add useUiBootstrap hook and update send email state (#643)
* feat: add useUiBootstrap hook and update send email state in create user form * fix: set email based on config * fix: update cache key Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
This commit is contained in:
parent
7773d107bc
commit
4571e3af81
@ -13,6 +13,7 @@ import React from 'react';
|
||||
import useUsers from '../../../../hooks/api/getters/useUsers/useUsers';
|
||||
import ConditionallyRender from '../../../common/ConditionallyRender/ConditionallyRender';
|
||||
import { EDIT } from '../../../../constants/misc';
|
||||
import useUiBootstrap from '../../../../hooks/api/getters/useUiBootstrap/useUiBootstrap';
|
||||
|
||||
interface IUserForm {
|
||||
email: string;
|
||||
@ -48,6 +49,7 @@ const UserForm: React.FC<IUserForm> = ({
|
||||
}) => {
|
||||
const styles = useStyles();
|
||||
const { roles } = useUsers();
|
||||
const { bootstrap } = useUiBootstrap();
|
||||
|
||||
const sortRoles = (a, b) => {
|
||||
if (b.name[0] < a.name[0]) {
|
||||
@ -125,7 +127,7 @@ const UserForm: React.FC<IUserForm> = ({
|
||||
</RadioGroup>
|
||||
</FormControl>
|
||||
<ConditionallyRender
|
||||
condition={mode !== EDIT}
|
||||
condition={mode !== EDIT && bootstrap?.email}
|
||||
show={
|
||||
<FormControl>
|
||||
<Typography
|
||||
|
@ -1,15 +1,16 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import useUiBootstrap from '../../../../hooks/api/getters/useUiBootstrap/useUiBootstrap';
|
||||
import useUsers from '../../../../hooks/api/getters/useUsers/useUsers';
|
||||
|
||||
const useProjectRoleForm = (
|
||||
const useCreateUserForm = (
|
||||
initialName = '',
|
||||
initialEmail = '',
|
||||
initialSendEmail = true,
|
||||
initialRootRole = 1
|
||||
) => {
|
||||
const { bootstrap } = useUiBootstrap();
|
||||
const [name, setName] = useState(initialName);
|
||||
const [email, setEmail] = useState(initialEmail);
|
||||
const [sendEmail, setSendEmail] = useState(initialSendEmail);
|
||||
const [sendEmail, setSendEmail] = useState(false);
|
||||
const [rootRole, setRootRole] = useState(initialRootRole);
|
||||
const [errors, setErrors] = useState({});
|
||||
|
||||
@ -24,8 +25,8 @@ const useProjectRoleForm = (
|
||||
}, [initialEmail]);
|
||||
|
||||
useEffect(() => {
|
||||
setSendEmail(initialSendEmail);
|
||||
}, [initialSendEmail]);
|
||||
setSendEmail(bootstrap?.email || false);
|
||||
}, [bootstrap?.email]);
|
||||
|
||||
useEffect(() => {
|
||||
setRootRole(initialRootRole);
|
||||
@ -81,4 +82,4 @@ const useProjectRoleForm = (
|
||||
};
|
||||
};
|
||||
|
||||
export default useProjectRoleForm;
|
||||
export default useCreateUserForm;
|
||||
|
@ -76,7 +76,7 @@ const Feedback = ({ feedbackId, openUrl }: IFeedbackProps) => {
|
||||
setShowFeedback(false);
|
||||
}, 100);
|
||||
};
|
||||
console.log(feedback);
|
||||
|
||||
const pnps = feedback.find(feedback => feedback.feedbackId === feedbackId);
|
||||
|
||||
if (pnps?.given || pnps?.neverShow) {
|
||||
|
@ -0,0 +1,39 @@
|
||||
import handleErrorResponses from '../httpErrorResponseHandler';
|
||||
import useSWR, { mutate, SWRConfiguration } from 'swr';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { formatApiPath } from '../../../../utils/format-path';
|
||||
|
||||
const useUiBootstrap = (options: SWRConfiguration = {}) => {
|
||||
const BOOTSTRAP_CACHE_KEY = `api/admin/ui-bootstrap`;
|
||||
|
||||
const fetcher = () => {
|
||||
const path = formatApiPath(`api/admin/ui-bootstrap`);
|
||||
|
||||
return fetch(path, {
|
||||
method: 'GET',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(handleErrorResponses('ui bootstrap'))
|
||||
.then(res => res.json());
|
||||
};
|
||||
|
||||
const { data, error } = useSWR(BOOTSTRAP_CACHE_KEY, fetcher, options);
|
||||
const [loading, setLoading] = useState(!error && !data);
|
||||
|
||||
const refetchUiBootstrap = () => {
|
||||
mutate(BOOTSTRAP_CACHE_KEY);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(!error && !data);
|
||||
}, [data, error]);
|
||||
|
||||
return {
|
||||
bootstrap: data,
|
||||
error,
|
||||
loading,
|
||||
refetchUiBootstrap,
|
||||
};
|
||||
};
|
||||
|
||||
export default useUiBootstrap;
|
Loading…
Reference in New Issue
Block a user