Skip to content

Commit

Permalink
Update company design (#4995)
Browse files Browse the repository at this point in the history
* Restyle and refactor BdbDetail

* Restyle and refactor BdbDetail

* Fix semester status change

* Add icon, refactor FileUpload

* Fix import order

* Center content

* Revert global table change

* Apply changes from feedback

* Fix import order
  • Loading branch information
Bestem0r authored Oct 9, 2024
1 parent 8d97ee5 commit 86127d0
Show file tree
Hide file tree
Showing 8 changed files with 452 additions and 732 deletions.
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;
}
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
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

0 comments on commit 86127d0

Please sign in to comment.