mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 20:09:11 +00:00
* chore: restructure project into yarn workspaces, remove next * fix tests, remove webapp from terraform * remove more ui deployment bits * remove pages, fix FUNDING.yml * remove isomorphism * remove next providers * fix linting issues * feat: start basis of new web ui system on CRA * chore: move types to @roleypoly/types package * chore: move src/common/utils to @roleypoly/misc-utils * chore: remove roleypoly/ path remappers * chore: renmove vercel config * chore: re-add worker-types to api package * chore: fix type linting scope for api * fix(web): craco should include all of packages dir * fix(ci): change api webpack path for wrangler * chore: remove GAR actions from CI * chore: update codeql job * chore: test better github dar matcher in lint-staged
151 lines
5.6 KiB
TypeScript
151 lines
5.6 KiB
TypeScript
import { FaderOpacity } from '@roleypoly/design-system/atoms/fader';
|
|
import { Space } from '@roleypoly/design-system/atoms/space';
|
|
import { Link } from '@roleypoly/design-system/atoms/typography';
|
|
import { PickerCategory } from '@roleypoly/design-system/molecules/picker-category';
|
|
import { ResetSubmit } from '@roleypoly/design-system/molecules/reset-submit';
|
|
import { ServerMasthead } from '@roleypoly/design-system/molecules/server-masthead';
|
|
import { ReactifyNewlines } from '@roleypoly/misc-utils/ReactifyNewlines';
|
|
import { sortBy } from '@roleypoly/misc-utils/sortBy';
|
|
import {
|
|
Category,
|
|
CategoryType,
|
|
GuildData,
|
|
GuildSlug,
|
|
Member,
|
|
Role,
|
|
} from '@roleypoly/types';
|
|
import { isEqual, xor } from 'lodash';
|
|
import * as React from 'react';
|
|
import { GoInfo } from 'react-icons/go';
|
|
import {
|
|
CategoryContainer,
|
|
Container,
|
|
InfoBox,
|
|
InfoIcon,
|
|
MessageBox,
|
|
} from './RolePicker.styled';
|
|
|
|
export type RolePickerProps = {
|
|
guild: GuildSlug;
|
|
guildData: GuildData;
|
|
member: Member;
|
|
roles: Role[];
|
|
onSubmit: (selectedRoles: string[]) => void;
|
|
editable: boolean;
|
|
};
|
|
|
|
export const RolePicker = (props: RolePickerProps) => {
|
|
const [selectedRoles, updateSelectedRoles] = React.useState<string[]>(
|
|
props.member.roles
|
|
);
|
|
|
|
React.useEffect(() => {
|
|
if (!isEqual(props.member.roles, selectedRoles)) {
|
|
updateSelectedRoles(props.member.roles);
|
|
}
|
|
}, [props.member.roles]);
|
|
|
|
const handleChange = (category: Category) => (role: Role) => (newState: boolean) => {
|
|
if (category.type === CategoryType.Single) {
|
|
updateSelectedRoles(
|
|
newState === true
|
|
? [
|
|
...selectedRoles.filter((x) => !category.roles.includes(x)),
|
|
role.id,
|
|
]
|
|
: selectedRoles.filter((x) => x !== role.id)
|
|
);
|
|
} else {
|
|
updateSelectedRoles(
|
|
newState === true
|
|
? [...selectedRoles, role.id]
|
|
: selectedRoles.filter((x) => x !== role.id)
|
|
);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Container>
|
|
<Space />
|
|
<ServerMasthead guild={props.guild} editable={props.editable} />
|
|
<Space />
|
|
{props.guildData.message && (
|
|
<>
|
|
<MessageBox>
|
|
<ReactifyNewlines>{props.guildData.message}</ReactifyNewlines>
|
|
</MessageBox>
|
|
<Space />
|
|
</>
|
|
)}
|
|
|
|
{props.guildData.categories.length !== 0 ? (
|
|
<>
|
|
<div>
|
|
{sortBy(
|
|
props.guildData.categories.filter(
|
|
(category) => !category.hidden
|
|
),
|
|
'position'
|
|
).map((category, idx) => (
|
|
<CategoryContainer key={idx}>
|
|
<PickerCategory
|
|
key={idx}
|
|
category={category}
|
|
title={category.name}
|
|
selectedRoles={selectedRoles.filter((roleId) =>
|
|
category.roles.includes(roleId)
|
|
)}
|
|
roles={
|
|
category.roles
|
|
.map((role) =>
|
|
props.roles.find((r) => r.id === role)
|
|
)
|
|
.filter((r) => r !== undefined) as Role[]
|
|
}
|
|
onChange={handleChange(category)}
|
|
wikiMode={false}
|
|
type={
|
|
category.type === CategoryType.Single
|
|
? 'single'
|
|
: 'multi'
|
|
}
|
|
/>
|
|
</CategoryContainer>
|
|
))}
|
|
</div>
|
|
<div>
|
|
<FaderOpacity
|
|
isVisible={
|
|
xor(selectedRoles, props.member.roles).length !== 0
|
|
}
|
|
>
|
|
<ResetSubmit
|
|
onSubmit={() => props.onSubmit(selectedRoles)}
|
|
onReset={() => {
|
|
updateSelectedRoles(props.member.roles);
|
|
}}
|
|
/>
|
|
</FaderOpacity>
|
|
</div>
|
|
</>
|
|
) : (
|
|
<InfoBox>
|
|
<InfoIcon>
|
|
<GoInfo />
|
|
</InfoIcon>
|
|
<div>
|
|
There are currently no roles available for you to choose from.
|
|
{props.editable && (
|
|
<>
|
|
{' '}
|
|
<a href={`/s/${props.guild.id}/edit`}>
|
|
<Link>Add some roles!</Link>
|
|
</a>
|
|
</>
|
|
)}
|
|
</div>
|
|
</InfoBox>
|
|
)}
|
|
</Container>
|
|
);
|
|
};
|