chore: update types

This commit is contained in:
Aaryan Khandelwal 2024-06-05 19:22:32 +05:30
parent f950976032
commit a2c624230a
5 changed files with 43 additions and 44 deletions

View File

@ -21,7 +21,7 @@ type Props = {
export const SidePeekView: React.FC<Props> = observer((props) => { export const SidePeekView: React.FC<Props> = observer((props) => {
const { anchor, handleClose, issueDetails } = props; const { anchor, handleClose, issueDetails } = props;
// store hooks // store hooks
const { comments } = usePublish(anchor); const { canComment } = usePublish(anchor);
return ( return (
<div className="flex h-full w-full flex-col overflow-hidden"> <div className="flex h-full w-full flex-col overflow-hidden">
@ -41,7 +41,7 @@ export const SidePeekView: React.FC<Props> = observer((props) => {
{/* divider */} {/* divider */}
<div className="my-5 h-[1] w-full border-t border-custom-border-200" /> <div className="my-5 h-[1] w-full border-t border-custom-border-200" />
{/* issue activity/comments */} {/* issue activity/comments */}
{comments && ( {canComment && (
<div className="w-full pb-5"> <div className="w-full pb-5">
<PeekOverviewIssueActivity anchor={anchor} issueDetails={issueDetails} /> <PeekOverviewIssueActivity anchor={anchor} issueDetails={issueDetails} />
</div> </div>

View File

@ -18,7 +18,7 @@ export interface IPublishStore extends TPublishSettings {
export class PublishStore implements IPublishStore { export class PublishStore implements IPublishStore {
// observables // observables
anchor: string | undefined; anchor: string | undefined;
comments: boolean; is_comments_enabled: boolean;
created_at: string | undefined; created_at: string | undefined;
created_by: string | undefined; created_by: string | undefined;
entity_identifier: string | undefined; entity_identifier: string | undefined;
@ -27,11 +27,11 @@ export class PublishStore implements IPublishStore {
inbox: unknown; inbox: unknown;
project: string | undefined; project: string | undefined;
project_details: TProjectDetails | undefined; project_details: TProjectDetails | undefined;
reactions: boolean; is_reactions_enabled: boolean;
updated_at: string | undefined; updated_at: string | undefined;
updated_by: string | undefined; updated_by: string | undefined;
view_props: TViewDetails | undefined; view_props: TViewDetails | undefined;
votes: boolean; is_votes_enabled: boolean;
workspace: string | undefined; workspace: string | undefined;
workspace_detail: IWorkspaceLite | undefined; workspace_detail: IWorkspaceLite | undefined;
@ -40,7 +40,7 @@ export class PublishStore implements IPublishStore {
publishSettings: TPublishSettings publishSettings: TPublishSettings
) { ) {
this.anchor = publishSettings.anchor; this.anchor = publishSettings.anchor;
this.comments = publishSettings.comments; this.is_comments_enabled = publishSettings.is_comments_enabled;
this.created_at = publishSettings.created_at; this.created_at = publishSettings.created_at;
this.created_by = publishSettings.created_by; this.created_by = publishSettings.created_by;
this.entity_identifier = publishSettings.entity_identifier; this.entity_identifier = publishSettings.entity_identifier;
@ -49,18 +49,18 @@ export class PublishStore implements IPublishStore {
this.inbox = publishSettings.inbox; this.inbox = publishSettings.inbox;
this.project = publishSettings.project; this.project = publishSettings.project;
this.project_details = publishSettings.project_details; this.project_details = publishSettings.project_details;
this.reactions = publishSettings.reactions; this.is_reactions_enabled = publishSettings.is_reactions_enabled;
this.updated_at = publishSettings.updated_at; this.updated_at = publishSettings.updated_at;
this.updated_by = publishSettings.updated_by; this.updated_by = publishSettings.updated_by;
this.view_props = publishSettings.view_props; this.view_props = publishSettings.view_props;
this.votes = publishSettings.votes; this.is_votes_enabled = publishSettings.is_votes_enabled;
this.workspace = publishSettings.workspace; this.workspace = publishSettings.workspace;
this.workspace_detail = publishSettings.workspace_detail; this.workspace_detail = publishSettings.workspace_detail;
makeObservable(this, { makeObservable(this, {
// observables // observables
anchor: observable.ref, anchor: observable.ref,
comments: observable.ref, is_comments_enabled: observable.ref,
created_at: observable.ref, created_at: observable.ref,
created_by: observable.ref, created_by: observable.ref,
entity_identifier: observable.ref, entity_identifier: observable.ref,
@ -69,11 +69,11 @@ export class PublishStore implements IPublishStore {
inbox: observable, inbox: observable,
project: observable.ref, project: observable.ref,
project_details: observable, project_details: observable,
reactions: observable.ref, is_reactions_enabled: observable.ref,
updated_at: observable.ref, updated_at: observable.ref,
updated_by: observable.ref, updated_by: observable.ref,
view_props: observable, view_props: observable,
votes: observable.ref, is_votes_enabled: observable.ref,
workspace: observable.ref, workspace: observable.ref,
workspace_detail: observable, workspace_detail: observable,
// computed // computed
@ -95,20 +95,20 @@ export class PublishStore implements IPublishStore {
* @description returns whether commenting is enabled or not * @description returns whether commenting is enabled or not
*/ */
get canComment() { get canComment() {
return !!this.comments; return !!this.is_comments_enabled;
} }
/** /**
* @description returns whether reacting is enabled or not * @description returns whether reacting is enabled or not
*/ */
get canReact() { get canReact() {
return !!this.reactions; return !!this.is_reactions_enabled;
} }
/** /**
* @description returns whether voting is enabled or not * @description returns whether voting is enabled or not
*/ */
get canVote() { get canVote() {
return !!this.votes; return !!this.is_votes_enabled;
} }
} }

View File

@ -5,7 +5,7 @@ export type TPublishEntityType = "project";
export type TPublishSettings = { export type TPublishSettings = {
anchor: string | undefined; anchor: string | undefined;
comments: boolean; is_comments_enabled: boolean;
created_at: string | undefined; created_at: string | undefined;
created_by: string | undefined; created_by: string | undefined;
entity_identifier: string | undefined; entity_identifier: string | undefined;
@ -14,11 +14,11 @@ export type TPublishSettings = {
inbox: unknown; inbox: unknown;
project: string | undefined; project: string | undefined;
project_details: TProjectDetails | undefined; project_details: TProjectDetails | undefined;
reactions: boolean; is_reactions_enabled: boolean;
updated_at: string | undefined; updated_at: string | undefined;
updated_by: string | undefined; updated_by: string | undefined;
view_props: TViewDetails | undefined; view_props: TViewDetails | undefined;
votes: boolean; is_votes_enabled: boolean;
workspace: string | undefined; workspace: string | undefined;
workspace_detail: IWorkspaceLite | undefined; workspace_detail: IWorkspaceLite | undefined;
}; };

View File

@ -27,9 +27,9 @@ type Props = {
type FormData = { type FormData = {
anchor: string; anchor: string;
id: string | null; id: string | null;
comments: boolean; is_comments_enabled: boolean;
reactions: boolean; is_reactions_enabled: boolean;
votes: boolean; is_votes_enabled: boolean;
inbox: string | null; inbox: string | null;
views: TProjectPublishViews[]; views: TProjectPublishViews[];
}; };
@ -37,14 +37,14 @@ type FormData = {
const defaultValues: FormData = { const defaultValues: FormData = {
anchor: "", anchor: "",
id: null, id: null,
comments: false, is_comments_enabled: false,
reactions: false, is_reactions_enabled: false,
votes: false, is_votes_enabled: false,
inbox: null, inbox: null,
views: ["list", "kanban"], views: ["list", "kanban"],
}; };
const viewOptions: { const VIEW_OPTIONS: {
key: TProjectPublishViews; key: TProjectPublishViews;
label: string; label: string;
}[] = [ }[] = [
@ -92,7 +92,7 @@ export const PublishProjectModal: React.FC<Props> = observer((props) => {
// prefill form with the saved settings if the project is already published // prefill form with the saved settings if the project is already published
useEffect(() => { useEffect(() => {
if (!projectPublishSettings) return; if (!projectPublishSettings?.anchor) return;
let userBoards: TProjectPublishViews[] = []; let userBoards: TProjectPublishViews[] = [];
@ -112,9 +112,9 @@ export const PublishProjectModal: React.FC<Props> = observer((props) => {
const updatedData = { const updatedData = {
id: projectPublishSettings?.id || null, id: projectPublishSettings?.id || null,
comments: projectPublishSettings?.comments || false, is_comments_enabled: !!projectPublishSettings?.is_comments_enabled,
reactions: projectPublishSettings?.reactions || false, is_reactions_enabled: !!projectPublishSettings?.is_reactions_enabled,
votes: projectPublishSettings?.votes || false, is_votes_enabled: !!projectPublishSettings?.is_votes_enabled,
inbox: projectPublishSettings?.inbox || null, inbox: projectPublishSettings?.inbox || null,
views: userBoards, views: userBoards,
}; };
@ -205,9 +205,9 @@ export const PublishProjectModal: React.FC<Props> = observer((props) => {
} }
const payload = { const payload = {
comments: formData.comments, is_comments_enabled: formData.is_comments_enabled,
reactions: formData.reactions, is_reactions_enabled: formData.is_reactions_enabled,
votes: formData.votes, is_votes_enabled: formData.is_votes_enabled,
inbox: formData.inbox, inbox: formData.inbox,
view_props: { view_props: {
list: formData.views.includes("list"), list: formData.views.includes("list"),
@ -235,16 +235,16 @@ export const PublishProjectModal: React.FC<Props> = observer((props) => {
const newSettings = getValues(); const newSettings = getValues();
if ( if (
currentSettings.comments !== newSettings.comments || currentSettings.is_comments_enabled !== newSettings.is_comments_enabled ||
currentSettings.reactions !== newSettings.reactions || currentSettings.is_reactions_enabled !== newSettings.is_reactions_enabled ||
currentSettings.votes !== newSettings.votes currentSettings.is_votes_enabled !== newSettings.is_votes_enabled
) { ) {
setIsUpdateRequired(true); setIsUpdateRequired(true);
return; return;
} }
let viewCheckFlag = 0; let viewCheckFlag = 0;
viewOptions.forEach((option) => { VIEW_OPTIONS.forEach((option) => {
if (currentSettings.view_props?.[option.key] !== newSettings.views.includes(option.key)) viewCheckFlag++; if (currentSettings.view_props?.[option.key] !== newSettings.views.includes(option.key)) viewCheckFlag++;
}); });
@ -337,8 +337,7 @@ export const PublishProjectModal: React.FC<Props> = observer((props) => {
<CustomPopover <CustomPopover
label={ label={
value.length > 0 value.length > 0
? viewOptions ? VIEW_OPTIONS.filter((v) => value.includes(v.key))
.filter((v) => value.includes(v.key))
.map((v) => v.label) .map((v) => v.label)
.join(", ") .join(", ")
: `` : ``
@ -346,7 +345,7 @@ export const PublishProjectModal: React.FC<Props> = observer((props) => {
placeholder="Select views" placeholder="Select views"
> >
<> <>
{viewOptions.map((option) => ( {VIEW_OPTIONS.map((option) => (
<div <div
key={option.key} key={option.key}
className={`relative m-1 flex cursor-pointer items-center justify-between gap-2 rounded-sm p-1 px-2 text-custom-text-200 ${ className={`relative m-1 flex cursor-pointer items-center justify-between gap-2 rounded-sm p-1 px-2 text-custom-text-200 ${
@ -385,7 +384,7 @@ export const PublishProjectModal: React.FC<Props> = observer((props) => {
<div className="text-sm">Allow comments</div> <div className="text-sm">Allow comments</div>
<Controller <Controller
control={control} control={control}
name="comments" name="is_comments_enabled"
render={({ field: { onChange, value } }) => ( render={({ field: { onChange, value } }) => (
<ToggleSwitch <ToggleSwitch
value={value} value={value}
@ -402,7 +401,7 @@ export const PublishProjectModal: React.FC<Props> = observer((props) => {
<div className="text-sm">Allow reactions</div> <div className="text-sm">Allow reactions</div>
<Controller <Controller
control={control} control={control}
name="reactions" name="is_reactions_enabled"
render={({ field: { onChange, value } }) => ( render={({ field: { onChange, value } }) => (
<ToggleSwitch <ToggleSwitch
value={value} value={value}
@ -419,7 +418,7 @@ export const PublishProjectModal: React.FC<Props> = observer((props) => {
<div className="text-sm">Allow voting</div> <div className="text-sm">Allow voting</div>
<Controller <Controller
control={control} control={control}
name="votes" name="is_votes_enabled"
render={({ field: { onChange, value } }) => ( render={({ field: { onChange, value } }) => (
<ToggleSwitch <ToggleSwitch
value={value} value={value}

View File

@ -16,9 +16,9 @@ export interface IProjectPublishSettings {
anchor?: string; anchor?: string;
id?: string; id?: string;
project?: string; project?: string;
comments: boolean; is_comments_enabled: boolean;
reactions: boolean; is_reactions_enabled: boolean;
votes: boolean; is_votes_enabled: boolean;
view_props: TProjectPublishViewsSettings; view_props: TProjectPublishViewsSettings;
inbox: string | null; inbox: string | null;
} }