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

Profile desc char limit #523

Merged
merged 2 commits into from
Apr 18, 2024
Merged
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
28 changes: 26 additions & 2 deletions FU.SPA/src/components/pages/ProfileSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export default function ProfileSettings() {
const [dateOfBirth, setDateOfBirth] = useState(dayjs());
const [newPfpUrl, setNewPfpUrl] = useState();
const { refreshUser } = useContext(UserContext);
const [isEnabled, setIsEnabled] = useState(false);
const [bioError, setBioError] = useState('');

useEffect(() => {
async function fetchUserInfo() {
Expand All @@ -44,6 +46,21 @@ export default function ProfileSettings() {
fetchUserInfo();
}, []);

useEffect(() => {
setIsEnabled(bio.length <= 1500);
}, [bio, isEnabled]);

// Handles the errors and value changes for the bio(About) section.
const handleBioChange = (e) => {
if (e.length > 1500) {
setBioError('About cannot exceed 1500 characters');
setBio(e);
} else {
setBioError('');
setBio(e);
}
};

const handleSubmit = async (e) => {
e.preventDefault();

Expand Down Expand Up @@ -141,12 +158,14 @@ export default function ProfileSettings() {
/>
</LocalizationProvider>
<TextField
error={bio.length > 1500}
helperText={bioError}
fullWidth
id="setBio"
label="About"
value={bio}
multiline
onChange={(e) => setBio(e.target.value)}
onChange={(e) => handleBioChange(e.target.value)}
InputProps={{
endAdornment: (
<InputAdornment position="end">
Expand All @@ -162,7 +181,12 @@ export default function ProfileSettings() {
}}
/>
<UploadAvatar onNewPreview={handlePreviewUrl} />
<Button type="submit" fullWidth variant="contained">
<Button
type="submit"
fullWidth
variant="contained"
disabled={!isEnabled}
>
Update Profile
</Button>
</Box>
Expand Down
Loading