Merge branch 'develop' of github.com:makeplane/plane into develop-deploy

This commit is contained in:
pablohashescobar 2023-11-24 11:19:18 +05:30
commit 11c2aa1faf
8 changed files with 260 additions and 27 deletions

View File

@ -76,7 +76,7 @@ export const DateFilterModal: React.FC<Props> = ({ title, handleClose, isOpen, o
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
> >
<Dialog.Panel className="relative flex transform rounded-lg bg-custom-background-100 px-5 py-8 text-left shadow-custom-shadow-md transition-all sm:my-8 sm:w-full sm:max-w-2xl sm:p-6"> <Dialog.Panel className="relative flex transform rounded-lg bg-custom-background-100 px-5 py-8 text-left shadow-custom-shadow-md transition-all sm:my-8 sm:w-full sm:max-w-2xl sm:p-6">
<form className="space-y-4" onSubmit={handleSubmit(handleFormSubmit)}> <form className="space-y-4">
<div className="flex w-full justify-between"> <div className="flex w-full justify-between">
<Controller <Controller
control={control} control={control}
@ -130,7 +130,13 @@ export const DateFilterModal: React.FC<Props> = ({ title, handleClose, isOpen, o
<Button variant="neutral-primary" size="sm" onClick={handleClose}> <Button variant="neutral-primary" size="sm" onClick={handleClose}>
Cancel Cancel
</Button> </Button>
<Button variant="primary" size="sm" type="submit" disabled={isInvalid}> <Button
variant="primary"
size="sm"
type="button"
onClick={handleSubmit(handleFormSubmit)}
disabled={isInvalid}
>
Apply Apply
</Button> </Button>
</div> </div>

View File

@ -26,11 +26,6 @@ export const FilterExtraOptions: React.FC<Props> = observer((props) => {
return ( return (
<> <>
<FilterHeader
title="Extra Options"
isPreviewEnabled={previewEnabled}
handleIsPreviewEnabled={() => setPreviewEnabled(!previewEnabled)}
/>
{previewEnabled && ( {previewEnabled && (
<div> <div>
{ISSUE_EXTRA_OPTIONS.map((option) => { {ISSUE_EXTRA_OPTIONS.map((option) => {

View File

@ -73,7 +73,7 @@ export const IssueCommentEditor: React.FC<IIssueCommentEditor> = (props) => {
return ( return (
<form onSubmit={handleSubmit(handleAddComment)}> <form onSubmit={handleSubmit(handleAddComment)}>
<div className="space-y-2"> <div className="space-y-2 py-2">
<div className="h-full"> <div className="h-full">
<Controller <Controller
name="access" name="access"

View File

@ -148,7 +148,11 @@ export const ModuleCardItem: React.FC<Props> = observer((props) => {
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
{moduleStatus && ( {moduleStatus && (
<span <span
className={`flex items-center justify-center text-xs h-6 w-20 rounded-sm ${moduleStatus.textColor} ${moduleStatus.bgColor}`} className="flex items-center justify-center text-xs text-center h-6 w-20 rounded-sm"
style={{
color: moduleStatus.color,
backgroundColor: `${moduleStatus.color}20`,
}}
> >
{moduleStatus.label} {moduleStatus.label}
</span> </span>

View File

@ -157,7 +157,11 @@ export const ModuleListItem: React.FC<Props> = observer((props) => {
<div className="flex items-center justify-center"> <div className="flex items-center justify-center">
{moduleStatus && ( {moduleStatus && (
<span <span
className={`flex items-center justify-center text-xs h-6 w-20 rounded-sm ${moduleStatus.textColor} ${moduleStatus.bgColor}`} className="flex items-center justify-center text-xs text-center h-6 w-20 rounded-sm"
style={{
color: moduleStatus.color,
backgroundColor: `${moduleStatus.color}20`,
}}
> >
{moduleStatus.label} {moduleStatus.label}
</span> </span>

View File

@ -1,48 +1,75 @@
import React from "react"; import React from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import Link from "next/link"; import Link from "next/link";
import { observer } from "mobx-react-lite";
// mobx
import { useMobxStore } from "lib/mobx/store-provider";
const PROFILE_LINKS: Array<{ const PROFILE_LINKS: Array<{
key: string;
label: string; label: string;
href: string; href: string;
}> = [ }> = [
{ {
key: "profile",
label: "Profile", label: "Profile",
href: `/me/profile`, href: `/me/profile`,
}, },
{ {
key: "change-password",
label: "Change password",
href: `/me/profile/change-password`,
},
{
key: "activity",
label: "Activity", label: "Activity",
href: `/me/profile/activity`, href: `/me/profile/activity`,
}, },
{ {
key: "preferences",
label: "Preferences", label: "Preferences",
href: `/me/profile/preferences`, href: `/me/profile/preferences`,
}, },
]; ];
export const ProfileSettingsSidebar = () => { export const ProfileSettingsSidebar = observer(() => {
const router = useRouter(); const router = useRouter();
const {
appConfig: { envConfig },
} = useMobxStore();
const enableEmailPassword =
envConfig &&
(envConfig?.email_password_login ||
!(
envConfig?.email_password_login ||
envConfig?.magic_login ||
envConfig?.google_client_id ||
envConfig?.github_client_id
));
return ( return (
<div className="flex flex-col gap-2 w-80 px-5"> <div className="flex flex-col gap-2 w-80 px-5">
<span className="text-xs text-custom-sidebar-text-400 font-semibold">My Account</span> <span className="text-xs text-custom-sidebar-text-400 font-semibold">My Account</span>
<div className="flex flex-col gap-1 w-full"> <div className="flex flex-col gap-1 w-full">
{PROFILE_LINKS.map((link) => ( {PROFILE_LINKS.map((link) => {
<Link key={link.href} href={link.href}> if (link.key === "change-password" && !enableEmailPassword) return;
<a> return (
<div <Link key={link.key} href={link.href}>
className={`px-4 py-2 text-sm font-medium rounded-md ${ <a>
router.asPath === link.href <div
? "bg-custom-primary-100/10 text-custom-primary-100" className={`px-4 py-2 text-sm font-medium rounded-md ${
: "text-custom-sidebar-text-200 hover:bg-custom-sidebar-background-80 focus:bg-custom-sidebar-background-80" router.asPath === link.href
}`} ? "bg-custom-primary-100/10 text-custom-primary-100"
> : "text-custom-sidebar-text-200 hover:bg-custom-sidebar-background-80 focus:bg-custom-sidebar-background-80"
{link.label} }`}
</div> >
</a> {link.label}
</Link> </div>
))} </a>
</Link>
);
})}
</div> </div>
</div> </div>
); );
}; });

View File

@ -0,0 +1,189 @@
import { ReactElement, useEffect, useState } from "react";
import { useRouter } from "next/router";
import { observer } from "mobx-react-lite";
import { Controller, useForm } from "react-hook-form";
// mobx store
import { useMobxStore } from "lib/mobx/store-provider";
// services
import { UserService } from "services/user.service";
// hooks
import useToast from "hooks/use-toast";
// layout
import { ProfileSettingsLayout } from "layouts/settings-layout";
// components
import { ProfileSettingsHeader } from "components/headers";
// ui
import { Button, Input, Spinner } from "@plane/ui";
// types
import { NextPageWithLayout } from "types/app";
interface FormValues {
old_password: string;
new_password: string;
confirm_password: string;
}
const defaultValues: FormValues = {
old_password: "",
new_password: "",
confirm_password: "",
};
const userService = new UserService();
const ChangePasswordPage: NextPageWithLayout = observer(() => {
const [isPageLoading, setIsPageLoading] = useState(true);
const {
appConfig: { envConfig },
} = useMobxStore();
const router = useRouter();
// use form
const {
control,
handleSubmit,
formState: { errors, isSubmitting },
} = useForm<FormValues>({ defaultValues });
const { setToastAlert } = useToast();
const handleChangePassword = async (formData: FormValues) => {
if (formData.new_password !== formData.confirm_password) {
setToastAlert({
type: "error",
title: "Error!",
message: "The new password and the confirm password don't match.",
});
return;
}
await userService
.changePassword(formData)
.then(() => {
setToastAlert({
type: "success",
title: "Success!",
message: "Password changed successfully.",
});
})
.catch((error) => {
setToastAlert({
type: "error",
title: "Error!",
message: error?.error ?? "Something went wrong. Please try again.",
});
});
};
useEffect(() => {
if (!envConfig) return;
const enableEmailPassword =
envConfig?.email_password_login ||
!(
envConfig?.email_password_login ||
envConfig?.magic_login ||
envConfig?.google_client_id ||
envConfig?.github_client_id
);
if (!enableEmailPassword) router.push("/me/profile");
else setIsPageLoading(false);
}, []);
if (isPageLoading)
return (
<div className="grid place-items-center h-screen w-full">
<Spinner />
</div>
);
return (
<form onSubmit={handleSubmit(handleChangePassword)} className="flex flex-col gap-8 my-10 w-full mr-9">
<div className="grid grid-col grid-cols-1 xl:grid-cols-2 2xl:grid-cols-3 items-center justify-between gap-10 w-full">
<div className="flex flex-col gap-1 ">
<h4 className="text-sm">Current password</h4>
<Controller
control={control}
name="old_password"
rules={{
required: "This field is required",
}}
render={({ field: { value, onChange } }) => (
<Input
id="old_password"
type="password"
value={value}
onChange={onChange}
placeholder="Old password"
className="rounded-md font-medium w-full"
hasError={Boolean(errors.old_password)}
/>
)}
/>
{errors.old_password && <span className="text-red-500 text-xs">{errors.old_password.message}</span>}
</div>
<div className="flex flex-col gap-1 ">
<h4 className="text-sm">New password</h4>
<Controller
control={control}
name="new_password"
rules={{
required: "This field is required",
}}
render={({ field: { value, onChange } }) => (
<Input
id="new_password"
type="password"
value={value}
placeholder="New password"
onChange={onChange}
className="w-full"
hasError={Boolean(errors.new_password)}
/>
)}
/>
{errors.new_password && <span className="text-red-500 text-xs">{errors.new_password.message}</span>}
</div>
<div className="flex flex-col gap-1 ">
<h4 className="text-sm">Confirm password</h4>
<Controller
control={control}
name="confirm_password"
rules={{
required: "This field is required",
}}
render={({ field: { value, onChange } }) => (
<Input
id="confirm_password"
type="password"
placeholder="Confirm password"
value={value}
onChange={onChange}
className="w-full"
hasError={Boolean(errors.confirm_password)}
/>
)}
/>
{errors.confirm_password && <span className="text-red-500 text-xs">{errors.confirm_password.message}</span>}
</div>
</div>
<div className="flex items-center justify-between py-2">
<Button variant="primary" type="submit" loading={isSubmitting}>
{isSubmitting ? "Changing password..." : "Change password"}
</Button>
</div>
</form>
);
});
ChangePasswordPage.getLayout = function getLayout(page: ReactElement) {
return (
<ProfileSettingsLayout header={<ProfileSettingsHeader title="Change Password" />}>{page}</ProfileSettingsLayout>
);
};
export default ChangePasswordPage;

View File

@ -139,6 +139,14 @@ export class UserService extends APIService {
}); });
} }
async changePassword(data: { old_password: string; new_password: string; confirm_password: string }): Promise<any> {
return this.post(`/api/users/me/change-password/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getUserProfileData(workspaceSlug: string, userId: string): Promise<IUserProfileData> { async getUserProfileData(workspaceSlug: string, userId: string): Promise<IUserProfileData> {
return this.get(`/api/workspaces/${workspaceSlug}/user-stats/${userId}/`) return this.get(`/api/workspaces/${workspaceSlug}/user-stats/${userId}/`)
.then((response) => response?.data) .then((response) => response?.data)