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

Update company design #4995

Merged
merged 10 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions app/components/TextWithIcon/TextWithIcon.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
.textContainer {
width: max-content;
}

.overflowWrap {
overflow-wrap: anywhere;
}
Comment on lines +10 to +12
Copy link
Member

Choose a reason for hiding this comment

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

This feels dangerous. Have you checked how this affects other uses of the component? Like on the event detail page

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I quickly checked through all uses now and couldn't spot any problems

9 changes: 7 additions & 2 deletions app/components/TextWithIcon/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Flex, Icon } from '@webkom/lego-bricks';
import cx from 'classnames';
import Tooltip from '../Tooltip';
import styles from './TextWithIcon.css';
import type { ReactElement, ReactNode } from 'react';
Expand Down Expand Up @@ -34,7 +35,11 @@ const TextWithIcon = ({
);

return (
<Flex alignItems="center" gap={gap} className={className}>
<Flex
alignItems="center"
gap={gap}
className={cx(styles.overflowWrap, className)}
>
{iconRight && (
<div className={styles.textContainer}>
<span>{content}</span>
Expand All @@ -45,7 +50,7 @@ const TextWithIcon = ({
) : (
<>{icon}</>
)}
<div>{iconRight ? <></> : <>{content}</>}</div>
{iconRight ? <></> : <>{content}</>}
</Flex>
);
};
Expand Down
113 changes: 51 additions & 62 deletions app/components/Upload/FileUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,72 +1,61 @@
import { Button } from '@webkom/lego-bricks';
import { Component } from 'react';
import { connect } from 'react-redux';
import { uploadFile } from 'app/actions/FileActions';
import { Flex, Icon } from '@webkom/lego-bricks';
import { UploadIcon } from 'lucide-react';
import { useState, useRef } from 'react';
import { useAppDispatch } from 'app/store/hooks';
import styles from './FileUpload.css';

type State = {
pending: boolean;
};
type Props = {
uploadFile: (arg0: { file: File }) => Promise<any>;
type FileUploadProps = {
uploadFile: (arg0: { file: File }) => Promise<{
meta: { fileKey: string; fileToken: string };
}>;
onChange: (arg0: string, arg1: string) => void;
className?: string;
};

class FileUpload extends Component<Props, State> {
input: HTMLInputElement | null | undefined;
state = {
pending: false,
};
handleClick = () => {
this.input && this.input.click();
};
handleChange = (e) => {
const file = e.target.files[0];
this.setState({
pending: true,
});
this.props
.uploadFile({
file,
})
.then(({ meta }) => {
this.setState({
pending: false,
});
this.props.onChange(meta.fileKey, meta.fileToken);
})
.catch((error) => {
this.setState({
pending: false,
});
throw error;
});
const FileUpload = ({ uploadFile, onChange }: FileUploadProps) => {
const [pending, setPending] = useState(false);
const inputRef = useRef<HTMLInputElement | null>(null);

const handleClick = () => {
inputRef.current && inputRef.current.click();
};

render() {
return (
<div>
<Button
isPending={this.state.pending}
onPress={this.handleClick}
className={this.props.className}
>
Last opp fil
</Button>
<input
ref={(ref) => (this.input = ref)}
className={styles.input}
onChange={this.handleChange}
type="file"
accept="application/pdf"
/>
</div>
);
}
}
const dispatch = useAppDispatch();

const mapDispatchToProps = {
uploadFile,
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (file) {
setPending(true);
dispatch(
uploadFile({ file })
.then(({ meta }) => {
setPending(false);
onChange(meta.fileKey, meta.fileToken);
})
.catch((error) => {
setPending(false);
throw error;
}),
);
}
};

return (
<Flex justifyContent="center">
<Icon
Bestem0r marked this conversation as resolved.
Show resolved Hide resolved
disabled={pending}
name="upload"
iconNode={<UploadIcon size={20} />}
onClick={handleClick}
/>
<input
className={styles.input}
onChange={handleChange}
type="file"
accept="application/pdf"
/>
</Flex>
);
};
export default connect(null, mapDispatchToProps)(FileUpload);

export default FileUpload;
Loading
Loading