Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OUT-46 Integrate APIs #11

Merged
merged 29 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0bf24d9
data plotting of table
aatbip Jan 31, 2024
de90790
data plotting of table
aatbip Jan 31, 2024
3236564
integrated custom field access and save apis
aatbip Feb 1, 2024
f0b535f
fix custom field access issues
aatbip Feb 2, 2024
77c70f6
added client api
aatbip Feb 2, 2024
9460e0a
added manage page
aatbip Feb 2, 2024
38d9b69
added history popup
aatbip Feb 2, 2024
ff7c3b1
added sorting feature
aatbip Feb 5, 2024
3b763f3
added searching feature
aatbip Feb 5, 2024
5c884ec
added searching for all fields
aatbip Feb 5, 2024
ef9cfdc
added chip color variations
aatbip Feb 5, 2024
3a5e5b0
fix bug
aatbip Feb 5, 2024
5804da2
added empty state fallback
aatbip Feb 5, 2024
abdf684
fix bug
aatbip Feb 5, 2024
c45c6ac
fix design issues
aatbip Feb 5, 2024
692d55c
fix design issues
aatbip Feb 5, 2024
f3e7e65
adds tooltip on disabled field
aatbip Feb 6, 2024
7e1f923
removed image if company image icon is not present
aatbip Feb 6, 2024
795574b
fix bugs
aatbip Feb 6, 2024
1e57eb9
added enums for ProfileLinks
aatbip Feb 8, 2024
ea24ab7
added enums for Permissions
aatbip Feb 8, 2024
d0ed649
removed unnecessary if/else comparisions
aatbip Feb 8, 2024
06f2a26
adds server action
aatbip Feb 8, 2024
c0e3213
fix issue with server action
aatbip Feb 8, 2024
8ebda6a
fix issue with server action
aatbip Feb 8, 2024
abb68f7
added token and portalId
aatbip Feb 8, 2024
361cb7e
stringified in client component
aatbip Feb 8, 2024
b6d7909
stringified in client component
aatbip Feb 8, 2024
414bff3
reverted from server action for now
aatbip Feb 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/app/views/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@ import { Box, Stack, Typography } from '@mui/material';
import { Switch } from '@/components/switch/Switch';
import { useAppState } from '@/hooks/useAppState';
import { arraysHaveSameElements } from '@/utils/arrayHaveSameElements';
import { ProfileLinks } from '@/types/settings';

export const Sidebar = () => {
const appState = useAppState();

const handleMutableSettings = (selected: boolean, type: string) => {
if (!selected) {
if (type === 'profile_settings') {
if (type === ProfileLinks.ProfileSetting) {
const newSettings = appState?.mutableSettings.filter((el: string) => el !== type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the underlying logic for both these conditions are same, why the type check at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d0ed649 commit removes unnecessary if/else comparision @sajjanstha

appState?.setAppState((prev) => ({ ...prev, mutableSettings: newSettings }));
}
if (type === 'payment_method') {
if (type === ProfileLinks.PaymentMethod) {
const newSettings = appState?.mutableSettings.filter((el: string) => el !== type);
appState?.setAppState((prev) => ({ ...prev, mutableSettings: newSettings }));
}
}
if (selected) {
if (type === 'profile_settings') {
if (type === ProfileLinks.ProfileSetting) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d0ed649 commit resolves this @sajjanstha

appState?.setAppState((prev) => ({
...prev,
mutableSettings: appState?.mutableSettings.includes(type)
? appState?.mutableSettings
: [...appState?.mutableSettings, type],
}));
}
if (type === 'payment_method') {
if (type === ProfileLinks.PaymentMethod) {
appState?.setAppState((prev) => ({
...prev,
mutableSettings: appState?.mutableSettings.includes(type)
Expand Down Expand Up @@ -81,19 +82,19 @@ export const Sidebar = () => {
<Stack direction="row" justifyContent="space-between" p="12px 0px 6px 0px">
<Typography variant="bodyMd">General profile settings</Typography>
<Switch
selected={appState?.mutableSettings.includes('profile_settings')}
selected={appState?.mutableSettings.includes(ProfileLinks.ProfileSetting)}
getValue={(selected) => {
handleMutableSettings(selected, 'profile_settings');
handleMutableSettings(selected, ProfileLinks.ProfileSetting);
}}
/>
</Stack>

<Stack direction="row" justifyContent="space-between" p="6px 0px">
<Typography variant="bodyMd">Manage payment method</Typography>
<Switch
selected={appState?.mutableSettings.includes('payment_method')}
selected={appState?.mutableSettings.includes(ProfileLinks.PaymentMethod)}
getValue={(selected) => {
handleMutableSettings(selected, 'payment_method');
handleMutableSettings(selected, ProfileLinks.PaymentMethod);
}}
/>
</Stack>
Expand Down
33 changes: 19 additions & 14 deletions src/components/customFieldAccessTable/CustomFieldAccessTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Box, Stack, Typography, Divider } from '@mui/material';
import { StyledCheckBox } from '../styled/StyledCheckbox';
import { useAppState } from '@/hooks/useAppState';
import { iconsTypeMap } from './iconsTypeMap';
import { Permissions } from '@/types/settings';

export const CustomFieldAccessTable = () => {
const appState = useAppState();
Expand All @@ -12,32 +13,36 @@ export const CustomFieldAccessTable = () => {
let customField = appState?.mutableCustomFieldAccess.find((el: any) => el.id === id);

if (checked) {
if (permission === 'VIEW') {
if (permission === Permissions.View) {
customField = {
...customField,
permission: customField.permission.includes('VIEW') ? customField.permission : [...customField.permission, 'VIEW'],
permission: customField.permission.includes(Permissions.View)
? customField.permission
: [...customField.permission, Permissions.View],
};
}
if (permission === 'EDIT') {
if (permission === Permissions.Edit) {
customField = {
...customField,
permission: customField.permission.includes('EDIT') ? customField.permission : [...customField.permission, 'EDIT'],
permission: customField.permission.includes(Permissions.Edit)
? customField.permission
: [...customField.permission, Permissions.Edit],
};
}
}

if (!checked) {
if (permission === 'VIEW') {
if (permission === Permissions.View) {
customField = {
...customField,
permission: customField.permission.includes('VIEW') ? [] : customField.permission,
permission: customField.permission.includes(Permissions.View) ? [] : customField.permission,
};
}
if (permission === 'EDIT') {
if (permission === Permissions.Edit) {
customField = {
...customField,
permission: customField.permission.includes('EDIT')
? customField.permission.filter((item: string) => item !== 'EDIT')
permission: customField.permission.includes(Permissions.Edit)
? customField.permission.filter((item: string) => item !== Permissions.Edit)
: customField.permission,
};
}
Expand Down Expand Up @@ -74,16 +79,16 @@ export const CustomFieldAccessTable = () => {
</Box>
<Stack direction="row" columnGap={12} alignItems="center">
<StyledCheckBox
checked={field.permission.includes('VIEW')}
checked={field.permission.includes(Permissions.View)}
handleChange={(checked) => {
updateCustomFieldAccess(checked, 'VIEW', field.id);
updateCustomFieldAccess(checked, Permissions.View, field.id);
}}
/>
{field.permission.includes('VIEW') ? (
{field.permission.includes(Permissions.View) ? (
<StyledCheckBox
checked={field.permission.includes('EDIT')}
checked={field.permission.includes(Permissions.Edit)}
handleChange={(checked) => {
updateCustomFieldAccess(checked, 'EDIT', field.id);
updateCustomFieldAccess(checked, Permissions.Edit, field.id);
}}
/>
) : (
Expand Down
7 changes: 6 additions & 1 deletion src/types/settings.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { z } from 'zod';

enum ProfileLinks {
export enum ProfileLinks {
ProfileSetting = 'profile_settings',
PaymentMethod = 'payment_method',
}

export enum Permissions {
View = 'VIEW',
Edit = 'EDIT',
}

export const SettingRequestSchema = z.object({
token: z.string(),
portalId: z.string(),
Expand Down
Loading